pool.start(worker)
def setBg(widget: QWidget, color: str):
- if (";" in color):
+ if (color) and (";" in color):
raise RuntimeException("No colour can contain a `;'")
- if (color):
+ if (color): # given color
bg = ("background-color: " + color + ";")
- elif hasattr(widget, "bgColor"):
- bg = ("background-color: " + widget.bgColor + ";")
- else:
+ elif (color == ""): # "" = no color
bg = ""
+ elif hasattr(widget, "bgColor"): # None = previous color (if any)
+ bg = ("background-color: " + widget.bgColor + ";")
+ else: # None + no previous color: no change
+ bg = None
changed = False
attribs = widget.styleSheet().split(";")
for i, attr in enumerate(attribs):
if (attr.strip().startswith("background-color:")):
- attribs[i] = bg if color else ""
+ if (not hasattr(widget, "bgColor")):
+ widget.bgColor = attribs[i]
+ if (bg != None):
+ attribs[i] = bg
changed = True
- if (not changed) and (color):
+
+ if (not hasattr(widget, "bgColor")):
+ widget.bgColor = ""
+ if (not changed) and (bg):
attribs.append(bg)
widget.setStyleSheet(";".join(attribs) + ";")
overlay.setParent(target)
overlay.move(0, 0)
overlay.bgColor = "rgba(0, 0, 0, 0)"
+ setBg(overlay, None)
self.overlay.append(overlay)
elif (widget.selected):
bg = "rgba(0, 0, 100, 60)"
else:
- bg = ""
+ bg = None
for overlay in widget.overlay:
setBg(overlay, bg)
for target in targets:
addOverlay(self, target)
- if (hasattr(self, "resizeEvent")):
- self._resizeEvent = self.resizeEvent
-
def resize(event):
- if (hasattr(self, "_resizeEvent")):
- self._resizeEvent(event)
- else:
- self.super().resizeEvent(event)
+ resize.super(self, event)
for widget in self.overlay:
widget.setFixedSize(widget.parent().size())
+ resize.super = self.__class__.resizeEvent
self.resizeEvent = resize
- if (hasattr(self, "enterEvent")):
- self._enterEvent = self.enterEvent
- if (hasattr(self, "leaveEvent")):
- self._leaveEvent = self.leaveEvent
- if (hasattr(self, "mousePressEvent")):
- self._mousePressEvent = self.mousePressEvent
- if (hasattr(self, "mouseReleaseEvent")):
- self._mouseReleaseEvent = self.mouseReleaseEvent
-
def enter(event):
self.hovered = True
fixColor(self)
- if (hasattr(self, "_enterEvent")):
- self._enterEvent(event)
- else:
- self.super().enterEvent(event)
+ enter.super(self, event)
+ enter.super = self.__class__.enterEvent
self.enterEvent = enter
def leave(event):
self.hovered = False
fixColor(self)
- if (hasattr(self, "_leaveEvent")):
- self._leaveEvent(event)
- else:
- self.super().leaveEvent(event)
+ leave.super(self, event)
+ leave.super = self.__class__.leaveEvent
self.leaveEvent = leave
def mousePress(event):
if event.button() == Qt.LeftButton:
self.clicked = True
fixColor(self)
- if (hasattr(self, "_mousePressEvent")):
- self._mousePressEvent(event)
- else:
- self.super().mousePressEvent(event)
+ mousePress.super(self, event)
+ mousePress.super = self.__class__.mousePressEvent
self.mousePressEvent = mousePress
def mouseRelease(event):
if event.button() == Qt.LeftButton:
self.clicked = False
fixColor(self)
- if (hasattr(self, "_mouseReleaseEvent")):
- self._mouseReleaseEvent(event)
- else:
- self.super().mouseReleaseEvent(event)
+ mouseRelease.super(self, event)
+ mouseRelease.super = self.__class__.mouseReleaseEvent
self.mouseReleaseEvent = mouseRelease
-if __name__ == "__main__":
- print("ok")