Skip to content

Commit

Permalink
tab feature
Browse files Browse the repository at this point in the history
  • Loading branch information
PingHsunTsai committed Jul 25, 2024
1 parent b942be5 commit 72219ee
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/compas_viewer/components/objectsetting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PySide6.QtWidgets import QDialog
from PySide6.QtWidgets import QPushButton
from PySide6.QtWidgets import QScrollArea
from PySide6.QtWidgets import QTabWidget
from PySide6.QtWidgets import QVBoxLayout
from PySide6.QtWidgets import QWidget

Expand Down Expand Up @@ -60,15 +61,37 @@ def __init__(self, viewer: "Viewer", items: list[dict]):
# Main layout
self.main_layout = QVBoxLayout(self)

# Scroll area setup
self.scroll_area = QScrollArea(self)
self.scroll_area.setWidgetResizable(True)
self.scroll_content = QWidget()
self.scroll_layout = QVBoxLayout(self.scroll_content)
self.scroll_layout.setAlignment(Qt.AlignTop)
self.scroll_area.setWidget(self.scroll_content)

self.main_layout.addWidget(self.scroll_area)
# Tab widget setup
self.tab_widget = QTabWidget(self)

# Tab 1 setup
self.tab1_content = QWidget()
self.tab1_scroll_area = QScrollArea(self.tab1_content)
self.tab1_scroll_area.setWidgetResizable(True)
self.tab1_scroll_content = QWidget()
self.tab1_scroll_layout = QVBoxLayout(self.tab1_scroll_content)
self.tab1_scroll_layout.setAlignment(Qt.AlignTop)
self.tab1_scroll_area.setWidget(self.tab1_scroll_content)

tab1_layout = QVBoxLayout(self.tab1_content)
tab1_layout.addWidget(self.tab1_scroll_area)
self.tab_widget.addTab(self.tab1_content, "Tab 1")

# Tab 2 setup
self.tab2_content = QWidget()
self.tab2_scroll_area = QScrollArea(self.tab2_content)
self.tab2_scroll_area.setWidgetResizable(True)
self.tab2_scroll_content = QWidget()
self.tab2_scroll_layout = QVBoxLayout(self.tab2_scroll_content)
self.tab2_scroll_layout.setAlignment(Qt.AlignTop)
self.tab2_scroll_area.setWidget(self.tab2_scroll_content)

tab2_layout = QVBoxLayout(self.tab2_content)
tab2_layout.addWidget(self.tab2_scroll_area)
self.tab_widget.addTab(self.tab2_content, "Tab 2")

# Add tab widget to main layout
self.main_layout.addWidget(self.tab_widget)

def clear_layout(self, layout):
"""Clear all widgets from the layout."""
Expand All @@ -84,18 +107,18 @@ def clear_layout(self, layout):

def update(self):
"""Update the layout with the latest object settings."""
self.clear_layout(self.scroll_layout)
self.clear_layout(self.tab1_scroll_layout)
self.setting_layout.generate_layout()

if len(self.setting_layout.widgets) != 0:
self.scroll_layout.addLayout(self.setting_layout.layout)
self.tab1_scroll_layout.addLayout(self.setting_layout.layout)
for _, widget in self.setting_layout.widgets.items():
if isinstance(widget, DoubleEdit):
widget.spinbox.valueChanged.connect(self.obj_update)
elif isinstance(widget, TextEdit):
widget.text_edit.textChanged.connect(self.obj_update)
else:
self.scroll_layout.addWidget(LabelWidget(text="No object Selected", alignment="center"))
self.tab1_scroll_layout.addWidget(LabelWidget(text="No object Selected", alignment="center"))

def obj_update(self):
"""Apply the settings from spin boxes to the selected objects."""
Expand Down

0 comments on commit 72219ee

Please sign in to comment.