class ColorButton(Button):
- def __init__(self, parent, rect, color, callback, is_active=False):
- super().__init__(parent, rect, None, callback, is_active)
+ def __init__(self, parent, rect, color, callback, highlight=False):
+ super().__init__(parent, rect, None, callback, highlight)
self.color = color
def draw(self):
@property
def stop_event(self):
return self.root.stop_event
-
- def update(self):
- pass
-
- def draw(self):
- pass
method_name = f"handle_{pygame.event.event_name(ev.type).lower()}"
if hasattr(self, method_name):
getattr(self, method_name)(ev)
+
+ def update(self):
+ pass
+
+ def draw(self):
+ pass
class Modal(Focusable, Parent, Child):
- def __init__(self, parent):
- super().__init__(parent, False)
- self.draw = self._check_enabled(self.draw)
- self.update = self._check_enabled(self.update)
- self.handle_event = self._check_enabled(self.handle_event)
- self.activate = self._check_enabled(self.activate, False)
+ def __init__(self, parent, enabled=False):
+ super().__init__(parent, enabled)
+ self.activate = self.activate
self.deactivate = self._check_enabled(self.deactivate)
def _check_enabled(self, method, cmp=True):
return inner
def activate(self):
+ if self.enabled:
+ return
super().activate()
self.enabled = True
self.root.stop_event = True
self.dirty = True
def deactivate(self):
+ if not self.enabled:
+ return
super().deactivate()
self.enabled = False
self.root.stop_event = True
class Parent(EventMethodDispatcher):
- root: "root.Root"
running: bool
stop_event: bool
break
def update(self):
- s = super()
- if hasattr(s, "update"):
- s.update()
+ super().update()
for child in self.children:
if child.enabled:
child.update()
def draw(self):
- s = super()
- if hasattr(s, "draw"):
- s.draw()
+ super().draw()
for child in self.children:
if child.enabled:
child.draw()