From 89600067cd10ff74fd9daae34c40adb64a32e118 Mon Sep 17 00:00:00 2001 From: Frederik Berlaen Date: Fri, 3 May 2024 11:39:38 +0200 Subject: [PATCH] Remove non existing axis names in location labels for sources and instances + white space --- .../lib/designspaceEditor/ui.py | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/DesignspaceEditor2.roboFontExt/lib/designspaceEditor/ui.py b/DesignspaceEditor2.roboFontExt/lib/designspaceEditor/ui.py index 7324748..d76ea0b 100644 --- a/DesignspaceEditor2.roboFontExt/lib/designspaceEditor/ui.py +++ b/DesignspaceEditor2.roboFontExt/lib/designspaceEditor/ui.py @@ -257,8 +257,8 @@ def __init__(self, parentWindow, operator, instances): self.w.roundCheckBox = vanilla.CheckBox((split + 20, 45, -10, 22), "Round Geometry") self.w.mathModelSuffix = vanilla.CheckBox((split + 20, 70, -10, 22), "Add Math Model Suffix") - #self.w.instancesRootText = vanilla.TextBox((10, 105, split, 22), "Instances Folder:", alignment="right") - #self.w.instancesRoot = vanilla.EditText((split + 20, 105 - 2, -10, 22), "foo") + # self.w.instancesRootText = vanilla.TextBox((10, 105, split, 22), "Instances Folder:", alignment="right") + # self.w.instancesRoot = vanilla.EditText((split + 20, 105 - 2, -10, 22), "foo") self.w.closeButton = vanilla.Button((-180, -30, -110, 20), "Cancel", callback=self.closeCallback) self.w.closeButton.bind(".", ["command"]) @@ -357,7 +357,7 @@ def axisMinimum(self): return None return self.axisDescriptor.minimum - #@tryExceptDecorator + # @tryExceptDecorator def setAxisMinimum_(self, value): if self.axisIsDescrete(): # convert to a continuous axis @@ -377,7 +377,7 @@ def axisMaximum(self): return None return self.axisDescriptor.maximum - #@tryExceptDecorator + # @tryExceptDecorator def setAxisMaximum_(self, value): if self.axisIsDescrete(): # convert to a continuous axis @@ -393,7 +393,7 @@ def axisDiscreteValues(self): return " ".join([numberToString(value) for value in self.axisDescriptor.values]) return "" - #@tryExceptDecorator + # @tryExceptDecorator def setAxisDiscreteValues_(self, value): if not self.axisIsDescrete(): # convert to a discrete axis @@ -1236,8 +1236,15 @@ def unwrapSourceDescriptor(self, wrappedSourceDescriptor): sourceDescriptor.familyName = wrappedSourceDescriptor["sourceFamilyName"] if wrappedSourceDescriptor.get("sourceFamilyName") else None sourceDescriptor.styleName = wrappedSourceDescriptor["sourceStyleName"] if wrappedSourceDescriptor.get("sourceStyleName") else None sourceDescriptor.layerName = wrappedSourceDescriptor["sourceLayerName"] if wrappedSourceDescriptor.get("sourceLayerName") else None + # update locations for axis in self.operator.axes: sourceDescriptor.location[axis.name] = wrappedSourceDescriptor.get(f"axis_{axis.name}", axis.default) + # remove non existing location axis names + existingAxisNames = [axis.name for axis in self.operator.axes] + for locationName in list(sourceDescriptor.location): + if locationName not in existingAxisNames: + del sourceDescriptor.location[locationName] + return sourceDescriptor def sourcesListDoubleClickCallback(self, sender): @@ -1313,9 +1320,15 @@ def unwrapInstanceDescriptor(self, wrappedInstanceDescriptor): instanceDescriptor.familyName = wrappedInstanceDescriptor["instanceFamilyName"] if wrappedInstanceDescriptor.get("instanceFamilyName") else None instanceDescriptor.styleName = wrappedInstanceDescriptor["instanceStyleName"] if wrappedInstanceDescriptor.get("instanceStyleName") else None instanceDescriptor.postScriptFontName = wrappedInstanceDescriptor["instancePostscriptFontName"] if wrappedInstanceDescriptor.get("instancePostscriptFontName") else None + # update locations location = instanceDescriptor.designLocation or instanceDescriptor.userLocation for axis in self.operator.axes: location[axis.name] = wrappedInstanceDescriptor.get(f"axis_{axis.name}", axis.default) + # remove non existing location axis names + existingAxisNames = [axis.name for axis in self.operator.axes] + for locationName in list(location): + if locationName not in existingAxisNames: + del location[locationName] return instanceDescriptor def instancesListDoubleClickCallback(self, sender): @@ -1538,19 +1551,19 @@ def newInstanceBetween(menuItem): return location = self.operator.newDefaultLocation(discreteLocation=firstDiscrete) for axisName in firstContinuous.keys(): - newValue = .5*(firstContinuous.get(axisName) + secondContinuous.get(axisName)) + newValue = .5 * (firstContinuous.get(axisName) + secondContinuous.get(axisName)) location[axisName] = newValue newFamilyName = first.familyName newStyleName = f"{first.styleName}_{second.styleName}" postScriptFontName = f"{newFamilyName}-{newStyleName}" instanceUFOFileName = f"{newFamilyName}-{newStyleName}.ufo" self.operator.addInstanceDescriptor( - familyName = first.familyName, - styleName = newStyleName, - designLocation = location, - filename = instanceUFOFileName, - postScriptFontName = postScriptFontName, - ) + familyName=first.familyName, + styleName=newStyleName, + designLocation=location, + filename=instanceUFOFileName, + postScriptFontName=postScriptFontName, + ) def updateUFOFilenameFromFontNames(menuItem): for item in selectedItems: @@ -1572,7 +1585,6 @@ def updatePostScriptFontNameFromFontNamesCallback(menuItem): def openUFO(menuItem): self.openSelectedItem(sender) - menu = [] for axisDescriptor in self.operator.axes: if axisDescriptor.name == axisName: