Skip to content

Commit 0f1d3ed

Browse files
committed
Add experimental overlay
1 parent 88ab7e0 commit 0f1d3ed

2 files changed

Lines changed: 55 additions & 13 deletions

File tree

openmc_plotter/main_window.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from PySide6.QtWidgets import (QApplication, QLabel, QSizePolicy, QMainWindow,
1010
QScrollArea, QMessageBox, QFileDialog,
1111
QColorDialog, QInputDialog, QWidget,
12-
QGestureEvent, QProgressBar)
12+
QGestureEvent)
1313

1414
import openmc
1515
import openmc.lib
@@ -115,12 +115,6 @@ def loadGui(self, use_settings_pkl=True):
115115
self.coord_label = QLabel()
116116
self.statusBar().addPermanentWidget(self.coord_label)
117117
self.coord_label.hide()
118-
self.busyIndicator = QProgressBar()
119-
self.busyIndicator.setRange(0, 0)
120-
self.busyIndicator.setMaximumWidth(self.font_metric.averageCharWidth() * 12)
121-
self.busyIndicator.setMaximumHeight(self.font_metric.height())
122-
self.busyIndicator.hide()
123-
self.statusBar().addPermanentWidget(self.busyIndicator)
124118

125119
self.plot_manager = self.model.plot_manager
126120
self.plot_manager.plot_started.connect(self._on_plot_started)
@@ -1252,11 +1246,12 @@ def waitForPlotIdle(self, timeout_ms=None):
12521246
return True
12531247

12541248
def _on_plot_started(self):
1255-
self.busyIndicator.show()
1256-
self.statusBar().showMessage('Generating Plot...')
1249+
if hasattr(self, "plotIm") and self.plotIm is not None:
1250+
self.plotIm.showUpdatingOverlay("Generating Plot...")
12571251

12581252
def _on_plot_queued(self):
1259-
self.statusBar().showMessage('Generating Plot... (update queued)')
1253+
if hasattr(self, "plotIm") and self.plotIm is not None:
1254+
self.plotIm.showUpdatingOverlay("Generating Plot... (update queued)")
12601255

12611256
def _on_plot_finished(self, view_snapshot, view_params, ids_map, properties):
12621257
if view_params != self.plot_manager.latest_view_params:
@@ -1273,8 +1268,8 @@ def _on_plot_error(self, error_msg):
12731268
msg_box.exec()
12741269

12751270
def _on_plot_idle(self):
1276-
self.busyIndicator.hide()
1277-
self.statusBar().showMessage('')
1271+
if hasattr(self, "plotIm") and self.plotIm is not None:
1272+
self.plotIm.hideUpdatingOverlay()
12781273

12791274
def saveSettings(self):
12801275
if self.model.statepoint:

openmc_plotter/plotgui.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from PySide6 import QtCore, QtGui
44
from PySide6.QtWidgets import (QWidget, QPushButton, QHBoxLayout, QVBoxLayout,
5-
QFormLayout, QComboBox, QSpinBox,
5+
QFormLayout, QComboBox, QSpinBox, QLabel,
66
QDoubleSpinBox, QSizePolicy, QMessageBox,
77
QCheckBox, QRubberBand, QMenu, QDialog,
88
QTabWidget, QTableView, QHeaderView)
@@ -21,6 +21,34 @@
2121
from .custom_widgets import HorizontalLine
2222

2323

24+
class PlotUpdateOverlay(QWidget):
25+
26+
def __init__(self, parent=None):
27+
super().__init__(parent)
28+
self.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents, True)
29+
self.setAttribute(QtCore.Qt.WA_StyledBackground, True)
30+
self.setFocusPolicy(QtCore.Qt.NoFocus)
31+
self.setStyleSheet("background-color: rgba(20, 20, 20, 140);")
32+
33+
layout = QVBoxLayout(self)
34+
layout.setContentsMargins(0, 0, 0, 0)
35+
layout.setAlignment(QtCore.Qt.AlignCenter)
36+
37+
self.label = QLabel("Generating Plot...", self)
38+
self.label.setAlignment(QtCore.Qt.AlignCenter)
39+
font = self.label.font()
40+
font.setPointSize(max(12, font.pointSize() + 6))
41+
font.setWeight(QtGui.QFont.DemiBold)
42+
self.label.setFont(font)
43+
self.label.setStyleSheet("color: white;")
44+
layout.addWidget(self.label)
45+
46+
self.hide()
47+
48+
def set_message(self, message: str):
49+
self.label.setText(message)
50+
51+
2452

2553
class PlotImage(FigureCanvas):
2654

@@ -59,6 +87,7 @@ def __init__(self, model: PlotModel, parent, main_window):
5987
self._last_data_indicator_value = None
6088

6189
self.menu = QMenu(self)
90+
self.update_overlay = PlotUpdateOverlay(self)
6291

6392
def enterEvent(self, event):
6493
self.setCursor(QtCore.Qt.CrossCursor)
@@ -122,6 +151,24 @@ def _resize(self):
122151
self.resize(self.parent.width() * z,
123152
self.parent.height() * z)
124153

154+
def resizeEvent(self, event):
155+
super().resizeEvent(event)
156+
if self.update_overlay is not None:
157+
self.update_overlay.setGeometry(self.rect())
158+
159+
def showUpdatingOverlay(self, message: str = "Generating Plot..."):
160+
if self.update_overlay is None:
161+
return
162+
self.update_overlay.set_message(message)
163+
self.update_overlay.setGeometry(self.rect())
164+
self.update_overlay.raise_()
165+
self.update_overlay.show()
166+
167+
def hideUpdatingOverlay(self):
168+
if self.update_overlay is None:
169+
return
170+
self.update_overlay.hide()
171+
125172
def saveImage(self, filename):
126173
"""Save an image of the current view
127174

0 commit comments

Comments
 (0)