OK, this is a big one. This branch redesigns the widget plugin system in hubs to use classes instead of Python modules.
In this new world, widgets are Python classes in their own module, which is usually in their own directory (but they don't have to be).
Here are the components involved for a widget:
a widget class
one or more view(s) that will be registered with the app
templates which are now in a subdirectory of the widget itself
cached functions, which are functions whoose results get cached and invalidated when the right message is recieved on the bus (as before). There can be as many cached functions as necessary per widget.
I would recommend reading the integrated documentation, you can build it with the tox -e docs command and read it with xdg-open ./docs/_build/html/api.html. If there's something unclear, please tell me, I'll fix it.
Improvements over the current system :
widgets can reside anywhere that is Python-accessible, which means they don't have to be inside the hubs app itself : widgets can be added from external modules, which makes it easier to have out-of-tree widgets, for people wanting to contribute to hubs or having their own site-specific widgets (there may be other installs of hubs one day).
widgets can have more than one view, and the root view (ex-data function) isn't any different from the others
the files are in their own directory, including templates (but not CSS files or JS, that's for later) which makes it easier to know what belongs to a widget and what belongs to the hubs app
the widget registration isn't static, it can be set in the config file, which means that the admin can disable or enable more widgets without touching the code
there's no implicit decoration of the functions anymore, which made it hard to understand where the data was coming from
the caching is separated from the view context, which enables view to have no caching, or to use multiple cached function to generate their output (with different invalidation policies)
there's way less global variables (like the widget templating environment, that one widget could edit and involuntarily propagate the change to other widgets).
the chrome template decoration system has been replaced with jinja template extention, it's the exact use cas for this feature.
the widget parameters have gained a label key which will make configuration more human-readable
probably other minor things I forgot... ;-)
I recognize that it's a big change, so I'd like to add the following :
try to read commits in order, I've made them topic-specific, so you can understand what's being changed and why. Reading the whole "Files changed" page is actually much harder.
I'm available for any questions you may have
I've converted all existing widgets, and if you don't want to convert the widget you're working on, I pledge to convert it myself (it's actually not that hard once you understand how the pieces fit together)
OK, this is a big one. This branch redesigns the widget plugin system in hubs to use classes instead of Python modules.
In this new world, widgets are Python classes in their own module, which is usually in their own directory (but they don't have to be).
Here are the components involved for a widget:
I would recommend reading the integrated documentation, you can build it with the
tox -e docscommand and read it withxdg-open ./docs/_build/html/api.html. If there's something unclear, please tell me, I'll fix it.Improvements over the current system :
datafunction) isn't any different from the otherschrometemplate decoration system has been replaced with jinja template extention, it's the exact use cas for this feature.labelkey which will make configuration more human-readableI recognize that it's a big change, so I'd like to add the following :