Traceback (most recent call last):
File "<string>", line 174, in <module>
File "GlyphsApp/__init__.py", line 124, in __repr__
File "GlyphsApp/__init__.py", line 140, in __iter__
File "GlyphsApp/__init__.py", line 7295, in values
File "GlyphsApp/__init__.py", line 7257, in deactivateFeatures
NameError: global name 'copy' is not defined
I noticed this a few cutting edge versions ago, but have been busy and didn’t get around to reporting it. I compared the GlyphsApp __init__.py to a previous version and use of copy was added, but there’s no import copy. To work around for the moment I just added to my scripts:
I’m not sure the current implementation is what I would expect (I didn’t implement it). tab.layers returns a list of the layers that you have typed. It does not change if you activate features. What do you think?
Well, that’s a tricky question, Georg. I can imagine that returning the actual layers might be more logical in some cases. On the other hand: for the potential use I can think of just now it’s already fine with the typed layers. It would not return all the layers in cases like when you hit that Show All Masters command as well?
Hi! Is there a way to get matching layers before and after features in a tab? I see that tab.selectedLayers() somehow keeps track of it (when you select ff it switches to f_f with features on and vice versa). Here’s roughly what I’m trying to get:
That works, thank you!
Is that a bug with how escaped characters are counted as 2? Shouldn’t it be either 1 or length of the actually typed out characters?
tab.text = 'o/f_f n'
for which characterIndexForLayerIndex returns:
['o', 0]
['f_f', 1]
['n', 3] # shouldn’t this be either 2 or 6 though?
Oh, I see! However, in this case it also seems a bit off, because escaped characters add 2 to indexing:
tab.text = "o/f_f n"
layerIndex = 2 # which is n
charIndex = layoutManager.characterIndexForLayerIndex_(layerIndex)
print(tab.allLayers()[layerIndex]) # correct
print(tab.string[charIndex]) # out of range, charIndex-1 would be correct
Prints:
<GSLayer "Regular” (n)>
Traceback (most recent call last):
File "<macro panel>", line 5
IndexError: string index out of range
Yes. I was about it write this. In objectiveC, a string is UTF16. So an upper plane (anything above 0xFFFF) char is two bytes. Python seems to smooth over this. I’ll see what is the best way to deal with this. But maybe just adding on to your index for upper plane chars is enough?