def buildMatrix(self, axesGrid): nCellsOnHorizontalAxis, nCellsOnVerticalAxis = axesGrid if hasattr(self.w, 'matrix'): delattr(self.w, 'matrix') self.w.matrix = Group((0, 50, -50, -0)) matrix = self.w.matrix windowPosSize = self.w.getPosSize() cellXSize, cellYSize = self.glyphPreviewCellSize(windowPosSize, axesGrid) for i in range(nCellsOnHorizontalAxis): ch = getKeyForValue(i) for j in range(nCellsOnVerticalAxis): setattr(matrix, '%s%s'%(ch,j), Group(((i*cellXSize), (j*cellYSize), cellXSize, cellYSize))) cell = getattr(matrix, '%s%s'%(ch,j)) cell.background = Box((0, 0, -0, -0)) cell.selectionMask = Box((0, 0, -0, -0)) cell.selectionMask.show(False) cell.masterMask = Box((0, 0, -0, -0)) cell.masterMask.show(False) cell.glyphView = GlyphPreview((0, 0, -0, -0)) cell.button = SquareButton((0, 0, -0, -0), None, callback=self.pickSpot) cell.button.spot = (ch, j) # cell.button.getNSButton().setBordered_(False) cell.button.getNSButton().setTransparent_(True) cell.coordinate = TextBox((5, -17, 30, 12), '%s%s'%(ch.capitalize(), j+1), sizeStyle='mini') cell.name = TextBox((40, -17, -10, 12), '', sizeStyle='mini', alignment='right')
def __init__(self, interface, glyphdata, compositionName, selectedContours): self.ui = interface self.gd = glyphdata self.compositionName = compositionName self.selectedContours = selectedContours self.w = Sheet((330, 350), self.ui.w) self.font = self.ui.font # self.storageFont = self.ui.font2Storage[self.font] self.selectedName = "" self.existingName = [value["Name"] for value in self.gd.variantsName] self.w.existingName_List = List( (10, 10, 150, 150), self.existingName, selectionCallback=self._existingName_List_selectionCallback, drawFocusRing=False, allowsMultipleSelection=False) self.w.existingName_List.setSelection([]) self.w.newName_button = Button((10, 160, 150, 20), "new Version", callback=self._newName_button_callback) self.selectedLayer = "" self.existingLayers = [] self.w.existingLayers_List = List( (170, 10, 150, 150), self.existingLayers, selectionCallback=self._existingLayers_List_selectionCallback, editCallback=self._existingLayers_List_editCallback, drawFocusRing=False, allowsEmptySelection=False, allowsMultipleSelection=False) self.w.newLayerbutton = Button((170, 160, 150, 20), "new Layer", callback=self._newLayer_button_callback) self.w.newLayerbutton.show(False) self.w.glyphPreview = GlyphPreview((0, 190, -0, -30)) self.w.addButton = Button((110, -30, -10, -10), "add", callback=self._addButton_callback) self.w.cancelButton = Button((10, -30, 100, -10), "cancel", callback=self._cancelButton_callback) Helpers.setDarkMode(self.w, self.ui.darkMode) self.w.open()
def _buildUI(self): w = FloatingWindow((300, 340), "Rotated Glyph Preview", (300, 340), (2560, 1440)) w.preview = GlyphPreview((2, 2, -2, -40)) w.rotationSlider = Slider( (10, -30, -10, 20), minValue=-180, maxValue=180, value=self.settings["rotation"], tickMarkCount=5, stopOnTickMarks=False, continuous=True, callback=self._setRotation, sizeStyle="small", ) return w
def __init__(self): self._unsubscribeGlyphCallback = None self._holdGlyphUpdates = False self.w = vanilla.Window((500, 600), self.title, minSize=(500, 500)) y = -(10 + 30 + len(self.attributes) * 30) self.w.preview = GlyphPreview((0, 0, -0, y)) middleLeft = 120 middleRight = middleLeft + 20 right = -10 self.w.hl = vanilla.HorizontalLine((0, y, -0, 1)) y += 10 for attr, kwargs in self.attributes: if kwargs.get("title") is None: txtObj = vanilla.TextBox((10, y, middleLeft, 22), "%s:" % attr, alignment="right") setattr(self.w, "%sText" % camelCase(attr), txtObj) uiElement = kwargs.get("ui", "Slider") if uiElement == "Slider" or uiElement is None: obj = SliderEditFloatStepper else: del kwargs["ui"] obj = getattr(vanilla, uiElement) obj = obj((middleRight, y - 2, -7, 22), callback=self.parametersChanged, **kwargs) setattr(self.w, camelCase(attr), obj) y += 30 self.w.apply = vanilla.Button((-150+right, y, -10, 22), "Apply Glyph", callback=self.applyCallback) self.w.newFont = vanilla.Button((-150+right-10-150, y, -150+right-10, 22), "New Font", callback=self.generateFontCallback) self.w.showInSpaceCenter = vanilla.CheckBox((10, y, 160, 22), "Show In Space Center", callback=self.showInSpaceCenterCallback) addObserver(self, "currentGlyphChanged", "currentGlyphChanged") self.w.bind("close", self.windowClose) self.parametersChanged() self.w.open()
def __init__(self, font): self.font = None self._glyphs = [] statusBarHeight = 20 self.w = Window((900, 700), "Glyph Builder", minSize=(400, 400)) self.w.getNSWindow().setCollectionBehavior_( 128) # NSWindowCollectionBehaviorFullScreenPrimary toolbarItems = [ dict( itemIdentifier="save", label="Save", imageNamed="toolbarScriptSave", callback=self.saveFile, ), dict( itemIdentifier="open", label="Open", imageNamed="toolbarScriptOpen", callback=self.openFile, ), dict(itemIdentifier=NSToolbarSpaceItemIdentifier), dict( itemIdentifier="reload", label="Update", imageNamed="toolbarScriptReload", callback=self.reload, ), dict(itemIdentifier=NSToolbarSpaceItemIdentifier), dict( itemIdentifier="analyse", label="Analyse", imageNamed="prefToolbarSort", callback=self.analyse, ), dict(itemIdentifier=NSToolbarFlexibleSpaceItemIdentifier), dict(itemIdentifier="buildGlyphs", label="Build Glyphs", imageNamed="toolbarRun", callback=self.generateGlyphs), ] self.w.addToolbar(toolbarIdentifier="GlyphBuilderControllerToolbar", toolbarItems=toolbarItems, addStandardItems=False) self.constructions = CodeEditor((0, 0, -0, -0), constructions, lexer=GlyphConstructionLexer()) # self.constructions.wrapWord(False) # in only availbel in the RoboFont 1.7 beta self.constructions.getNSScrollView().setBorderType_(NSNoBorder) self.preview = MultiLineView( (0, 0, -0, -0), pointSize=50, lineHeight=500, applyKerning=False, displayOptions={ "Beam": False, "displayMode": "Multi Line" }, selectionCallback=self.previewSelectionCallback) self.analyser = AnalyserTextEditor((0, 0, -0, -0), readOnly=True) self.analyserPreview = Group((0, 0, -0, -0)) constructionColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0, 0, .6) self.analyserPreview.construction = GlyphPreview( (0, 0, -0, -0), contourColor=constructionColor, componentColor=constructionColor) self.analyserPreview.construction.getNSView()._buffer = 100 originColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 1, 0, 0, .6) self.analyserPreview.origin = GlyphPreview((0, 0, -0, -0), contourColor=originColor, componentColor=originColor) self.analyserPreview.origin.getNSView()._buffer = 100 self.analyserPreview.build = Button((10, -30, -10, 20), "Build", sizeStyle="small", callback=self.buildSingleGlyph) self.analyserPreview.build.enable(False) paneDescriptions = [ dict(view=self.analyser, identifier="analyserText", canCollapse=False, minSize=100), dict(view=self.analyserPreview, identifier="analyserPreview", canCollapse=False, minSize=100), ] self.analyserSplit = Splitter((0, 0, -0, -statusBarHeight), paneDescriptions=paneDescriptions, drawBorderLine=False, isVertical=False, dividerThickness=1) paneDescriptions = [ dict(view=self.constructions, identifier="constructions", canCollapse=False, minSize=200, maxSize=600, liveResizeable=False), dict(view=self.preview, identifier="preview", canCollapse=False, minSize=300, liveResizeable=True), dict(view=self.analyserSplit, identifier="analyser", canCollapse=True, minSize=100, maxSize=300, liveResizeable=False) ] self.w.split = Splitter((0, 0, -0, -statusBarHeight), paneDescriptions=paneDescriptions, drawBorderLine=False, dividerThickness=1) # self.w.split.showPane("analyser", True) self.w.statusBar = StatusBar( (0, -statusBarHeight, -0, statusBarHeight)) self.w.statusBar.hiddenReload = Button((0, 0, -0, -0), "Reload", self.reload) button = self.w.statusBar.hiddenReload.getNSButton() button.setBezelStyle_(NSRoundRectBezelStyle) button.setAlphaValue_(0) self.w.statusBar.hiddenReload.bind("\r", ["command"]) self.w.statusBar.hiddenSave = Button((0, 0, -0, -0), "Reload", self.saveFile) button = self.w.statusBar.hiddenSave.getNSButton() button.setBezelStyle_(NSRoundRectBezelStyle) button.setAlphaValue_(0) self.w.statusBar.hiddenSave.bind("s", ["command"]) self.subscribeFont(font) self.setUpBaseWindowBehavior() addObserver(self, "fontBecameCurrent", "fontBecameCurrent") addObserver(self, "fontResignCurrent", "fontResignCurrent") self.w.open()
def __init__(self, value, font1, font2, available_fonts): self.activateModule() # sets initial value # self.redBlink = False global redIsOn redIsOn = False x = 10 y = 10 lineHeight = 23 self.value = value self.font1 = font1 self.font2 = font2 self.available_fonts = available_fonts # gname1 if CurrentGlyph() != None: g = CurrentGlyph() else: g = gInit self.gname = g # use minSize to make window re-sizable self.w = vanilla.Window((400, 400), 'Delorean: Interpolation Preview', minSize=(200, 200)) # Figuring out what to display in the dropdown list styleNames_set = False familyNames_set = False familyNames_differ = False if all([f.info.styleName for f in self.available_fonts]): styleNames_set = True if all([f.info.familyName for f in self.available_fonts]): familyNames_set = True if len(set([f.info.familyName for f in self.available_fonts])) > 1: familyNames_differ = True if styleNames_set: # If style names are all set and family name is all the same # (or not set), display only the style name. # If family names are different, display family name & style name. if familyNames_set: if familyNames_differ: fontList = [ '%s %s' % (f.info.familyName, f.info.styleName) for f in self.available_fonts ] else: fontList = [f.info.styleName for f in self.available_fonts] else: fontList = [f.info.styleName for f in self.available_fonts] elif familyNames_set and familyNames_differ: # If for some reason only the family name is set, check if it is # different across UFOs. If it is, use it. fontList = [f.info.familyName for f in self.available_fonts] else: # Last resort (neither family nor style name are set), or the # family name is the same across UFOs (and no style name set): # Only display the UFO path. fontList = [os.path.basename(f.path) for f in self.available_fonts] # Dropdown menus w_width = self.w.getPosSize()[2] menu_width = w_width / 2 - 15 # It would be nice to make the dropdown respond to a width change, # of the window, but that is for next time. self.w.leftList = vanilla.PopUpButton( (x, y, menu_width, lineHeight), fontList, callback=self.font1ChangeCallback) self.w.leftList.set(self.available_fonts.index(font1)) self.w.rightList = vanilla.PopUpButton( (-menu_width - x, y, menu_width, lineHeight), fontList, callback=self.font2ChangeCallback) self.w.rightList.set(self.available_fonts.index(font2)) # Line Return y += lineHeight # vanilla.TextBox (not interactive field) self.w.gnameTextBox = vanilla.TextBox((x, y, 200, lineHeight), 'Glyph name') self.w.valueTextBox = vanilla.TextBox((x + 105, y, 200, lineHeight), 'Interpolation %') # Line Return y += lineHeight # "Glyph name" self.w.gnameTextInput = vanilla.EditText( (x, y, 80, lineHeight), self.gname.name, callback=self.setterButtonCallback) # "Percentage" Slider # Value self.w.valueTextInput = SliderEditIntStepper( (x + 105, y, -10, 22), minValue=-200, maxValue=400, value=50, increment=10, callback=self.setterButtonCallback) y += lineHeight y += 15 # -5 from bottom self.w.preview = GlyphPreview((0, y, -0, -5)) # Report self.w.reportText = vanilla.TextBox((x, -27, 400, lineHeight), '') # generate instance self.w.generate = vanilla.Button((-35, -27, 27, lineHeight), u"⬇", callback=self.generateCallback) if CurrentGlyph() != None: g = CurrentGlyph() else: g = gInit gname = g.name self.interpSetGlyph(gname) self.w.box = vanilla.Box((0, (y - 9), -0, -30)) self.setUpBaseWindowBehavior() self.w.open()
def __init__(self): bgColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 255, 255, 255, 255) self.w = Window((1200, 900), minSize=(900, 600)) self.w.getNSWindow().setBackgroundColor_(bgColor) self.w.fontList = SingleFontList(self, AllFonts(), (0, 0, 300, 250)) self.w.matrixModel = Group((15, 265, 270, 270)) self.w.matrixView = Group((300, 0, 0, -0)) self.master_matrix = [] self.instance_matrix = [] self.ipf = .5 self.xpf = 1 x, y, wi, he = self.w.getPosSize() wi = (wi - 300) / 3 he /= 3 for i, k in enumerate(['a', 'b', 'c']): self.master_matrix.append([]) self.instance_matrix.append([]) for j, l in enumerate(['a', 'b', 'c']): setattr(self.w.matrixView, 'back' + k + l, Box((wi * i, he * j, wi, he))) setattr(self.w.matrixView, k + l, GlyphPreview((wi * i, he * j, wi, he))) setattr(self.w.matrixModel, 'back' + k + l, Box((90 * i, 90 * j, 90, 90))) setattr( self.w.matrixModel, k + l, SquareButton((5 + (90 * i), 5 + (90 * j), 80, 80), '', callback=self.pickSpot, sizeStyle='mini')) setattr( self.w.matrixModel, 'reset' + k + l, SquareButton((1 + (90 * i), 1 + (90 * j), 20, 20), 'x', callback=self.clearSpot, sizeStyle='mini')) spotButton = getattr(self.w.matrixModel, k + l) resetpot = getattr(self.w.matrixModel, 'reset' + k + l) resetpot.key = spotButton.key = (i, j, k, l) spotButton.getNSButton().setBordered_(False) resetpot.getNSButton().setBezelStyle_(7) self.master_matrix[i].append([k + l, None]) self.instance_matrix[i].append([k + l, None]) self.w.interpolation = Group((10, 565, 280, 50)) self.w.interpolation.start = TextBox((7, 2, 20, 12), '0', sizeStyle='mini') self.w.interpolation.end = TextBox((-20, 2, 20, 12), '1', sizeStyle='mini') self.w.interpolation.title = TextBox((20, 0, -20, 17), 'Interpolation factor', sizeStyle='small', alignment='center') self.w.interpolation.slider = Slider((5, 27, -5, 15), minValue=0, maxValue=1, value=self.ipf, callback=self.sliderInput, tickMarkCount=5) self.w.interpolation.slider.name = 'ipf' self.w.extrapolation = Group((10, 632, 280, 50)) self.w.extrapolation.start = TextBox((7, 2, 20, 12), '1', sizeStyle='mini') self.w.extrapolation.end = TextBox((-20, 2, 20, 12), '3', sizeStyle='mini') self.w.extrapolation.title = TextBox((20, 0, -20, 17), 'Extrapolation factor', sizeStyle='small', alignment='center') self.w.extrapolation.slider = Slider((5, 27, -5, 15), minValue=0, maxValue=2, value=self.xpf, callback=self.sliderInput, tickMarkCount=5) self.w.extrapolation.slider.name = 'xpf' self.spotFocus = getattr(self.w.matrixModel, 'bb') self.w.updateMatrixButton = Button((10, 727, 280, 20), 'Update', callback=self.updateMasters) self.w.resetMatrixButton = Button((10, 755, 280, 20), 'Reset', callback=self.resetMatrix) self.newFont = [] addObserver(self, 'updateMasters', 'currentGlyphChanged') addObserver(self, 'updateMasters', 'draw') addObserver(self, 'updateFontList', 'fontDidOpen') addObserver(self, 'updateFontList', 'fontDidClose') self.w.bind('close', self.windowClose) self.w.bind('resize', self.windowResize) self.w.open()