1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-01-01 19:41:18 +01:00

fix(progress-ring-bar): fix parent inheritance and cleanup of ring objects; closes #496

This commit is contained in:
2025-04-15 14:30:17 +02:00
committed by wakonig_k
parent 1fe052e9da
commit b460ea9955
2 changed files with 13 additions and 11 deletions

View File

@@ -96,7 +96,6 @@ class Ring(BECConnector, QObject):
def __init__(
self,
parent=None,
parent_progress_widget=None,
config: RingConfig | dict | None = None,
client=None,
gui_id: Optional[str] = None,
@@ -111,7 +110,8 @@ class Ring(BECConnector, QObject):
self.config = config
super().__init__(parent=parent, client=client, config=config, gui_id=gui_id, **kwargs)
self.parent_progress_widget = parent_progress_widget
self.parent_progress_widget = parent
self.color = None
self.background_color = None
self.start_position = None

View File

@@ -123,7 +123,7 @@ class RingProgressBar(BECWidget, QWidget):
# For updating bar behaviour
self._auto_updates = True
self._rings = None
self._rings = []
if num_bars is not None:
self.config.num_bars = max(
@@ -134,11 +134,12 @@ class RingProgressBar(BECWidget, QWidget):
self.enable_auto_updates(self.config.auto_updates)
@property
def rings(self):
def rings(self) -> list[Ring]:
"""Returns a list of all rings in the progress bar."""
return self._rings
@rings.setter
def rings(self, value):
def rings(self, value: list[Ring]):
self._rings = value
def update_config(self, config: RingProgressBarConfig | dict):
@@ -169,9 +170,7 @@ class RingProgressBar(BECWidget, QWidget):
)
for i in range(self.config.num_bars)
]
self._rings = [
Ring(parent_progress_widget=self, config=config) for config in self.config.rings
]
self._rings = [Ring(parent=self, config=config) for config in self.config.rings]
if self.config.color_map:
self.set_colors_from_map(self.config.color_map)
@@ -199,7 +198,7 @@ class RingProgressBar(BECWidget, QWidget):
directions=-1,
**kwargs,
)
ring = Ring(parent_progress_widget=self, config=ring_config)
ring = Ring(parent=self, config=ring_config)
self.config.num_bars += 1
self._rings.append(ring)
self.config.rings.append(ring.config)
@@ -225,7 +224,10 @@ class RingProgressBar(BECWidget, QWidget):
self._reindex_rings()
if self.config.color_map:
self.set_colors_from_map(self.config.color_map)
del ring
# Remove ring from rpc, afterwards call close event.
ring.rpc_register.remove_rpc(ring)
ring.deleteLater()
# del ring
self.update()
def _reindex_rings(self):
@@ -292,7 +294,7 @@ class RingProgressBar(BECWidget, QWidget):
widget_class="Ring", index=i, start_positions=90 * 16, directions=-1
)
self.config.rings.append(new_ring_config)
new_ring = Ring(parent_progress_widget=self, config=new_ring_config)
new_ring = Ring(parent=self, config=new_ring_config)
self._rings.append(new_ring)
elif num_bars < current_num_bars: