mGui icon indicating copy to clipboard operation
mGui copied to clipboard

YAML - like layout language?

Open theodox opened this issue 9 years ago • 10 comments

What do people think about a Yaml-like declarative layout format for saving GUI as data? Is that a step forward or back? mGui.MenuLoader is great for menus, since there's a lot of boilerplate in making menus. Is it worth extending as whole layouts?

theodox avatar Jan 14 '17 05:01 theodox

So a kind of xaml for mGui?

bob-white avatar Jan 14 '17 20:01 bob-white

yeah, that's the basic idea. Or more like QT uic files. I'm not sure how I feel about it though, it's good separation of concerns but the handshake between code and content gets messy. There's an old thread on TAO about this; Rob G is very anti 'gui as data' . I'm not sure how I feel.

theodox avatar Jan 14 '17 21:01 theodox

How would you like to handle event and callback binding? Would that happen inside the python code proper, after the ui is being serialized into python class? (I.e, like what we are doing now with pyside/pyqt)?

dshlai avatar Jan 15 '17 17:01 dshlai

in the menuloader, I use fully qualifies names (see https://github.com/theodox/mGui/blob/master/mGui/menu_loader.py) to bind functions to events. That seems to work pretty well, although I'm sure you'd get some edge cases if there were a lot of dynamic loading going on

theodox avatar Jan 15 '17 18:01 theodox

another possible GUI language reference: https://kivy.org/docs/api-kivy.lang.html

dshlai avatar Jan 15 '17 18:01 dshlai

This looks like a promising YAML alternative

https://code.google.com/archive/p/rson/ https://pypi.python.org/pypi/rsonlite/0.1.0

Rson is a syntax transform of Json, so it's just a formatting thing which I like

theodox avatar Jan 22 '17 02:01 theodox

I like the simple syntax, but we do lose a few features from yaml.

  • Serialize arbitrary objects - json dialects are limited to basic primitives
  • Circular references - might be needed when dealing with formLayouts, and data bindings
  • Comments - more useful in config, but you never know.
  • Clean multi-line text blocks - really handy in the shelf loader.

Of course the downside is it being a large-ish dependency, but its been pretty stable the last few years (one bugfix release?) and is thankfully pure python.

bob-white avatar Jan 22 '17 19:01 bob-white

Looking at menuloader, it seems like we're not really leveraging much of the fanciness of yaml at all. It might be more flexible to rewrite the menuloader and other UI loaders off of pure python dictionaries instead of YamlObject and remove the dependency -- or at least, move it sideways into a separate thin wrapper that loaded any nested-dictionary style object graph.

That would sidestep both syntax wars and dependency management. It would probably also support xml as an alternative format for free.

Thoughts?

theodox avatar Jan 22 '17 23:01 theodox

A definite possibility. I did a quick test of converting the shelf_loader over to use pure dictionaries, loaded from a json file. https://github.com/bob-white/mGui/tree/shelf_no_yaml - didn't think it was worth a whole pull request. If this seems like a more agreeable path, I'll update the existing one to match.

Required fairly minimal changes from the yaml version. The data file is noisier, but a nice thing about acting on pure dictionaries is that anyone could write an adapter to their favorite serialization library without to much headache.

bob-white avatar Jan 23 '17 02:01 bob-white

I think this might be the way to go, and then we can apply the same change to the menu loader and sorta-kinda get the gui layout language for free.

theodox avatar Jan 23 '17 02:01 theodox