Skip to content

Commit 29cdca3

Browse files
committed
Change docks to tabs
1 parent 274d793 commit 29cdca3

2 files changed

Lines changed: 129 additions & 159 deletions

File tree

openmc_plotter/docks.py

Lines changed: 95 additions & 80 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)
1112
import matplotlib.pyplot as plt
1213
import numpy as np
1314
import openmc
@@ -18,26 +19,26 @@
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 MeshAnnotationPanel(PlotterPanel):
38+
"""Panel for mesh annotation 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()
@@ -56,55 +57,88 @@ def __init__(self, model, font_metric, parent=None):
5657

5758
self.meshTree.setHeaderHidden(True)
5859

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)
6760
self.treeLayout.addWidget(self.meshTree)
68-
self.treeLayout.addWidget(HorizontalLine())
69-
self.treeLayout.addWidget(self.applyButton)
7061

71-
self.optionsWidget = QWidget()
72-
self.optionsWidget.setLayout(self.treeLayout)
73-
self.setWidget(self.optionsWidget)
62+
self.setLayout(self.treeLayout)
7463

7564
def get_checked_meshes(self):
7665
return [id for id, item in self.mesh_items if item.checkState(0) == QtCore.Qt.Checked]
7766

7867
def update(self):
7968
pass
8069

70+
71+
class TabbedDock(QDockWidget):
72+
"""
73+
Dock widget containing tabbed panels for Geometry, Tallies, and Mesh Annotations
74+
"""
75+
76+
def __init__(self, model, font_metric, parent=None):
77+
super().__init__(parent)
78+
79+
self.model = model
80+
self.font_metric = font_metric
81+
self.main_window = parent
82+
83+
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
84+
self.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea)
85+
86+
# Create the tab widget
87+
self.tabWidget = QTabWidget()
88+
89+
# Create the three panels
90+
self.geometryPanel = GeometryPanel(model, font_metric, parent, self)
91+
self.tallyPanel = TallyPanel(model, font_metric, parent, self)
92+
self.meshAnnotationPanel = MeshAnnotationPanel(model, font_metric, parent, self)
93+
94+
# Add panels as tabs
95+
self.tabWidget.addTab(self.geometryPanel, "Geometry")
96+
self.tabWidget.addTab(self.tallyPanel, "Tallies")
97+
self.tabWidget.addTab(self.meshAnnotationPanel, "Mesh Annotations")
98+
99+
# Create Apply Changes button
100+
self.applyButton = QPushButton("Apply Changes")
101+
self.applyButton.setMinimumHeight(self.font_metric.height() * 1.6)
102+
self.applyButton.clicked.connect(self.main_window.applyChanges)
103+
104+
# Main layout with tabs and apply button
105+
self.mainLayout = QVBoxLayout()
106+
self.mainLayout.addWidget(self.tabWidget)
107+
self.mainLayout.addWidget(HorizontalLine())
108+
self.mainLayout.addWidget(self.applyButton)
109+
110+
# Create container widget
111+
self.containerWidget = QWidget()
112+
self.containerWidget.setLayout(self.mainLayout)
113+
self.setWidget(self.containerWidget)
114+
115+
def updateDock(self):
116+
"""Update geometry panel"""
117+
self.geometryPanel.updateDock()
118+
119+
def update(self):
120+
"""Update tally panel"""
121+
self.tallyPanel.update()
122+
81123
def resizeEvent(self, event):
82124
self.main_window.resizeEvent(event)
83125

84126
hideEvent = showEvent = moveEvent = resizeEvent
85127

86128

87-
class DomainDock(PlotterDock):
129+
class GeometryPanel(PlotterPanel):
88130
"""
89-
Domain options dock
131+
Geometry options panel
90132
"""
91133

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

97137
# Create Controls
98138
self._createOriginBox()
99139
self._createOptionsBox()
100140
self._createResolutionBox()
101141

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-
108142
# Create Zoom box
109143
self.zoomBox = QSpinBox()
110144
self.zoomBox.setSuffix(' %')
@@ -120,22 +154,15 @@ def __init__(self, model, font_metric, parent=None):
120154
self.zoomWidget.setLayout(self.zoomLayout)
121155

122156
# 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)
157+
self.panelLayout = QVBoxLayout()
158+
self.panelLayout.addWidget(self.originGroupBox)
159+
self.panelLayout.addWidget(self.optionsGroupBox)
160+
self.panelLayout.addWidget(self.resGroupBox)
161+
self.panelLayout.addWidget(HorizontalLine())
162+
self.panelLayout.addWidget(self.zoomWidget)
163+
self.panelLayout.addStretch()
164+
165+
self.setLayout(self.panelLayout)
139166

140167
def _createOriginBox(self):
141168

@@ -362,20 +389,12 @@ def revertToCurrent(self):
362389
self.widthBox.setValue(cv.width)
363390
self.heightBox.setValue(cv.height)
364391

365-
def resizeEvent(self, event):
366-
self.main_window.resizeEvent(event)
367-
368-
hideEvent = showEvent = moveEvent = resizeEvent
369-
370-
371-
class TallyDock(PlotterDock):
372-
373-
def __init__(self, model, font_metric, parent=None):
374-
super().__init__(model, font_metric, parent)
392+
class TallyPanel(PlotterPanel):
375393

376-
self.setAllowedAreas(QtCore.Qt.RightDockWidgetArea)
394+
def __init__(self, model, font_metric, main_window, parent=None):
395+
super().__init__(model, font_metric, main_window, parent)
377396

378-
# Dock maps for tally information
397+
# Panel maps for tally information
379398
self.tally_map = {}
380399
self.filter_map = {}
381400
self.score_map = {}
@@ -395,11 +414,6 @@ def __init__(self, model, font_metric, parent=None):
395414
self.tallyGroupBox = QGroupBox('Selected Tally')
396415
self.tallyGroupBox.setLayout(self.tallySelectorLayout)
397416

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-
403417
# Color options section
404418
self.tallyColorForm = ColorForm(self.model, self.main_window, 'tally')
405419
self.scoresGroupBox = Expander(title="Scores:")
@@ -408,23 +422,24 @@ def __init__(self, model, font_metric, parent=None):
408422
self.nuclidesListWidget = QListWidget()
409423

410424
# 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
425+
self.panelLayout = QVBoxLayout()
426+
self.panelLayout.addWidget(self.tallyGroupBox)
427+
self.panelLayout.addStretch()
428+
self.panelLayout.addWidget(HorizontalLine())
429+
self.panelLayout.addWidget(self.tallyColorForm)
430+
431+
# Create widget for scroll area and apply main layout
422432
self.scroll = QScrollArea()
423433
self.scroll.setWidgetResizable(True)
424434
self.widget = QWidget()
425-
self.widget.setLayout(self.dockLayout)
435+
self.widget.setLayout(self.panelLayout)
426436
self.scroll.setWidget(self.widget)
427-
self.setWidget(self.scroll)
437+
438+
# Set scroll area as main layout
439+
mainLayout = QVBoxLayout()
440+
mainLayout.setContentsMargins(0, 0, 0, 0)
441+
mainLayout.addWidget(self.scroll)
442+
self.setLayout(mainLayout)
428443

429444
def _createFilterTree(self, spatial_filters):
430445
av = self.model.activeView

0 commit comments

Comments
 (0)