Skip to content

Instantly share code, notes, and snippets.

@weiweihuanghuang
Created November 24, 2017 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weiweihuanghuang/4ed1f3556b4911bad55cbd1a8dfa31fb to your computer and use it in GitHub Desktop.
Save weiweihuanghuang/4ed1f3556b4911bad55cbd1a8dfa31fb to your computer and use it in GitHub Desktop.
Select Same Glyph and Layer Color
#MenuTitle: Select Same Glyph and Layer Color
# -*- coding: utf-8 -*-
__doc__="""
In Font view, select glyphs with the same color(s) and layer color as the currently selected one(s).
"""
import GlyphsApp
def indexSetWithIndex( index ):
indexSet = NSIndexSet.alloc().initWithIndex_( index )
return indexSet
thisFont = Glyphs.font
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
glyphColorIndexes = []
LayerColorIndexes = []
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()
thisLayerColorIndex = displayedGlyphsInFontView[i].layers[thisFont.selectedFontMaster.id].colorIndex()
if not thisGlyphColorIndex in glyphColorIndexes:
glyphColorIndexes.append( thisGlyphColorIndex )
if not thisLayerColorIndex in LayerColorIndexes:
LayerColorIndexes.append( thisLayerColorIndex )
if glyphColorIndexes:
for i in displayedIndexRange:
if displayedGlyphsInFontView[i].colorIndex() in glyphColorIndexes and displayedGlyphsInFontView[i].layers[thisFont.selectedFontMaster.id].colorIndex() in LayerColorIndexes:
fontView.addSelectionIndexes_( indexSetWithIndex(i) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment