This commit is contained in:
shenjack 2023-09-02 01:59:56 +08:00
parent 132c6f09ba
commit 46ecf1f19d
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -45,6 +45,9 @@ class BaseTheme:
self.secondary_color = secondary_color
self.main_font = main_font
def __repr__(self) -> str:
return f'<{self.__class__.__name__} main_color={self.main_color} secondary_color={self.secondary_color} main_font={self.main_font}>'
class FontTheme(BaseTheme):
"""
@ -65,6 +68,12 @@ class FontTheme(BaseTheme):
self.font_italic = font_italic
self.font_stretch = font_stretch
def __repr__(self) -> str:
return (f'<{self.__class__.__name__} main_color={self.main_color} '
f'secondary_color={self.secondary_color} main_font={self.main_font} '
f'font_size={self.font_size} font_bold={self.font_bold} '
f'font_italic={self.font_italic} font_stretch={self.font_stretch}>')
class ButtonTheme(BaseTheme):
"""
@ -81,6 +90,11 @@ class ButtonTheme(BaseTheme):
self.font_theme = font_theme or FontTheme()
self.hit_color = hit_color
def __repr__(self) -> str:
return (f'<{self.__class__.__name__} main_color={self.main_color} '
f'secondary_color={self.secondary_color} main_font={self.main_font} '
f'font_theme={self.font_theme} hit_color={self.hit_color}>')
class PressTextButton(widgets.WidgetBase):
"""
@ -101,17 +115,14 @@ class PressTextButton(widgets.WidgetBase):
super().__init__(x, y, width, height)
self.back_ground_batch = batch or Batch()
self.front_batch = batch or Batch()
if group:
self.front_group = Group(order=10, parent=group)
self.back_ground_group = Group(order=5, parent=group)
else:
self.front_group = Group(order=5)
self.back_ground_group = Group(order=10)
self.front_group = Group(order=10, parent=group)
self.back_ground_group = Group(order=5, parent=group)
self.pressed = False
self.theme = theme or ButtonTheme()
self.font_theme = font_theme or FontTheme()
print(self.theme)
self.untouched_color = self.theme.main_color
self.touched_color = self.theme.secondary_color
self.hit_color = self.theme.hit_color
@ -153,6 +164,7 @@ class PressTextButton(widgets.WidgetBase):
def on_mouse_motion(self, x, y, dx, dy):
if (x, y) in self.back_rec:
self.back_rec.color = self.touched_color
print(self.back_rec.color)
else:
self.pressed = False
self.back_rec.color = self.untouched_color