Problems with File Format Plugin (custom export)

Hi all,

I’m having a couple of difficulties writing an export plugin (file format plugin) for Glyphs 3. First, unlike in Glyphs 2, the dialog is not resizeable and, by default, does not take the size of the panel as defined in IBDialog.nib. If I select “OTF” and then reselect the custom file format, it is taller as it gets resized to the OTF dimensions, but it is still not tall enough. How can I make the call to resize the dialog to the custom file format’s dimensions on display?

grafik

Secondly, when performing the export, there is no feedback or progress bar; Glyphs just freezes until the export is done (which may take a long time). When performing a normal OTF export, Glyphs displays a notification panel for each instance, which then disappears when the export is completed. How can I do something similar for the custom file format? The Message() function always has an OK button and won’t disappear until it’s OKd. I need to be able to show the panel during processing and then hide it again programmatically.

grafik

Thanks in advance for your help

The layout of the export dialog is determined by auto layout now. And you might need to check this property of the view: Apple Developer Documentation

Thanks, Georg, for the link to the NSView property. I will try it out. Is there any documentation on how the auto layout works? Or can we still use the Interface Builder to explicitly position the elements?

Setting this property to True upon initialization gives me the following result. So it seems that no constraints have been set (despite the view having controls). How can I do this using the Python bridge?

grafik

By the way, the Glyphs sample File Format Plugin also needs to be updated to Glyphs 3, as the following happens:

grafik

Could you also provide a pointer to my second issue, how I can display a progress pane or similar indicator like the one Glyphs normally shows? Or at least return control to Glyphs so that the Macro window can be updated; currently Glyphs freezes until the whole export is done. Thanks!

So you either set the translatesAutoresizingMaskIntoConstraints in interface builder and set the autoresizing:

Bildschirmfoto 2021-12-12 um 00.16.22

Or you set it to automatic and add layout constraints:


(those blue lines)
The later is a bit tricky to get right but is much more flexible.
as a intro this might help: Introduction to Auto Layout in iOS: Interface Builder and Auto Layout - raywenderlich.com - YouTube (it is meant for iOS, but the basics are the same)

Or the docs from apple: Auto Layout Guide: Understanding Auto Layout

Thanks, Georg. It’s fiddly but I have now more or less got it working.

By the way, for anyone else reading this topic, I have solved the progress bar issue with the following Vanilla methods:

https://vanilla.robotools.dev/en/latest/objects/ProgressSpinner.html?highlight=progress
https://vanilla.robotools.dev/en/latest/objects/ProgressBar.html?highlight=progress

The progress dialog from Glyphs can be used like this:

GSProgressWindowController = objc.lookUpClass("GSProgressWindowController")
progressWindow = GSProgressWindowController.new()
progressWindow.setTitle_("doing something long")
progressWindow.showProgress()

# Do the long thing
progressWindow.setMessage_("some detail")
# Do more

progressWindow.hideProgress()

(I didn’t try that from a script, but it should work)

1 Like

Hi Georg, hi all,

I’m having a couple of further problems getting this export script working, which is based on the sample script in the Glyphs SDK.

The sample script stores the values of the checkboxes and other controls in e.g. Glyphs.defaults[unicodePref], which are then used by the export method.
However, my script has some calculated and other user-selectable controls that aren’t stored as a preference, but as a runtime variable, in particular the destination directory, self.exportDestination.

When the export routine is run, these variables are gone and are replaced by their defaults. It looks like, when the user clicks “Next”, a new instance of the plugin is created, start() is run all over again followed by export(). Is this correct?

Is there any way to store the selections made in the controls on the form (other than using Glyphs.defaults[XXpref]) so that they can be used by the export() method? In particular, I need to be able to pass the destination directory to the export method as a string, and attepting to store a string in Glyphs.defaults[XXpref] causes Glyphs to crash.

@GeorgSeifert If you need my code, I sent you the plugin on December 15 by email to gs@…

Thanks in advance!

You can transfer settings by returning a dictionary from a method called exportOptions.

So you need to implement those two methods:

def exportOptions(self):
    return {"some key" : "some value"}
def setExportOptions_(self, exportOptions):
    self.someValue = exportOptions["some key"]

(I wrote that in the browser, so I hope I didn’t mess it up).

Thanks @GeorgSeifert for your reply. However, I am not sure how to pass this dictionary to the export method as Glyphs only calls it with the parameters selfand font. If I try calling self.exportOptions() from the export method it is referencing the new object, and the settings previously chosen in the dialog are missing. Or do I need to store this dictionary somewhere?

You don’t need to call it. You need to implement those two methods in your plugin.
The two methods will be called from Glyphs.

1 Like

Thanks @GeorgSeifert, it’s working now!

For anyone else following this thread, this should make things clearer:

def exportOptions(self):
    return {"some key" : self.someValue}
def setExportOptions_(self, exportOptions):
    self.someValue = exportOptions["some key"]

You can even reference checkboxes and other controls in exportOptions directly.

And to explain why this is needed: This ensures that each export is done by a unique plugin instance. This is needed when exporting more than one font at a time.