Script breaking API changes

In Version 811 the function Layer.selection() was changed to a property for whatever reason. So for a script to work in versions after 811 you have to remove the braces. For older versions the braces have to be present. This breaks many existing scripts. mekkablue already changed some (but not all) of his scripts using try/except clauses to fix this issue in a backwards compatible way. In schriftgestalts objectsGS.py e.g. one occurence was changed to the new style while many others still use the function-style, so at the moment it dosen’t work properly in any version.

Would it be possible to reintroduce the selection() function and simply make it return the property? This way oldstyle scripts would still work in newer versions and it would be easier to build scripts that work in any version, even Glyphs1…

I’m afraid that you can’t have both, .selection and .selection().

I think it is important to improve the python API even if it breaks compatibility with some scripts. We try to provide workarounds if possible.

Edit: I improved the objectsGS.py a bit that it should work in new and old versions.

Thanks for fixing objectsGS.py.

Which one did I forget?

Update: I went through the scripts again and found two more uncaught selection() calls. Should be fixed now. I believe I have updated all occasions. Let me know if you still find something.

To anyone who writes scripts and wants to be compatible with pre-2.2, here is a function you can use:

def selectionForLayer(thisLayer):
	selection = ()
	try:
		selection = thisLayer.selection() # v2.1 and earlier
	except:
		selection = thisLayer.selection # v2.2 and later
	return selection

Simply call it with mySelection = selectionForLayer(myLayer) and you’re good.

Yes, now all mekkablue scripts work again. Thank you for looking into it.