Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions LabelKey.glyphsPalette/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>Label Key</string>
<string>en</string>
<key>CFBundleExecutable</key>
<string>plugin</string>
<key>CFBundleIdentifier</key>
Expand All @@ -14,25 +12,17 @@
<string>6.0</string>
<key>CFBundleName</key>
<string>Label Key</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleVersion</key>
<string>2.0</string>
<key>CFBundleShortVersionString</key>
<string>2.0</string>
<key>UpdateFeedURL</key>
<string>https://github.com/RobertPratley/labelKey/LabelKey.glyphsPalette/Contents/Info.plist</string>
<key>productPageURL</key>
<string>https://github.com/RobertPratley/labelKey</string>
<key>productReleaseNotes</key>
<string></string>
<key>CFBundleVersion</key>
<string>3</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright, RobertPratley, 2017</string>
<key>NSPrincipalClass</key>
<string>labelKey</string>
<key>PyMainFileNames</key>
<array>
<string>../MacOS/main.py</string>
<string>plugin.py</string>
</array>
</dict>
</plist>
11 changes: 0 additions & 11 deletions LabelKey.glyphsPalette/Contents/MacOS/main.py

This file was deleted.

Binary file modified LabelKey.glyphsPalette/Contents/MacOS/plugin
100644 → 100755
Binary file not shown.
1 change: 0 additions & 1 deletion LabelKey.glyphsPalette/Contents/PkgInfo

This file was deleted.

94 changes: 70 additions & 24 deletions LabelKey.glyphsPalette/Contents/Resources/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: utf-8
from __future__ import division, print_function, unicode_literals

###########################################################################################################
#
Expand All @@ -11,6 +12,7 @@
#
###########################################################################################################
from vanilla import *
import objc
import re
import os
import codecs
Expand All @@ -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",
Expand All @@ -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
Expand All @@ -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__
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down