I am looking for a way to open a dialog, especially one that asks for user’s text input, and file dialog (trying to open a text file). I thought robofab may be the way to go, but its page or robofab help didn’t get me anywhere. Could anyone teach me how to do it?
For file dialogs, there are the convenience methods GetOpenFile()
and GetSaveFile()
, more details on docu.glyphsapp.com. For a text input window, Vanilla gives you nice wrappers for the PyObjC functions.
Thanks, that will do for the file part. I haven’t found the text input dialog yet (I looked at vanilla help countless times yesterday, but couldn’t find it). Could you give me an example?
Take a peek in my Vanilla scripts, like Make OT Class from Selected Glyphs etc.
I had a look at it, and it’s not doing anything different from making a floating window just as usual, which is what I want to avoid. I am looking for a much simpler code sample like EasyDialogs.AskString or what’s equivalent in robofont, that works.
That is the type of window, not the text input. You have regular windows as well in Vanilla, try help(vanilla.Window)
I had a look, but I can’t find what I want. Sorry for learning slowly, but are you saying that there is no easy way and I have to recreate the dialog window?
EDIT: I recreated it anyway using vanilla.Window, but this way I can’t get the dialog to appear more than once. It gives me an error saying “can’t re-open a window”
EDIT: I could get the dialogs to show and hide. I can manage for now, but I still wish there was an easier way.
There is a AskString
dialog in robofab. You need to import from robofab.interface.all.dialogs import AskString
to be able to use it.
def AskString(message, value='', title='RoboFab'):
Why don’t you make your own convenience method that you can re-use?
That’s okay within one script, but I don’t want to make something that only works in my environment (though I think it’s okay assume everyone has robofont and vanilla, from which I have finally found stuff that work with Georg’s help. Some were implemented and others weren’t, and I had no way of knowing it just by my research).