diff --git a/LabelKey.glyphsPalette/Contents/Info.plist b/LabelKey.glyphsPalette/Contents/Info.plist index fd13dba..7e22376 100644 --- a/LabelKey.glyphsPalette/Contents/Info.plist +++ b/LabelKey.glyphsPalette/Contents/Info.plist @@ -1,11 +1,9 @@ - + CFBundleDevelopmentRegion - English - CFBundleDisplayName - Label Key + en CFBundleExecutable plugin CFBundleIdentifier @@ -14,25 +12,17 @@ 6.0 CFBundleName Label Key - CFBundlePackageType - BNDL - CFBundleVersion - 2.0 CFBundleShortVersionString 2.0 - UpdateFeedURL - https://github.com/RobertPratley/labelKey/LabelKey.glyphsPalette/Contents/Info.plist - productPageURL - https://github.com/RobertPratley/labelKey - productReleaseNotes - + CFBundleVersion + 3 NSHumanReadableCopyright Copyright, RobertPratley, 2017 NSPrincipalClass labelKey PyMainFileNames - ../MacOS/main.py + plugin.py diff --git a/LabelKey.glyphsPalette/Contents/MacOS/main.py b/LabelKey.glyphsPalette/Contents/MacOS/main.py deleted file mode 100644 index 98f307d..0000000 --- a/LabelKey.glyphsPalette/Contents/MacOS/main.py +++ /dev/null @@ -1,11 +0,0 @@ -def _run(*scripts): - global __file__ - import os, sys #, site - sys.frozen = 'macosx_plugin' - base = os.environ['RESOURCEPATH'] - for script in scripts: - path = os.path.join(base, script) - __file__ = path - execfile(path, globals(), globals()) - -_run('plugin.py') diff --git a/LabelKey.glyphsPalette/Contents/MacOS/plugin b/LabelKey.glyphsPalette/Contents/MacOS/plugin old mode 100644 new mode 100755 index b21f0e4..ce7d93c Binary files a/LabelKey.glyphsPalette/Contents/MacOS/plugin and b/LabelKey.glyphsPalette/Contents/MacOS/plugin differ diff --git a/LabelKey.glyphsPalette/Contents/PkgInfo b/LabelKey.glyphsPalette/Contents/PkgInfo deleted file mode 100644 index 19a9cf6..0000000 --- a/LabelKey.glyphsPalette/Contents/PkgInfo +++ /dev/null @@ -1 +0,0 @@ -BNDL???? \ No newline at end of file diff --git a/LabelKey.glyphsPalette/Contents/Resources/plugin.py b/LabelKey.glyphsPalette/Contents/Resources/plugin.py index 0641f38..8899be3 100644 --- a/LabelKey.glyphsPalette/Contents/Resources/plugin.py +++ b/LabelKey.glyphsPalette/Contents/Resources/plugin.py @@ -1,4 +1,5 @@ # encoding: utf-8 +from __future__ import division, print_function, unicode_literals ########################################################################################################### # @@ -11,6 +12,7 @@ # ########################################################################################################### from vanilla import * +import objc import re import os import codecs @@ -19,21 +21,21 @@ class labelKey(PalettePlugin): - - def settings( self ): + @objc.python_method + def settings(self): self.name = 'Label Key' self.width = 160 - self.elementHeight = 16 + self.elementHeight = 17 keyQuantity = 12 self.height = keyQuantity * self.elementHeight self.paletteView = Window((self.width, self.height + 10)) - self.paletteView.frame = Group((0, 0, self.width, self.height + 5)) + self.paletteView.frame = Group((0, 0, self.width, self.height + 10)) self.paletteView.frame.swatches = CanvasView((10, 0, -10, 0), self) self.dialog = self.paletteView.frame.getNSView() - colorsData = Glyphs.defaults["LabelColors"] + #colorsData = GSGlyphsInfo.labelColors() colorKeys = ["red", "orange", "brown", @@ -46,52 +48,95 @@ def settings( self ): "magenta", "lightGray", "charcoal"] - colours = [] - for colorData in colorsData: - color = NSUnarchiver.unarchiveObjectWithData_(colorData) - colours.append(color) + colours = [ + (0.85, 0.26, 0.06, 0.9), + (0.99, 0.62, 0.11, 0.9), + (0.65, 0.48, 0.20, 0.9), + (0.97, 0.90, 0.00, 0.9), + (0.67, 0.95, 0.38, 0.9), + (0.04, 0.57, 0.04, 0.9), + (0.06, 0.60, 0.98, 0.9), + (0.00, 0.20, 0.88, 0.9), + (0.50, 0.09, 0.79, 0.9), + (0.98, 0.36, 0.67, 0.9), + (0.75, 0.75, 0.75, 0.9), + (0.25, 0.25, 0.25, 0.9), + ] + # for colorData in colorsData: + # color = NSUnarchiver.unarchiveObjectWithData_(colorData) + # colours.append(color) self.colours = dict(zip(colorKeys, colours)) + self.order = self.mapKeys(self.getKeyFile()) + @objc.python_method def update(self, sender): if hasattr(self.paletteView.frame, 'labels'): delattr(self.paletteView.frame, 'labels') colourLabels, self.order = self.mapKeys(self.getKeyFile()) - self.paletteView.frame.labels = Group((27, 4, -10, 0)) + self.paletteView.frame.labels = Group((0, 4, -10, 0)) for num, i in enumerate(self.order): - setattr(self.paletteView.frame.labels, i, TextBox((0, num * self.elementHeight, 0, 22), colourLabels[i], sizeStyle="small")) + setattr(self.paletteView.frame.labels, i, TextBox((24, num * self.elementHeight, 0, 22), colourLabels[i], sizeStyle="small")) + + newHeight = self.elementHeight * len(self.order) self.paletteView.frame.resize(self.width, newHeight + 10) - def draw( self, view ): + @objc.python_method + def draw(self, view): keyDiameter = 10 height = view.bounds().size.height for num, i in enumerate(self.order, 1): if bool(re.search(r"\d", i)): + duplicateColour = re.match(r".*?(?=\d)", i).group(0) self.colours[duplicateColour].set() else: - self.colours[i].set() - NSBezierPath.bezierPathWithOvalInRect_(((0, height - (num * self.elementHeight)), (keyDiameter, keyDiameter))).fill() + NSColor.colorWithRed_green_blue_alpha_(*(self.colours[i])).set() + + NSBezierPath.bezierPathWithOvalInRect_(((0, height - (num * self.elementHeight)), (keyDiameter, keyDiameter))).fill() - def getKeyFile( self ): - keyFile = None + @objc.python_method + def getKeyFile(self): + keyFilePath = None + keyFileName = 'colorNames.txt' + # Get colorNames.txt file next to Glyph file try: - thisDirPath = os.path.dirname(self.windowController().document().font.filepath) - localKeyFile = thisDirPath + '/labelkey.txt' - if os.path.exists(localKeyFile): - keyFile = localKeyFile + thisDirPath = os.path.dirname(self.windowController().document().fileURL().path()) + localKeyFilePath = os.path.join(thisDirPath, keyFileName) + if os.path.exists(localKeyFilePath): + keyFilePath = localKeyFilePath except: pass - if keyFile is None: - keyFile = os.path.expanduser('~/Library/Application Support/Glyphs/Info/labelkey.txt') - return keyFile + if keyFilePath is None: + + if Glyphs.versionNumber >= 3: + keyFolderPath = '~/Library/Application Support/Glyphs 3/Info' + else: + keyFolderPath = '~/Library/Application Support/Glyphs/Info' + + keyFolderPath = os.path.expanduser(keyFolderPath) + + if not os.path.exists(keyFolderPath): + os.makedirs(keyFolderPath) + + keyFilePath = os.path.join(keyFolderPath, keyFileName) + if not os.path.exists(keyFilePath): + f = codecs.open(keyFilePath, mode="w", encoding="utf-8") + f.write("None=🫥 None\nred=🚨 Red\norange=🦊 Orange\nbrown=🪵 Brown\nyellow=🌼 Yellow\nlightGreen=🍀 Light green\ndarkGreen=🫑 Dark green\nlightBlue=💎 Light blue\ndarkBlue=🌀 Dark blue\npurple=🔮 Purple\nmagenta=🌺 Magenta\nlightGray=🏐 Light Gray\ncharcoal=🎱 Charcoal") + f.close() + + return keyFilePath + + @objc.python_method + def mapKeys(self, keyFile): - def mapKeys( self, keyFile ): order = [] colourLabels = {} if os.path.exists(keyFile): with codecs.open(keyFile, "r", "utf-8") as file: for line in file: + if "None" in line: continue + colour = re.match(r".*?(?=\=)", line).group(0) label = re.search(r"(?<=\=).*", line).group(0) colourLabels[colour] = label @@ -107,6 +152,7 @@ def setWindowController_(self, windowController): import traceback self.logError(traceback.format_exc()) + @objc.python_method def __file__(self): """Please leave this method unchanged""" return __file__ diff --git a/README.md b/README.md index 5c61660..1c282df 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ It adds a new palette to the sidebar displaying a user defined key for Glyphs' c ### How to use -The plugin requires a labelkey.txt file stored in either ~/Library/Application Support/Glyphs/info/ or the same directory as the current Glyphs source file. Preference is given to the latter allowing for the sharing of the labelkey.txt file with glyphs source files to retain labelling information between project contributors. +The plugin requires a `colorNames.txt` file stored in either ~/Library/Application Support/Glyphs/info/ or the same directory as the current Glyphs source file. Preference is given to the latter allowing for the sharing of the labelkey.txt file with glyphs source files to retain labelling information between project contributors. -The labelkey.txt file requires the formatting `colorName=meaning`, with each key on a newline and with no space surrounding the '='. The order of the key will follow the order specified in the text file. An example, with the defined colorNames is given below. +The `colorNames.txt` file requires the formatting `colorName=meaning`, with each key on a newline and with no space surrounding the '='. The order of the key will follow the order specified in the text file. An example, with the defined colorNames is given below. ``` red=Red