2021-06-07 13:56:08 +02:00
|
|
|
# Will be called when the styles of the base theme are already added
|
|
|
|
# to add new styles
|
|
|
|
|
|
|
|
|
|
|
|
class NewTheme(lv.theme_t):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
# Initialize the styles
|
2023-09-14 20:12:31 +02:00
|
|
|
self.style_button = lv.style_t()
|
|
|
|
self.style_button.init()
|
|
|
|
self.style_button.set_bg_color(lv.palette_main(lv.PALETTE.GREEN))
|
|
|
|
self.style_button.set_border_color(lv.palette_darken(lv.PALETTE.GREEN, 3))
|
|
|
|
self.style_button.set_border_width(3)
|
2021-06-07 13:56:08 +02:00
|
|
|
|
2022-03-21 18:25:51 +08:00
|
|
|
# This theme is based on active theme
|
2023-10-12 20:37:27 +02:00
|
|
|
th_act = lv.theme_get_from_obj(lv.screen_active())
|
2021-06-07 13:56:08 +02:00
|
|
|
# This theme will be applied only after base theme is applied
|
2022-03-21 18:25:51 +08:00
|
|
|
self.set_parent(th_act)
|
2021-12-05 14:41:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ExampleStyle_14:
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
def __init__(self):
|
2022-03-21 18:25:51 +08:00
|
|
|
#
|
2021-06-07 13:56:08 +02:00
|
|
|
# Extending the current theme
|
|
|
|
#
|
|
|
|
|
2023-10-12 20:37:27 +02:00
|
|
|
button = lv.button(lv.screen_active())
|
2023-09-14 20:12:31 +02:00
|
|
|
button.align(lv.ALIGN.TOP_MID, 0, 20)
|
2021-06-07 13:56:08 +02:00
|
|
|
|
2023-09-14 20:12:31 +02:00
|
|
|
label = lv.label(button)
|
2021-06-07 13:56:08 +02:00
|
|
|
label.set_text("Original theme")
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
self.new_theme_init_and_set()
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2023-10-12 20:37:27 +02:00
|
|
|
button = lv.button(lv.screen_active())
|
2023-09-14 20:12:31 +02:00
|
|
|
button.align(lv.ALIGN.BOTTOM_MID, 0, -20)
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2023-09-14 20:12:31 +02:00
|
|
|
label = lv.label(button)
|
2021-06-07 13:56:08 +02:00
|
|
|
label.set_text("New theme")
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-12-05 14:41:17 +01:00
|
|
|
def new_theme_apply_cb(self, th, obj):
|
2021-06-07 13:56:08 +02:00
|
|
|
print(th,obj)
|
2023-09-14 20:12:31 +02:00
|
|
|
if obj.get_class() == lv.button_class:
|
|
|
|
obj.add_style(self.th_new.style_button, 0)
|
2022-03-21 18:25:51 +08:00
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
def new_theme_init_and_set(self):
|
|
|
|
print("new_theme_init_and_set")
|
2022-03-21 18:25:51 +08:00
|
|
|
# Initialize the new theme from the current theme
|
2021-06-07 13:56:08 +02:00
|
|
|
self.th_new = NewTheme()
|
|
|
|
self.th_new.set_apply_cb(self.new_theme_apply_cb)
|
2023-09-18 22:57:30 +02:00
|
|
|
lv.display_get_default().set_theme(self.th_new)
|
2021-12-05 14:41:17 +01:00
|
|
|
|
|
|
|
|
2021-06-07 13:56:08 +02:00
|
|
|
exampleStyle_14 = ExampleStyle_14()
|