Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
hacking the pyui file
-
@omz Is there any way to add "non-standard" keyword:value pairs to the pyui elements such that they can then be accessed in the script as instance variables? Seems I can add them without "breaking" the pyui file, but then they are not accessible.
-
No, that's not possible. The mapping of JSON keys to view attributes is basically hard-coded, and anything else is simply ignored.
-
here is a method to read in a pyui, and create a view without using the built in
load_view
. This will let you use hacked pyui. If you've created a custom view, In theory you should be able to set instance variables, though I have not tried it. You might need to set those variables initially in your constructor. The script will attempt to first instantiate your custom view, which must take no arguments. Then it sets the frame, then walks through attributes, setting those. Finally, it creates subviews and adds them recursively.Although I haven't quite finished, this method would allow you to specify actions that are bound to instance methods... The
bind_action
method needs to be modified to allow specifying actions on buttons likesuperview.superview.myaction
... Or perhaps something like__rootview__.myaction
, which would then be bound to the root custom view.There are still a few quirky things about the pyui json that I haven't bothered implementing, like TableView datasources, etc, since most people set these after the fact. This method could be extended in theory to allow delegates/datasources to be set within the pyui.