From 7bcba58ea6762bcca6c1f9cabafae4c06fa4a6fe Mon Sep 17 00:00:00 2001 From: PingHsunTsai <47770211+PingHsunTsai@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:10:51 +0200 Subject: [PATCH 1/6] hash check --- src/compas_viewer/components/sceneform.py | 3 ++- src/compas_viewer/scene/sceneobject.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/compas_viewer/components/sceneform.py b/src/compas_viewer/components/sceneform.py index a0f9d1322..f151b5bbc 100644 --- a/src/compas_viewer/components/sceneform.py +++ b/src/compas_viewer/components/sceneform.py @@ -67,7 +67,8 @@ def scene(self): return self.viewer.scene def update(self): - if list(self.scene.objects) == self._sceneobjects: + current_scene_objects = {hash(obj) for obj in self.scene.objects} + if current_scene_objects == self._sceneobjects: for node in self.scene.traverse("breadthfirst"): widget = node.attributes.get("widget") if widget: diff --git a/src/compas_viewer/scene/sceneobject.py b/src/compas_viewer/scene/sceneobject.py index b7d1d7f54..01205f593 100644 --- a/src/compas_viewer/scene/sceneobject.py +++ b/src/compas_viewer/scene/sceneobject.py @@ -1,3 +1,4 @@ +import copy from typing import Any from typing import Optional @@ -95,6 +96,7 @@ def __init__( ): # Basic super().__init__(**kwargs) + self.kwargs = kwargs self.show = show self.show_points = show_points if show_points is not None else False self.show_lines = show_lines if show_lines is not None else True @@ -128,6 +130,20 @@ def __init__( self._inited = False + def __eq__(self, other) -> bool: + if not isinstance(other, ViewerSceneObject): + return False + return self.compair_kwargs == other.compair_kwargs + + def __hash__(self): + return hash(tuple(self.compair_kwargs)) + + @property + def compair_kwargs(self): + kwarg = copy.deepcopy(self.kwargs) + del kwarg["item"] + return kwarg + @property def bounding_box(self): return self._bounding_box From 64642c1b44330e3e872a13cdde6e16a1864478ec Mon Sep 17 00:00:00 2001 From: PingHsunTsai <47770211+PingHsunTsai@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:14:30 +0200 Subject: [PATCH 2/6] change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c6c77437..6dc4a2712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Updated callback to `SceneTree`. * Updated `ObjectSetting` and `CameraSetting` to support setting from config. * Updated `Slider` to be able change value with `TextEdit` +* Updated `ViewerSceneObject` with hash ability to check if `kwarg` is equal ### Removed From 81e231c24e10858205a41c26baed346023e7c4d7 Mon Sep 17 00:00:00 2001 From: PingHsunTsai <47770211+PingHsunTsai@users.noreply.github.com> Date: Thu, 25 Jul 2024 02:07:12 +0200 Subject: [PATCH 3/6] textedit alignright --- CHANGELOG.md | 2 ++ src/compas_viewer/components/slider.py | 10 +++++----- src/compas_viewer/components/textedit.py | 13 +++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dc4a2712..bb45f2606 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +* Updated alignright feature to `TextEdit` + ### Removed diff --git a/src/compas_viewer/components/slider.py b/src/compas_viewer/components/slider.py index 1b085f910..cd6670fe5 100644 --- a/src/compas_viewer/components/slider.py +++ b/src/compas_viewer/components/slider.py @@ -99,11 +99,11 @@ def __init__( self._min_label = QLabel(str(self.min_val), alignment=Qt.AlignLeft) self._max_label = QLabel(str(self.max_val), alignment=Qt.AlignRight) self.value_label = QLabel(f"{self.title}:") - self.text_edit = TextEdit(str(self.starting_val)) - self.text_edit.text_edit.textChanged.connect(self.text_update) + self.text_widget = TextEdit(str(self.starting_val)) + self.text_widget.text_edit.textChanged.connect(self.text_update) self._text_layout.addWidget(self.value_label) - self._text_layout.addWidget(self.text_edit.text_edit) + self._text_layout.addWidget(self.text_widget.text_edit) # Add widgets to layout self._domain_layout.addWidget(self._min_label) @@ -135,7 +135,7 @@ def on_value_changed(self, value): return self._updating = True scaled_value = round(value * self.step, 2) - self.text_edit.text_edit.setText(str(scaled_value)) + self.text_widget.text = str(scaled_value) if self.action: self.action(self, scaled_value) self._updating = False @@ -145,7 +145,7 @@ def text_update(self): return self._updating = True try: - value = float(self.text_edit.text_edit.toPlainText()) / self.step + value = float(self.text_widget.text) / self.step self.slider.setValue(value) if self.action: self.action(self, value * self.step) diff --git a/src/compas_viewer/components/textedit.py b/src/compas_viewer/components/textedit.py index bf34df817..63c6ca8b6 100644 --- a/src/compas_viewer/components/textedit.py +++ b/src/compas_viewer/components/textedit.py @@ -20,15 +20,24 @@ def __init__( self.text_edit = QTextEdit() self.text_edit.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - self.text_edit.setMaximumSize(85, 25) + self.text_edit.setMaximumSize(50, 25) self.text_edit.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) - self.text_edit.setText(text) + self.text = text self.layout = self.default_layout self.layout.setAlignment(Qt.AlignCenter) self.layout.addWidget(self.text_edit) self.setLayout(self.layout) + @property + def text(self) -> str: + return self.text_edit.toPlainText() + + @text.setter + def text(self, text: str) -> None: + self.text_edit.setText(text) + self.text_edit.setAlignment(Qt.AlignRight) + @property def default_layout(self): if self._default_layout is None: From 7f4809935b341148b23c11e588ba398eb4e49b90 Mon Sep 17 00:00:00 2001 From: PingHsunTsai <47770211+PingHsunTsai@users.noreply.github.com> Date: Thu, 25 Jul 2024 02:15:43 +0200 Subject: [PATCH 4/6] align color buttom and textedit widget --- src/compas_viewer/components/color.py | 3 +++ src/compas_viewer/components/textedit.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compas_viewer/components/color.py b/src/compas_viewer/components/color.py index ee113a5bb..44c10b95a 100644 --- a/src/compas_viewer/components/color.py +++ b/src/compas_viewer/components/color.py @@ -1,5 +1,6 @@ from typing import TYPE_CHECKING +from PySide6.QtCore import Qt from PySide6.QtGui import QColor from PySide6.QtWidgets import QColorDialog from PySide6.QtWidgets import QPushButton @@ -180,8 +181,10 @@ def __init__( default_color = QColor(*remap_rgb(default_color, to_range_one=False)) self.color_button = QPushButton(self) + self.color_button.setMaximumSize(70, 25) self.layout = QVBoxLayout(self) self.layout.addWidget(self.color_button) + self.layout.setAlignment(Qt.AlignCenter) self.color_button.clicked.connect(self.open_color_dialog) self.set_button_color(default_color) diff --git a/src/compas_viewer/components/textedit.py b/src/compas_viewer/components/textedit.py index 63c6ca8b6..f2571c929 100644 --- a/src/compas_viewer/components/textedit.py +++ b/src/compas_viewer/components/textedit.py @@ -20,7 +20,7 @@ def __init__( self.text_edit = QTextEdit() self.text_edit.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - self.text_edit.setMaximumSize(50, 25) + self.text_edit.setMaximumSize(70, 25) self.text_edit.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.text = text From 338182b07ad80d93d404984abdd33e49771e7dcd Mon Sep 17 00:00:00 2001 From: PingHsunTsai <47770211+PingHsunTsai@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:02:36 +0200 Subject: [PATCH 5/6] use settings instead kwarg --- src/compas_viewer/scene/sceneobject.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/compas_viewer/scene/sceneobject.py b/src/compas_viewer/scene/sceneobject.py index 01205f593..f3f663065 100644 --- a/src/compas_viewer/scene/sceneobject.py +++ b/src/compas_viewer/scene/sceneobject.py @@ -133,16 +133,10 @@ def __init__( def __eq__(self, other) -> bool: if not isinstance(other, ViewerSceneObject): return False - return self.compair_kwargs == other.compair_kwargs + return self.settings == other.settings def __hash__(self): - return hash(tuple(self.compair_kwargs)) - - @property - def compair_kwargs(self): - kwarg = copy.deepcopy(self.kwargs) - del kwarg["item"] - return kwarg + return hash(tuple(self.settings)) @property def bounding_box(self): From 7025d717bd685a094142e9a750577229ebe355f3 Mon Sep 17 00:00:00 2001 From: PingHsunTsai <47770211+PingHsunTsai@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:38:12 +0200 Subject: [PATCH 6/6] hash all items --- CHANGELOG.md | 4 +--- src/compas_viewer/components/sceneform.py | 4 ++-- src/compas_viewer/scene/sceneobject.py | 10 +++------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4beb41c00..54ad765b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed +* Updated `ViewerSceneObject` with hash ability in order to catch the update from `settings`. ### Removed @@ -33,8 +34,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fixed `Tag` inconsistent height issue. * Dynamically adjust camera pan delta based on distacne. -* Updated alignright feature to `TextEdit` - ### Removed @@ -54,7 +53,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Updated callback to `SceneTree`. * Updated `ObjectSetting` and `CameraSetting` to support setting from config. * Updated `Slider` to be able change value with `TextEdit` -* Updated `ViewerSceneObject` with hash ability to check if `kwarg` is equal ### Removed diff --git a/src/compas_viewer/components/sceneform.py b/src/compas_viewer/components/sceneform.py index a99316f2a..7abe68a62 100644 --- a/src/compas_viewer/components/sceneform.py +++ b/src/compas_viewer/components/sceneform.py @@ -67,7 +67,7 @@ def scene(self): return self.viewer.scene def update(self): - current_scene_objects = {hash(obj) for obj in self.scene.objects} + current_scene_objects = [hash(obj) for obj in self.scene.objects] if current_scene_objects == self._sceneobjects: for node in self.scene.traverse("breadthfirst"): widget = node.attributes.get("widget") @@ -78,7 +78,7 @@ def update(self): self.scrollToItem(widget) else: - self._sceneobjects = list(self.scene.objects) + self._sceneobjects = [hash(obj) for obj in self.scene.objects] self.clear() self.checkbox_columns = {} diff --git a/src/compas_viewer/scene/sceneobject.py b/src/compas_viewer/scene/sceneobject.py index f3f663065..e56df0da1 100644 --- a/src/compas_viewer/scene/sceneobject.py +++ b/src/compas_viewer/scene/sceneobject.py @@ -1,4 +1,3 @@ -import copy from typing import Any from typing import Optional @@ -130,13 +129,10 @@ def __init__( self._inited = False - def __eq__(self, other) -> bool: - if not isinstance(other, ViewerSceneObject): - return False - return self.settings == other.settings - def __hash__(self): - return hash(tuple(self.settings)) + # Convert self.settings.items() to a hashable type (e.g., frozenset) but convert Color objects to tuples + hashable_settings = frozenset((key, (value.rgb255 if isinstance(value, Color) else value)) for key, value in self.settings.items()) + return hash(hashable_settings) @property def bounding_box(self):