lv_example_style_14.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Will be called when the styles of the base theme are already added
  2. # to add new styles
  3. class NewTheme(lv.theme_t):
  4. def __init__(self):
  5. super().__init__()
  6. # Initialize the styles
  7. self.style_btn = lv.style_t()
  8. self.style_btn.init()
  9. self.style_btn.set_bg_color(lv.palette_main(lv.PALETTE.GREEN))
  10. self.style_btn.set_border_color(lv.palette_darken(lv.PALETTE.GREEN, 3))
  11. self.style_btn.set_border_width(3)
  12. # This theme is based on active theme
  13. th_act = lv.theme_get_from_obj(lv.scr_act())
  14. # This theme will be applied only after base theme is applied
  15. self.set_parent(th_act)
  16. class ExampleStyle_14:
  17. def __init__(self):
  18. #
  19. # Extending the current theme
  20. #
  21. btn = lv.btn(lv.scr_act())
  22. btn.align(lv.ALIGN.TOP_MID, 0, 20)
  23. label = lv.label(btn)
  24. label.set_text("Original theme")
  25. self.new_theme_init_and_set()
  26. btn = lv.btn(lv.scr_act())
  27. btn.align(lv.ALIGN.BOTTOM_MID, 0, -20)
  28. label = lv.label(btn)
  29. label.set_text("New theme")
  30. def new_theme_apply_cb(self, th, obj):
  31. print(th,obj)
  32. if obj.get_class() == lv.btn_class:
  33. obj.add_style(self.th_new.style_btn, 0)
  34. def new_theme_init_and_set(self):
  35. print("new_theme_init_and_set")
  36. # Initialize the new theme from the current theme
  37. self.th_new = NewTheme()
  38. self.th_new.set_apply_cb(self.new_theme_apply_cb)
  39. lv.disp_get_default().set_theme(self.th_new)
  40. exampleStyle_14 = ExampleStyle_14()