Skip to content

Commit

Permalink
Improve adding/changing instances with an empty family or styleName
Browse files Browse the repository at this point in the history
  • Loading branch information
typemytype committed Oct 18, 2024
1 parent b9e668a commit 66c4a0e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions DesignspaceEditor2.roboFontExt/lib/designspaceEditor/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,19 @@ def removeInstance(self, instanceDescriptor):
self.instances.remove(instanceDescriptor)

def addInstanceDescriptor(self, **kwargs):
if "familyName" not in kwargs:
familyName = kwargs.get("familyName")
styleName = kwargs.get("styleName")
if familyName is None:
if self.instances:
familyName = self.instances[0].familyName
elif self.sources:
familyName = self.sources[0].familyName
else:
familyName = "NewFamily"
kwargs["familyName"] = familyName
if "styleName" not in kwargs:
kwargs["styleName"] = f"Style_{len(self.instances)}"
if styleName is None:
styleName = kwargs["styleName"] = f"Style_{len(self.instances)}"

if "filename" not in kwargs:
filename = postScriptNameTransformer(kwargs["familyName"], kwargs["styleName"])
kwargs["filename"] = os.path.join(getExtensionDefault('instanceFolderName', 'instances'), f"{filename}.ufo")
Expand Down Expand Up @@ -252,7 +255,11 @@ def __init__(self, parentWindow, operator, instances):
# update the path attribute in all given instanceDescriptors
for item in instances:
instanceDescriptor = item["object"]
instanceDescriptor.path = os.path.abspath(os.path.join(os.path.dirname(self.operator.path), instanceDescriptor.filename))
# filename could be None
filename = instanceDescriptor.filename
if filename is None:
filename = fileNameForInstance(instanceDescriptor)
instanceDescriptor.path = os.path.abspath(os.path.join(os.path.dirname(self.operator.path), filename))

self.instances = instances
self.w = vanilla.Sheet((350, 140), parentWindow=parentWindow)
Expand Down

0 comments on commit 66c4a0e

Please sign in to comment.