hacking the pyui file
polymerchm last edited by
@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.
omz last edited by
No, that's not possible. The mapping of JSON keys to view attributes is basically hard-coded, and anything else is simply ignored.
JonB last edited by
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_actionmethod needs to be modified to allow specifying actions on buttons like
superview.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.