How to properly set tab’s master?

Hi! After I insert layers to tab.layers, and try to switch master through interface, it only changes the selected layer:

How can I hook them up to the master, so they are treated together (unless layer is different)?

This is for a tweak for Change Case plugin, so I want to keep user’s layers and can’t set it through tab.text.

When you set tab.layers, each layer has the master information attached. Like when you click the master in the layer panel for each layer. If you don’t like that, you need to use the tab.text API:

string = ""
for l in Font.selectedLayers:
	char = Font.characterForGlyph_(l.parent)
	string += chr(char)
tab = Font.tabs[0]
tab.text = string

Can I ask what’s the API for clicking the Layers panel in a tab? tab.layers[ i ] = layer doesn’t seem to be allowed.

You could ask for the layers, change it and then assign it back. But that might behave unexpectedly.

To understand how it works internally, habe a look at the implementation in the python wrapper in the GlyphsSDK repo.

1 Like

Hi Georg,
I’m facing the same issue with another script, and can’t seem to find the answer in GlyphsSDK.
May I ask what’s the python analogue to changing masters (on the toolbar) for the selected layers in a tab? It is apparently different from setting tab.layers

try:

Font.masterIndex = 1

Sure, but it doesn’t apply it to selected layers. If the tab contains layers different from current master (those changed from layers panel), Font.masterIndex doesn’t apply to them.

To show an example, below, some layers in the middle are different from current master, and I want to ‘reset’ only some of them:

Turn this:


Into this:

tab.layers turns them all into ‘non-current-master layers’, and tab.text resets all layers to current master. I can’t seem to figure out how the app mixes both when you click the layers/master buttons with some selection :slight_smile:

UPD
Ohhh I figured, Font.masterIndex does apply to actually selected layers (I was trying using a range of indices). That works for me, thanks!

That function works exactly like clicking the master icons. That means it switches the default master and all active/selected layers. All layers that have set their own master (like when selecting a different master in the layer panel or using tab.layers) will keep their masters.

1 Like