Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/text edit #193

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -36,6 +38,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

Expand Down
3 changes: 3 additions & 0 deletions src/compas_viewer/components/color.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion src/compas_viewer/components/sceneform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions src/compas_viewer/components/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions src/compas_viewer/components/textedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(70, 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:
Expand Down
10 changes: 10 additions & 0 deletions src/compas_viewer/scene/sceneobject.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
from typing import Any
from typing import Optional

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -128,6 +130,14 @@ 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))
PingHsunTsai marked this conversation as resolved.
Show resolved Hide resolved

@property
def bounding_box(self):
return self._bounding_box
Expand Down
Loading