Add a markup language for describing Toga app layouts
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 827
- Avg merge
- 9h 45m
- Merged PRs (30d)
- 58
Description
### What is the problem or limitation you are having?
Toga apps are currently defined by constructing a layout in Python code. This works well, but there is a group of users who have requested the ability to define their GUI layout with a markup language, rather than code.
Although this risks becoming Yet Another Yet Another Markup Language, there would be some potential benefits - most notably, allowing for separation between GUI definition and business logic, which could be useful if/when a GUI app designer is in use.
### Describe the solution you'd like
It should be possible to define app layout in terms of a non-Python markup language.
The exact format for the markup language will need to be the subject of the design process - XML, JSON, YAML, or even a DSL in Python. It might even be worth defining the markup language in abstract terms so that *any* markup language could be mapped to the internal format with the appropriate parser.
Whatever the final markup format, it should be possible to:
* Define a structure of nodes, children and leaf nodes in a widget tree
* Assign IDs to the nodes on the tree
* Associate styles with each node of the tree
* Associate handlers that are defined in the Python code (either as bare functions, or as properties/methods on the app) with nodes on the tree.
The final API would end up being something like:
```
class MyApp(toga.App):
def startup(self):
self.build_layout("path/to/file.toga")
```
or, avoiding the need for a startup method at all:
```
class MyApp(toga.App):
...
app = MyApp(layout="path/to/file.toga")
```
### Describe alternatives you've considered
* Don't do this at all. We don't need YA-YAML.
* Don't define *another* markup language - write parsers for existing markup languages (like QML, KML, or GLADE). It's unclear the extent to which this will be possible, given the way those languages are tightly bound to their underlying GUI frameworks.
### Additional context
The good news is that Toga is especially well suited to a markup-based construction approach. The `content` of a widget is a widget that has children that have children; that's essentially identical to what HTML defines.
It's also possible to build this completely external to Toga's core. Although `build_layout()` has been defined as a member method on `toga.App` in the example above, it could be just as easily defined as a standalone method that takes `app` as an argument.
Contributor guide
Research direction
Start by reviewing Toga's current Python widget-tree construction and the proposed startup/build_layout entry points. Define the markup format and its mapping for nodes, IDs, styles, and Python handlers; done means layouts can be defined and loaded through a documented API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop, frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100