The code setup is as follows:
- Module ui_theme.py defines a theme and variant selector.
- variant_selector has an on_change event handler.
- Module cards_page.py imports ui_theme.py and has a handler on_variant_change.
Now, what I want to achieve that when ui_theme.on_change event is invoked then it should somehow call the cards_page.on_variant_change event.
Constraint: I definitely do not want to create a function to generate variant_selector. That makes the code-org bit messy. I also, can not post initialization, set the event handler.
My current solution is as follows:
- ui_theme.py
on_change_variant_callback = None
def on_change_variant_click(dbref, msg, to_ms):
print ("button clicked:", msg.value)
if on_change_variant_callback:
on_change_variant_callback(dbref, msg, to_ms)
pass
- in cards.py
import ui_theme
def on_variant_select():
pass
ui_theme.on_change_variant_callback = on_variant_select
Seems to me that there should be a better way -- probably this where dependency injection can help, although i don't understand that concept well enough.