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] 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):