def toggleLabels(self): if self.show_labels: self.show_labels = False self.generalContextMenus = [ { "name": Glyphs.localize( { 'en': u'Show Error Labels', 'de': u'Fehlerbeschriftung anzeigen' } ), "action": self.toggleLabels }, ] else: self.show_labels = True self.generalContextMenus = [ { "name": Glyphs.localize( { 'en': u'Hide Error Labels', 'de': u'Fehlerbeschriftung ausblenden' } ), "action": self.toggleLabels }, ] Glyphs.defaults["%s.showLabels" % plugin_id] = self.show_labels
def settings(self): self.menuName = "Red Arrows" self.keyboardShortcut = "a" self.keyboardShortcutModifier = (NSCommandKeyMask | NSShiftKeyMask | NSAlternateKeyMask) self.hide_labels_menu = [ { "name": Glyphs.localize({ "en": "Hide Error Labels", "de": "Fehlerbeschriftung ausblenden", }), "action": self.toggleLabels_, }, ] self.show_labels_menu = [ { "name": Glyphs.localize({ "en": "Show Error Labels", "de": "Fehlerbeschriftung anzeigen", }), "action": self.toggleLabels_, }, ] self.show_labels = Glyphs.defaults["%s.showLabels" % plugin_id] self.show_labels = not (self.show_labels) self.toggleLabels_(None)
def settings(self): self.menuName = Glyphs.localize( { "en": "Curve Equalizer", "de": "Kurven-Equalizer", # "fr": "Mon filtre", # "es": "Mi filtro", # "pt": "Meu filtro", # "jp": "私のフィルター", # "ko": "내 필터", # "zh": "我的过滤器", } ) # Word on Run Button (default: Apply) self.actionButtonLabel = Glyphs.localize( { "en": "Equalize selected", "de": "Auf Auswahl anwenden", "fr": "Appliquer", "es": "Aplicar", "pt": "Aplique", "jp": "申し込む", "ko": "대다", "zh": "应用", } ) # Build UI self.build_ui(useFloatingWindow=False) self.dialog = self.paletteView.group.getNSView()
def activate(self): self.current_layer = self.get_current_layer() if self.current_layer is not None: self.loadScrawl() self.w.pen_size.set(self.pen_size) self.w.pen_size_text.set(self.pen_size) self.prev_location = None Glyphs.addCallback(self.update, UPDATEINTERFACE)
def toggleLabels_(self, sender): if self.show_labels: self.show_labels = False self.generalContextMenus = self.show_labels_menu self.startMouseMoved() else: self.show_labels = True self.generalContextMenus = self.hide_labels_menu self.stopMouseMoved() Glyphs.defaults["%s.showLabels" % plugin_id] = self.show_labels Glyphs.redraw()
def executeAndReport(kernStrings): # brings macro window to front and clears its log: Glyphs.clearLog() Glyphs.showMacroWindow() # print status and modify Sample Texts: print("Adding %i lines to Sample Texts..." % len(kernStrings)) if not addToSampleText(kernStrings): print("Warning: could not add the lines.") else: print("Done.")
def __init__(self): self.tool = None self.curvesegments = [] self.values = [] self.vmin = None self.vmax = None self.histogram = {} self.glyphchanged = False self.numberofcurvesegments = 0 self.glyphstring = None self.preferences = {} self.preferenceKeys = ('illustrationPositionIndex', 'curveGain', 'useFader', 'fader') self.unitsperem = 1000 self.curves = 'cubic' self.loadPreferences() # Preferences justInstalled = False if not self.getPreference('illustrationPositionIndex'): self.setPreference('illustrationPositionIndex', 1) justInstalled = True if not self.getPreference('curveGain'): self.setPreference('curveGain', Interpolate(curveGain[0], curveGain[1], .2)) justInstalled = True self.setPreference('fader', 1.0) self.setPreference('useFader', False) self.savePreferences() ''' # UI self.prefwindow = SpeedPunkPrefWindow(self) self.drawGradientImage() ''' ## Welcome if justInstalled and environment == 'GlyphsApp': Message( Glyphs.localize({ 'en': u'Thank you for choosing Speed Punk. You’ll find me in the View menu under ‘Show Speed Punk’ or with the keyboard shortcut Cmd+Shift+X. The plug-in settings have moved into the context menu (right click).\n\nEnjoy and make sure to follow @yanone on Twitter.', 'de': u'Danke zur Wahl von Speed Punk. Du findest mich im Ansicht-Menü unter ‘Speed Punk anzeigen’ oder mit dem Tastenkürzel Cmd+Shift+X. Die Plug-In-Einstellungen sind ins Kontextmenü (Rechtsklick) gewandert.\n\nViel Spaß und wir sehen uns bei @yanone auf Twitter.', }), Glyphs.localize({ 'en': u'Welcome to Speed Punk %s' % VERSION, 'de': u'Willkommen zu Speed Punk %s' % VERSION, })) return
def foreground(self, layer): if self.should_update_report: #self.logToConsole( "_updateOutlineCheck: %s" % layer) self._updateOutlineCheck(layer) #self.logToConsole( "foreground: Errors: %s" % self.errors ) #self.should_update_report = False try: try: self.mouse_position = self.controller.graphicView().getActiveLocation_(Glyphs.currentEvent()) except Exception as e: self.logToConsole( "foreground: mouse_position: %s" % str(e) ) self.mouse_position = (0, 0) currentController = self.controller.view().window().windowController() if currentController: tool = currentController.toolDrawDelegate() # don't activate if on cursor tool, or pan tool if not ( tool.isKindOfClass_(NSClassFromString("GlyphsToolText")) or tool.isKindOfClass_(NSClassFromString("GlyphsToolHand")) or tool.isKindOfClass_(NSClassFromString("GlyphsToolTrueTypeInstructor")) ): if len(self.errors) > 0: self._drawArrows() except Exception as e: self.logToConsole( "foreground: %s" % str(e) )
def settings(self): self.menuName = "Red Arrows" self.keyboardShortcut = 'a' self.keyboardShortcutModifier = NSCommandKeyMask | NSShiftKeyMask | NSAlternateKeyMask self.generalContextMenus = [ {"name": Glyphs.localize({'en': u'Show Error Labels', 'de': u'Fehlerbeschriftung anzeigen'}), "action": self.toggleLabels}, ]
def settings(self): self.menuName = Glyphs.localize({ 'en': 'Optimize Start Nodes', 'de': 'Startpunkte optimieren', 'es': 'Optimizar los primeros nodos', 'fr': 'Optimiser les nœuds prémiers', })
def showWindow(self): print "__window" self.glyphlist = [] Font = Glyphs.orderedDocuments()[0].font for Layer in Font.selectedLayers: self.glyphlist.append(Layer.parent.name) self.mode = 'normal' # TODO implement proper handling of MM self._fontListController.setContent_(NSDocumentController.sharedDocumentController().valueForKeyPath_("documents.font")) self._window.makeKeyAndOrderFront_(self)
def start(self): mainMenu = NSApplication.sharedApplication().mainMenu() s = objc.selector(self.editMasterGrid, signature=b'v@:@') newMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( Glyphs.localize({ 'en': "Master Grid…", 'de': 'Master-Raster…' }), s, "") newMenuItem.setTarget_(self) submenu = mainMenu.itemAtIndex_(2).submenu() submenu.insertItem_atIndex_(newMenuItem, 12)
def addMenuItem(self): mainMenu = NSApplication.sharedApplication().mainMenu() s = objc.selector(self.selectGlyphsWithErrors,signature='v@:') newMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( Glyphs.localize({ 'en': u"Select Glyphs With Outline Errors", 'de': u'Glyphen mit Outlinefehlern auswählen', 'ko': u"윤곽선 오류가 있는 글리프 선택" }), s, "" ) newMenuItem.setTarget_(self) mainMenu.itemAtIndex_(2).submenu().insertItem_atIndex_(newMenuItem, 11)
def addMenuItem(self): mainMenu = NSApplication.sharedApplication().mainMenu() s = objc.selector(self.selectGlyphsWithErrors, signature=b"v@:@") newMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( Glyphs.localize({ "en": "Select Glyphs With Outline Errors", "de": "Glyphen mit Outlinefehlern auswählen", "ko": "윤곽선 오류가 있는 글리프 선택", }), s, "", ) newMenuItem.setTarget_(self) mainMenu.itemAtIndex_(2).submenu().insertItem_atIndex_(newMenuItem, 12)
def SearchAndReplaceInAnchorNamesMain(sender): try: searchString = window.searchFor.get() replaceString = window.replaceBy.get() thisFont = Glyphs.font # frontmost font listOfSelectedLayers = thisFont.selectedLayers # active layers of currently selected glyphs for thisLayer in listOfSelectedLayers: # loop through layers thisGlyph = thisLayer.parent reportString = "Anchors renamed in %s:" % thisGlyph.name displayReportString = False for thisGlyphLayer in thisGlyph.layers: for thisAnchor in thisGlyphLayer.anchors: oldAnchorName = thisAnchor.name newAnchorName = oldAnchorName.replace( searchString, replaceString) if oldAnchorName != newAnchorName: thisAnchor.name = newAnchorName reportString += "\n layer '%s': %s > %s" % ( thisGlyphLayer.name, oldAnchorName, newAnchorName) displayReportString = True if displayReportString: print(reportString) if not SavePreferences(): print( "Note: 'Search And Replace In Anchor Names' could not write preferences." ) window.close() # delete if you want window to stay open except Exception as e: # brings macro window to front and reports error: Glyphs.showMacroWindow() print("Search And Replace In Anchor Names Error: %s" % e)
def foreground(self, layer): try: self.mouse_position = self.editViewController().graphicView( ).getActiveLocation_(Glyphs.currentEvent()) except: # self.logToConsole("foreground: mouse_position: %s" % str(e)) self.mouse_position = None return if self.mouse_position is not None: # Draw a preview circle at the mouse position x, y = self.mouse_position rect = NSMakeRect(x - self.pen_size / 2, y - self.pen_size * self.pixel_ratio / 2, self.pen_size, self.pen_size * self.pixel_ratio) path = NSBezierPath.bezierPathWithOvalInRect_(rect) path.setLineWidth_(1) if self.erase: NSColor.redColor().set() else: NSColor.lightGrayColor().set() path.stroke()
def foreground(self, layer): # self.logToConsole("_updateOutlineCheck: %s" % layer) self._updateOutlineCheck(layer) # self.logToConsole("foreground: Errors: %s" % self.errors ) try: self.mouse_position = ( self.controller.graphicView().getActiveLocation_( Glyphs.currentEvent())) except Exception as e: self.logToConsole("foreground: mouse_position: %s" % str(e)) self.mouse_position = (0, 0) currentController = self.controller.view().window().windowController() if currentController: tool = currentController.toolDrawDelegate() # don't activate if on cursor tool, or pan tool if not (tool.isKindOfClass_(NSClassFromString("GlyphsToolText")) or tool.isKindOfClass_(NSClassFromString("GlyphsToolHand")) or tool.isKindOfClass_( NSClassFromString("GlyphsToolTrueTypeInstructor"))): if self.errors: self._drawArrows()
def start(self): for window in Glyphs.windows(): if window.className() == "GSMacroWindow": self.macroPanel = window if not self.macroPanel: LogError("Floating Macro Panel: could not find macro panel.") return self.macroPanel.setLevel_(NSFloatingWindowLevel) NSNotificationCenter.defaultCenter().addObserverForName_object_queue_usingBlock_( NSApplicationWillResignActiveNotification, None, NSOperationQueue.mainQueue(), lambda x: self.willResignActive(x), ) NSNotificationCenter.defaultCenter().addObserverForName_object_queue_usingBlock_( NSApplicationWillBecomeActiveNotification, None, NSOperationQueue.mainQueue(), lambda x: self.willBecomeActive(x), )
def settings(self): self.menuName = Glyphs.localize({ 'en': 'Master Grid', 'de': 'Master-Raster' })
def deactivate(self): Glyphs.removeCallback(self.mouseDidMove_) Glyphs.removeCallback(self.update)
def __init__(self): self.tool = None self.curvesegments = [] self.values = [] self.vmin = None self.vmax = None self.histogram = {} self.glyphchanged = False self.numberofcurvesegments = 0 self.glyphstring = None self.preferences = {} self.preferenceKeys = ('illustrationPositionIndex', 'curveGain', 'useFader', 'fader') self.unitsperem = 1000 self.curves = 'cubic' self.loadPreferences() # Preferences justInstalled = False if not self.getPreference('illustrationPositionIndex'): self.setPreference('illustrationPositionIndex', 1) justInstalled = True if not self.getPreference('curveGain'): self.setPreference('curveGain', Interpolate(curveGain[0], curveGain[1], .2)) justInstalled = True self.setPreference('fader', 1.0) self.setPreference('useFader', False) self.savePreferences() ''' # UI self.prefwindow = SpeedPunkPrefWindow(self) self.drawGradientImage() ''' ## Welcome if justInstalled and environment == 'GlyphsApp': Message( message=Glyphs.localize({ 'en': 'Thank you for choosing Speed Punk. You’ll find me in the View menu under ‘Show Speed Punk’ or with the keyboard shortcut Cmd+Shift+X. The plug-in settings have moved into the context menu (right click).\n\nEnjoy and make sure to follow @yanone on Twitter.', 'de': 'Danke zur Wahl von Speed Punk. Du findest mich im Ansicht-Menü unter ‘Speed Punk anzeigen’ oder mit dem Tastenkürzel Cmd+Shift+X. Die Plug-in-Einstellungen sind ins Kontextmenü (Rechtsklick) gewandert.\n\nViel Spaß und wir sehen uns bei @yanone auf Twitter.', 'fr': 'Merci d’avoir choisi Speed Punk. Retrouvez-le dans le menu Affichage sous ‘Afficher Speed Punk’ ou avec le raccourci Cmd+Shift+X. Les préférences se trouvent dans le menu contextuel (clic-droit).\n\nProfitez-en et suivez-moi sur Twitter: @yanone.', 'es': '¡Gracias por instalar Speed Punk! Lo encontrarás en el menú «Vista > Mostrar Speed Punk» o con el atajo de teclado Cmd+Shift+X. Botón derecho para ver las preferencias. ¡Disfrútalo! Puedes seguirme en Twitter: @yanone.', 'pt': 'Obrigado por instalar o Speed Punk! Você o encontrará no menu «Visualizar > Exibir Speed Punk» ou com o atalho de teclado Cmd+Shift+X. Clique com o botão direito do mouse para ver as preferências. Aproveite! Você pode me seguir no Twitter: @yanone.', 'ja': 'Speed Punk を使っていただき有難うございます。Speed Punkは表示メニューバーの「Speed Punk を表示」または Cmd+Shift+X ショートカットで使えます。プラグイン設定は右クリックのコンテクストメニューにあります。\n\nお楽しみください。Twitter の @yanone もよろしくお願いします。', 'ko': '“Speed Punk”를 사용해주셔서 감사합니다. 상단메뉴의 ’보기 > 보기 Speed Punk’ 클릭 또는 단축키 Cmd + Shift + X로 실행할 수 있습니다. 플러그인 설정은 마우스 오른쪽 > 컨텍스트 메뉴에 있습니다.\n\n트위터에서 @yanone 를 팔로우 해주시기 바랍니다.', }), title=Glyphs.localize({ 'en': 'Welcome to Speed Punk %s' % VERSION, 'de': 'Willkommen zu Speed Punk %s' % VERSION, 'fr': 'Bienvenu·e·s chez Speed Punk %s' % VERSION, 'es': 'Bienvenido a Speed Punk %s' % VERSION, 'pt': 'Bem-vindo ao Speed Punk %s' % VERSION, 'ja': 'Speed Punk %s へようこそ' % VERSION, 'ko': '“Speed Punk %s”를 사용해주셔서 감사합니다.' % VERSION, }), ) return
def stringToListOfGlyphsForFont(string, Font, report=True, excludeNonExporting=True, suffix=""): # parse string into parseList: parseList = [] waitForSeparator = False parsedName = "" # cut off comment: if "#" in string: string = string[:string.find("#")].strip() # parse string: for i, x in enumerate(string): if x in "/ ": if parsedName: parseList.append(parsedName) parsedName = "" if x == "/": waitForSeparator = True else: waitForSeparator = False elif waitForSeparator: parsedName += x if i == len(string) - 1: parseList.append(parsedName) else: parsedName = "" parseList.append(x) # go through parseList and find corresponding glyph in Font: glyphList = [] for parsedName in parseList: if parsedName.startswith("@"): # category and subcategory: if ":" in parsedName: category, subcategory = parsedName[1:].split(":") else: category, subcategory = parsedName[1:], None # TODO parse categoryGlyphs = listOfNamesForCategories( Font, category, subcategory, #OK "latin", # requiredScript, # need to implement still None, # excludedGlyphNameParts, # need to implement still excludeNonExporting, #OK suffix=suffix, ) if categoryGlyphs: glyphList += categoryGlyphs if report: print(u"Added glyphs for category %s, subcategory %s: %s" % (category, subcategory, ", ".join(categoryGlyphs))) elif report: print( u"Warning: no glyphs found for category %s, subcategory %s." % (category, subcategory)) else: # actual single glyph names: glyph = Font.glyphForName_(parsedName + suffix) # actual single character: if not glyph and len(parsedName) == 1: unicodeForName = "%04X" % ord(parsedName) glyphInfo = Glyphs.glyphInfoForUnicode(unicodeForName) if glyphInfo: glyphName = "%s%s" % (glyphInfo.name, suffix) glyph = Font.glyphs[glyphName] # check if glyph exists, exports, and collect in glyphList: if glyph: if (glyph.export or not excludeNonExporting): glyphList.append(glyph) elif report: print(u"Ignoring non-exporting glyph '%s'." % (parsedName + suffix)) elif report: print(u"Warning: Could not find glyph for '%s'." % (parsedName + suffix)) return glyphList
def willDeactivate(self): try: Glyphs.removeCallback(self.mouseDidMove) #Glyphs.removeCallback(self.updateReport) except Exception as e: self.logToConsole( "willDeactivate: %s" % str(e) )
def willActivate(self): #Glyphs.addCallback(self.updateReport, UPDATEINTERFACE) Glyphs.addCallback(self.mouseDidMove, MOUSEMOVED)
def mouseDidMove(self, notification): Glyphs.redraw()
def updateReport(self, notification): if DEBUG: self.logToConsole( "updateReport") self.should_update_report = True Glyphs.redraw()
def mouseDidMove_(self, event): Glyphs.redraw()
def settings(self): self.name = Glyphs.localize({'en': 'DrawBot'})
def settings(self): from vanilla import Group, Slider, TextBox, Window self.name = 'Scrawl' self.slider_value = 1 # current slider value # Create Vanilla window and group with controls viewWidth = 266 viewHeight = 42 self.sliderMenuView = Window((viewWidth, viewHeight)) self.sliderMenuView.group = Group((0, 0, viewWidth, viewHeight)) self.w = self.sliderMenuView.group y = 0 self.w.text = TextBox((20, y, -20, 17), "%s Pen Size" % self.name) y += 18 self.w.pen_size = Slider( (20, y, -60, 24), minValue=1, maxValue=256, value=float(self.slider_value), tickMarkCount=0, # stopOnTickMarks = False, # continuuous = True, callback=self.slider_callback, sizeStyle="small", ) self.w.pen_size_text = TextBox((-50, y + 3, -20, 17), "%s" % default_pen_size) self.generalContextMenus = [ { "view": self.sliderMenuView.group.getNSView() }, { "name": Glyphs.localize({ 'en': u'Delete Scrawl', 'de': u'Gekritzel löschen' }), "action": self.delete_data }, { "name": Glyphs.localize({ 'en': u'Save Scrawl To Background Image', 'de': u'Gekritzel als Hintergrundbild speichern' }), "action": self.save_background }, # { # "name": Glyphs.localize({ # 'en': u'Save current size as master default', # 'de': u'Aktuelle Größe als Master-Standard speichern' # }), # "action": self.save_background # }, ] self.keyboardShortcut = 'c' self.pen_size = default_pen_size self.pixel_size = default_pixel_size self.pixel_ratio = default_pixel_ratio self.rect = NSMakeRect(0, 0, 1000, 1000) self.data = None self.prev_location = None self.erase = False self.mouse_position = None self.layer = None self.needs_save = False self.current_layer = self.get_current_layer()
def deactivate(self): Glyphs.removeCallback(self.update)
# MenuTitle: Increase Kerning # -*- coding: utf-8 -*- __doc__ = """ Uses modifier keys to adjust the kerning. """ from AppKit import NSEvent from GlyphsApp import Glyphs Glyphs.clearLog() # Glyphs.showMacroWindow() # --- From mekkablue --- keysPressed = NSEvent.modifierFlags() shiftKey = 131072 controlKey = 262144 optionKey = 524288 commandKey = 1048576 shiftKeyPressed = keysPressed & shiftKey == shiftKey controlKeyPressed = keysPressed & controlKey == controlKey optionKeyPressed = keysPressed & optionKey == optionKey commandKeyPressed = keysPressed & commandKey == commandKey # --- def get_current_glyphs(): g1 = Glyphs.font.currentTab.layers[Glyphs.font.currentTab.layersCursor - 1].parent g2 = Glyphs.font.currentTab.layers[ Glyphs.font.currentTab.layersCursor].parent return g1, g2
def settings(self): self.menuName = Glyphs.localize({ 'en': u'All Coordinates', 'de': u'Alle Koordinaten' })
def settings(self): self.menuName = Glyphs.localize({'en': u'Scrawl'})