Browse Source

reduced update calls on hovering regions

master
Christian Voigt 1 year ago
parent
commit
e31e656e44
  1. 34
      world_regions_widget/region_label.py
  2. 25
      world_regions_widget/region_label_collection.py

34
world_regions_widget/region_label.py

@ -15,6 +15,7 @@ class RegionLabel(QLabel):
is_selected = bool
parent_collection = object
parent_collection_index = str
image = QImage
@ -27,6 +28,7 @@ class RegionLabel(QLabel):
self.is_selected = False
self.parent_collection = collection
self.parent_collection_index = "{y}-{x}"
self.region_string = "r.{}.{}.7rg".format(
int(x - 16),
@ -39,9 +41,6 @@ class RegionLabel(QLabel):
self.setScaledContents(True)
self.setMouseTracking(True)
def trigger_cursor_change(self):
self.parent_collection.trigger_cursor_change(self)
def clear_image(self):
self.image = None
@ -55,25 +54,22 @@ class RegionLabel(QLabel):
def mark_as_region(self):
self.is_region = True
def remove_graphics_effects(self):
self.setGraphicsEffect(None)
def update_style_effects(self):
style = "*{ border: 1px dotted #aaaaaa; }"
self.setStyleSheet(style)
def remove_style_effects(self):
self.setStyleSheet(None)
def update_graphics_effect(self):
effect = QGraphicsColorizeEffect()
if self.is_marked:
style = "*{ border: 1px dotted #aaaaaa; }"
self.setStyleSheet(style)
else:
self.remove_style_effects()
if self.is_selected:
effect.setColor(QColor(255, 255, 255, 16))
self.setGraphicsEffect(effect)
else:
self.remove_graphics_effects()
effect.setColor(QColor(255, 255, 255, 16))
self.setGraphicsEffect(effect)
def remove_graphics_effects(self):
self.setGraphicsEffect(None)
""" altering class functions """
def mousePressEvent(self, event):
@ -94,16 +90,14 @@ class RegionLabel(QLabel):
def enterEvent(self, event) -> None:
self.is_selected = True
self.update_graphics_effect()
self.parent_collection.set_currently_hovered_label(self)
self.trigger_cursor_change()
self.parent_collection.trigger_cursor_change(self)
super().enterEvent(event)
def leaveEvent(self, event) -> None:
self.is_selected = False
self.update_graphics_effect()
self.trigger_cursor_change()
self.parent_collection.trigger_cursor_change(self)
super().leaveEvent(event)

25
world_regions_widget/region_label_collection.py

@ -1,7 +1,6 @@
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QColor, QPainter
from PyQt5.QtWidgets import (
QGridLayout, QApplication, QGraphicsColorizeEffect
QGridLayout
)
from .region_label import RegionLabel
@ -9,7 +8,8 @@ from .region_label import RegionLabel
class RegionLabelCollection(QGridLayout):
label_collection = dict
currently_hovered_label = object
currently_hovered_label = RegionLabel
def __init__(self, world_regions, size):
super().__init__()
@ -18,29 +18,24 @@ class RegionLabelCollection(QGridLayout):
self.create_label_collection(size)
def set_currently_hovered_label(self, label):
self.world_regions.set_currently_hovered_region(label)
def set_selected(self, region_label=None):
def set_currently_hovered_label(self, region_label):
self.world_regions.set_currently_hovered_region(region_label)
for index, label in self.label_collection.items():
if region_label is not label:
label.is_selected = False
label.update_graphics_effect()
if region_label is not None:
self.toggle_selected(region_label)
label.remove_graphics_effects()
@staticmethod
def toggle_selected(region_label=None):
if region_label is not None:
region_label.is_selected = not region_label.is_selected
region_label.update_graphics_effect()
@staticmethod
def toggle_marked(region_label=None):
if region_label is not None:
region_label.is_marked = not region_label.is_marked
region_label.update_graphics_effect()
if region_label.is_marked:
region_label.update_style_effects()
else:
region_label.remove_style_effects()
def trigger_cursor_change(self, region_label=None):
if region_label is not None:

Loading…
Cancel
Save