Created
October 22, 2020 20:41
-
-
Save tshirtman/c67e8504d22fdf4cc746d72408bfd03a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Theme object example | |
''' | |
from kivy.app import App | |
from kivy.lang import Builder | |
from kivy import properties as P | |
from kivy.lang.parser import global_idmap | |
from kivy.event import EventDispatcher | |
KV = ''' | |
<AppLabel@Label>: | |
font_size: theme.font_size_1 | |
color: theme.color_primary | |
<AppTitle@Label>: | |
font_size: theme.font_size_2 | |
color: theme.color_secondary | |
<AppButton@Button>: | |
font_size: theme.font_size_1 | |
BoxLayout: | |
orientation: 'vertical' | |
canvas.before: | |
Color: | |
rgba: theme.background_color | |
Rectangle: | |
pos: self.pos | |
size: self.size | |
AppTitle: | |
text: 'App title' | |
AppLabel: | |
text: 'app label' | |
AppButton: | |
text: 'app button' | |
''' | |
class Theme(EventDispatcher): | |
font_size_1 = P.NumericProperty(26) | |
font_size_2 = P.NumericProperty(32) | |
background_color = P.ColorProperty("#BBBBBB") | |
color_primary = P.ColorProperty("#223344") | |
color_secondary = P.ColorProperty("#334455") | |
global_idmap['theme'] = theme = Theme() | |
class Application(App): | |
def build(self): | |
return Builder.load_string(KV) | |
if __name__ == "__main__": | |
Application().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment