Skip to content

Commit 12f9f18

Browse files
Reorganize layout to use tabbed panels instead of docks (#170)
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
1 parent 274d793 commit 12f9f18

File tree

4 files changed

+151
-174
lines changed

4 files changed

+151
-174
lines changed

openmc_plotter/docks.py

Lines changed: 108 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
QGroupBox, QFormLayout, QLabel, QLineEdit,
88
QComboBox, QSpinBox, QDoubleSpinBox, QSizePolicy,
99
QCheckBox, QDockWidget, QScrollArea, QListWidget,
10-
QListWidgetItem, QTreeWidget, QTreeWidgetItem)
10+
QListWidgetItem, QTreeWidget, QTreeWidgetItem,
11+
QTabWidget, QSplitter)
1112
import matplotlib.pyplot as plt
1213
import numpy as np
1314
import openmc
@@ -18,31 +19,34 @@
1819
_REACTION_UNITS, _SPATIAL_FILTERS)
1920

2021

21-
class PlotterDock(QDockWidget):
22+
class PlotterPanel(QWidget):
2223
"""
23-
Dock widget with common settings for the plotting application
24+
Base panel widget with common settings for the plotting application
2425
"""
2526

26-
def __init__(self, model, font_metric, parent=None):
27+
def __init__(self, model, font_metric, main_window, parent=None):
2728
super().__init__(parent)
2829

2930
self.model = model
3031
self.font_metric = font_metric
31-
self.main_window = parent
32+
self.main_window = main_window
3233

3334
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
3435

3536

36-
class MeshAnnotationDock(PlotterDock):
37-
"""Dock for mesh annotation options"""
37+
class MeshPanel(PlotterPanel):
38+
"""Panel for mesh options"""
3839

39-
def __init__(self, model, font_metric, parent=None):
40-
super().__init__(model, font_metric, parent)
40+
def __init__(self, model, font_metric, main_window, parent=None):
41+
super().__init__(model, font_metric, main_window, parent)
4142

4243
self.treeLayout = QVBoxLayout()
4344
self.meshTree = QTreeWidget()
45+
self.meshTree.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
46+
self.meshTree.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
4447
self.treeExpander = Expander("Meshes:", layout=self.treeLayout)
4548
self.treeExpander.expand() # start with meshes expanded
49+
self.headerLabel = QLabel("Mesh Annotations")
4650

4751
self.meshTree.setColumnCount(1)
4852

@@ -56,55 +60,104 @@ def __init__(self, model, font_metric, parent=None):
5660

5761
self.meshTree.setHeaderHidden(True)
5862

59-
# Create submit button
60-
self.applyButton = QPushButton("Apply Changes")
61-
# Mac bug fix
62-
self.applyButton.setMinimumHeight(self.font_metric.height() * 1.6)
63-
self.applyButton.clicked.connect(self.main_window.applyChanges)
64-
65-
label = QLabel("Mesh Annotations")
66-
self.treeLayout.addWidget(label)
6763
self.treeLayout.addWidget(self.meshTree)
68-
self.treeLayout.addWidget(HorizontalLine())
69-
self.treeLayout.addWidget(self.applyButton)
7064

71-
self.optionsWidget = QWidget()
72-
self.optionsWidget.setLayout(self.treeLayout)
73-
self.setWidget(self.optionsWidget)
65+
self.panelLayout = QVBoxLayout()
66+
self.panelLayout.addWidget(self.headerLabel)
67+
68+
self.treeSplitter = QSplitter(QtCore.Qt.Vertical)
69+
self.treeSplitter.setChildrenCollapsible(False)
70+
self.treeSplitter.addWidget(self.meshTree)
71+
self.treeSplitter.addWidget(QWidget())
72+
self.treeSplitter.setStretchFactor(0, 1)
73+
self.treeSplitter.setStretchFactor(1, 2)
74+
self.panelLayout.addWidget(self.treeSplitter)
75+
self.setLayout(self.panelLayout)
7476

7577
def get_checked_meshes(self):
7678
return [id for id, item in self.mesh_items if item.checkState(0) == QtCore.Qt.Checked]
7779

7880
def update(self):
7981
pass
8082

83+
84+
class TabbedDock(QDockWidget):
85+
"""
86+
Dock widget containing tabbed panels for Geometry, Tallies, and Meshes
87+
"""
88+
89+
def __init__(self, model, font_metric, parent=None):
90+
super().__init__(parent)
91+
92+
self.model = model
93+
self.font_metric = font_metric
94+
self.main_window = parent
95+
96+
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
97+
self.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea)
98+
99+
# Create the tab widget
100+
self.tabWidget = QTabWidget()
101+
102+
# Create the three panels
103+
self.geometryPanel = GeometryPanel(model, font_metric, parent, self)
104+
self.tallyPanel = TallyPanel(model, font_metric, parent, self)
105+
self.meshAnnotationPanel = MeshPanel(model, font_metric, parent, self)
106+
107+
# Wrap panels in scroll areas
108+
geometryScroll = QScrollArea()
109+
geometryScroll.setWidget(self.geometryPanel)
110+
geometryScroll.setWidgetResizable(True)
111+
112+
tallyScroll = QScrollArea()
113+
tallyScroll.setWidget(self.tallyPanel)
114+
tallyScroll.setWidgetResizable(True)
115+
116+
meshScroll = QScrollArea()
117+
meshScroll.setWidget(self.meshAnnotationPanel)
118+
meshScroll.setWidgetResizable(True)
119+
120+
# Add panels as tabs
121+
self.tabWidget.addTab(geometryScroll, "Geometry")
122+
self.tabWidget.addTab(tallyScroll, "Tallies")
123+
self.tabWidget.addTab(meshScroll, "Meshes")
124+
125+
# Create Apply Changes button
126+
self.applyButton = QPushButton("Apply Changes")
127+
self.applyButton.setMinimumHeight(self.font_metric.height() * 1.6)
128+
self.applyButton.setStyleSheet("QPushButton { background-color: #4CAF50; color: white; }")
129+
self.applyButton.clicked.connect(self.main_window.applyChanges)
130+
131+
# Main layout with tabs and apply button
132+
self.mainLayout = QVBoxLayout()
133+
self.mainLayout.addWidget(self.tabWidget)
134+
self.mainLayout.addWidget(HorizontalLine())
135+
self.mainLayout.addWidget(self.applyButton)
136+
137+
# Create container widget
138+
self.containerWidget = QWidget()
139+
self.containerWidget.setLayout(self.mainLayout)
140+
self.setWidget(self.containerWidget)
141+
81142
def resizeEvent(self, event):
82143
self.main_window.resizeEvent(event)
83144

84145
hideEvent = showEvent = moveEvent = resizeEvent
85146

86147

87-
class DomainDock(PlotterDock):
148+
class GeometryPanel(PlotterPanel):
88149
"""
89-
Domain options dock
150+
Geometry options panel
90151
"""
91152

92-
def __init__(self, model, font_metric, parent=None):
93-
super().__init__(model, font_metric, parent)
94-
95-
self.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea)
153+
def __init__(self, model, font_metric, main_window, parent=None):
154+
super().__init__(model, font_metric, main_window, parent)
96155

97156
# Create Controls
98157
self._createOriginBox()
99158
self._createOptionsBox()
100159
self._createResolutionBox()
101160

102-
# Create submit button
103-
self.applyButton = QPushButton("Apply Changes")
104-
# Mac bug fix
105-
self.applyButton.setMinimumHeight(self.font_metric.height() * 1.6)
106-
self.applyButton.clicked.connect(self.main_window.applyChanges)
107-
108161
# Create Zoom box
109162
self.zoomBox = QSpinBox()
110163
self.zoomBox.setSuffix(' %')
@@ -120,22 +173,15 @@ def __init__(self, model, font_metric, parent=None):
120173
self.zoomWidget.setLayout(self.zoomLayout)
121174

122175
# Create Layout
123-
self.dockLayout = QVBoxLayout()
124-
self.dockLayout.addWidget(QLabel("Geometry/Properties"))
125-
self.dockLayout.addWidget(HorizontalLine())
126-
self.dockLayout.addWidget(self.originGroupBox)
127-
self.dockLayout.addWidget(self.optionsGroupBox)
128-
self.dockLayout.addWidget(self.resGroupBox)
129-
self.dockLayout.addWidget(HorizontalLine())
130-
self.dockLayout.addWidget(self.zoomWidget)
131-
self.dockLayout.addWidget(HorizontalLine())
132-
self.dockLayout.addStretch()
133-
self.dockLayout.addWidget(self.applyButton)
134-
self.dockLayout.addWidget(HorizontalLine())
135-
136-
self.optionsWidget = QWidget()
137-
self.optionsWidget.setLayout(self.dockLayout)
138-
self.setWidget(self.optionsWidget)
176+
self.panelLayout = QVBoxLayout()
177+
self.panelLayout.addWidget(self.originGroupBox)
178+
self.panelLayout.addWidget(self.optionsGroupBox)
179+
self.panelLayout.addWidget(self.resGroupBox)
180+
self.panelLayout.addWidget(HorizontalLine())
181+
self.panelLayout.addWidget(self.zoomWidget)
182+
self.panelLayout.addStretch()
183+
184+
self.setLayout(self.panelLayout)
139185

140186
def _createOriginBox(self):
141187

@@ -292,7 +338,7 @@ def _createResolutionBox(self):
292338
self.resGroupBox = QGroupBox("Resolution")
293339
self.resGroupBox.setLayout(self.resLayout)
294340

295-
def updateDock(self):
341+
def update(self):
296342
self.updateOrigin()
297343
self.updateWidth()
298344
self.updateHeight()
@@ -362,20 +408,12 @@ def revertToCurrent(self):
362408
self.widthBox.setValue(cv.width)
363409
self.heightBox.setValue(cv.height)
364410

365-
def resizeEvent(self, event):
366-
self.main_window.resizeEvent(event)
367-
368-
hideEvent = showEvent = moveEvent = resizeEvent
369-
370-
371-
class TallyDock(PlotterDock):
411+
class TallyPanel(PlotterPanel):
372412

373-
def __init__(self, model, font_metric, parent=None):
374-
super().__init__(model, font_metric, parent)
375-
376-
self.setAllowedAreas(QtCore.Qt.RightDockWidgetArea)
413+
def __init__(self, model, font_metric, main_window, parent=None):
414+
super().__init__(model, font_metric, main_window, parent)
377415

378-
# Dock maps for tally information
416+
# Panel maps for tally information
379417
self.tally_map = {}
380418
self.filter_map = {}
381419
self.score_map = {}
@@ -395,11 +433,6 @@ def __init__(self, model, font_metric, parent=None):
395433
self.tallyGroupBox = QGroupBox('Selected Tally')
396434
self.tallyGroupBox.setLayout(self.tallySelectorLayout)
397435

398-
# Create submit button
399-
self.applyButton = QPushButton("Apply Changes")
400-
self.applyButton.setMinimumHeight(self.font_metric.height() * 1.6)
401-
self.applyButton.clicked.connect(self.main_window.applyChanges)
402-
403436
# Color options section
404437
self.tallyColorForm = ColorForm(self.model, self.main_window, 'tally')
405438
self.scoresGroupBox = Expander(title="Scores:")
@@ -408,23 +441,13 @@ def __init__(self, model, font_metric, parent=None):
408441
self.nuclidesListWidget = QListWidget()
409442

410443
# Main layout
411-
self.dockLayout = QVBoxLayout()
412-
self.dockLayout.addWidget(QLabel("Tallies"))
413-
self.dockLayout.addWidget(HorizontalLine())
414-
self.dockLayout.addWidget(self.tallyGroupBox)
415-
self.dockLayout.addStretch()
416-
self.dockLayout.addWidget(HorizontalLine())
417-
self.dockLayout.addWidget(self.tallyColorForm)
418-
self.dockLayout.addWidget(HorizontalLine())
419-
self.dockLayout.addWidget(self.applyButton)
420-
421-
# Create widget for dock and apply main layout
422-
self.scroll = QScrollArea()
423-
self.scroll.setWidgetResizable(True)
424-
self.widget = QWidget()
425-
self.widget.setLayout(self.dockLayout)
426-
self.scroll.setWidget(self.widget)
427-
self.setWidget(self.scroll)
444+
self.panelLayout = QVBoxLayout()
445+
self.panelLayout.addWidget(self.tallyGroupBox)
446+
self.panelLayout.addStretch()
447+
self.panelLayout.addWidget(HorizontalLine())
448+
self.panelLayout.addWidget(self.tallyColorForm)
449+
450+
self.setLayout(self.panelLayout)
428451

429452
def _createFilterTree(self, spatial_filters):
430453
av = self.model.activeView

0 commit comments

Comments
 (0)