Last active
July 28, 2019 09:10
-
-
Save mekkablue/d07533c1dbd053aed4ef2c0f81c4a816 to your computer and use it in GitHub Desktop.
Select Same Glyph/Layer Color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#MenuTitle: Select Same Color | |
# -*- coding: utf-8 -*- | |
__doc__=""" | |
In Font view, select glyphs with the same color(s) as the currently selected one(s). | |
""" | |
from AppKit import NSIndexSet | |
def indexSetWithIndex( index ): | |
indexSet = NSIndexSet.alloc().initWithIndex_( index ) | |
return indexSet | |
thisDoc = Glyphs.currentDocument # frontmost document | |
try: | |
fontView = thisDoc.windowController().tabBarControl().tabItemAtIndex_(0).glyphsArrayController() | |
except: | |
fontView = thisDoc.windowController().tabBarControl().viewControllers()[0].glyphsArrayController() | |
displayedGlyphsInFontView = fontView.arrangedObjects() # all glyphs currently displayed | |
colorIndexes = [] | |
if displayedGlyphsInFontView: | |
displayedIndexRange = range(len(displayedGlyphsInFontView)) # indexes of glyphs in Font view | |
for i in displayedIndexRange: | |
if fontView.selectionIndexes().containsIndex_(i): | |
thisGlyphColorIndex = displayedGlyphsInFontView[i].colorIndex() | |
if not thisGlyphColorIndex in colorIndexes: | |
colorIndexes.append( thisGlyphColorIndex ) | |
if colorIndexes: | |
for i in displayedIndexRange: | |
if displayedGlyphsInFontView[i].colorIndex() in colorIndexes: | |
fontView.addSelectionIndexes_( indexSetWithIndex(i) ) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#MenuTitle: Select Same Layer Color | |
# -*- coding: utf-8 -*- | |
__doc__=""" | |
In Font view, select glyphs with the same color(s) as the currently selected one(s). | |
""" | |
from AppKit import NSIndexSet | |
def indexSetWithIndex( index ): | |
indexSet = NSIndexSet.alloc().initWithIndex_( index ) | |
return indexSet | |
thisDoc = Glyphs.currentDocument # frontmost document | |
try: | |
fontView = thisDoc.windowController().tabBarControl().tabItemAtIndex_(0).glyphsArrayController() | |
except: | |
fontView = thisDoc.windowController().tabBarControl().viewControllers()[0].glyphsArrayController() | |
displayedGlyphsInFontView = fontView.arrangedObjects() # all glyphs currently displayed | |
colorIndexes = [] | |
thisFont = Glyphs.font | |
if displayedGlyphsInFontView: | |
displayedIndexRange = range(len(displayedGlyphsInFontView)) # indexes of glyphs in Font view | |
for i in displayedIndexRange: | |
if fontView.selectionIndexes().containsIndex_(i): | |
thisGlyphColorIndex = displayedGlyphsInFontView[i].layers[thisFont.selectedFontMaster.id].colorIndex() | |
if not thisGlyphColorIndex in colorIndexes: | |
colorIndexes.append( thisGlyphColorIndex ) | |
if colorIndexes: | |
for i in displayedIndexRange: | |
if displayedGlyphsInFontView[i].layers[thisFont.selectedFontMaster.id].colorIndex() in colorIndexes: | |
fontView.addSelectionIndexes_( indexSetWithIndex(i) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment