Skip to content

Commit 94d54e5

Browse files
authored
Make material info context window scrollable (#175)
1 parent df39fac commit 94d54e5

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

openmc_plotter/main_window.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from PySide6.QtGui import QKeyEvent, QAction
99
from PySide6.QtWidgets import (QApplication, QLabel, QSizePolicy, QMainWindow,
1010
QScrollArea, QMessageBox, QFileDialog,
11-
QColorDialog, QInputDialog, QWidget,
11+
QColorDialog, QInputDialog, QWidget, QDialog,
12+
QVBoxLayout, QPlainTextEdit, QDialogButtonBox,
1213
QGestureEvent)
1314

1415
import openmc
@@ -58,6 +59,8 @@ def __init__(self,
5859
self.default_res = resolution
5960
self.model = None
6061
self.plot_manager = None
62+
self.materialPropsDialog = None
63+
self.materialPropsText = None
6164

6265
def loadGui(self, use_settings_pkl=True):
6366

@@ -1287,12 +1290,14 @@ def exportTallyData(self):
12871290
self.showExportDialog()
12881291

12891292
def viewMaterialProps(self, id):
1290-
"""display material properties in message box"""
1293+
"""Display material properties in a scrollable dialog."""
12911294
mat = openmc.lib.materials[id]
12921295
if mat.name:
1293-
msg_str = f"Material {id} ({mat.name}) Properties\n\n"
1296+
title = f"Material {id} ({mat.name}) Properties"
12941297
else:
1295-
msg_str = f"Material {id} Properties\n\n"
1298+
title = f"Material {id} Properties"
1299+
1300+
msg_str = f"{title}\n\n"
12961301

12971302
# get density and temperature
12981303
dens_g = mat.get_density(units='g/cm3')
@@ -1305,7 +1310,28 @@ def viewMaterialProps(self, id):
13051310
for nuc, dens in zip(mat.nuclides, mat.densities):
13061311
msg_str += f'{nuc}: {dens:5.3e}\n'
13071312

1308-
msg_box = QMessageBox(self)
1309-
msg_box.setText(msg_str)
1310-
msg_box.setModal(False)
1311-
msg_box.show()
1313+
if self.materialPropsDialog is None:
1314+
dialog = QDialog(self)
1315+
dialog.setModal(False)
1316+
dialog.setMinimumSize(560, 420)
1317+
1318+
layout = QVBoxLayout(dialog)
1319+
text = QPlainTextEdit(dialog)
1320+
text.setReadOnly(True)
1321+
text.setLineWrapMode(QPlainTextEdit.NoWrap)
1322+
layout.addWidget(text)
1323+
1324+
buttons = QDialogButtonBox(QDialogButtonBox.Close, parent=dialog)
1325+
buttons.rejected.connect(dialog.close)
1326+
buttons.accepted.connect(dialog.close)
1327+
layout.addWidget(buttons)
1328+
1329+
self.materialPropsDialog = dialog
1330+
self.materialPropsText = text
1331+
1332+
self.materialPropsDialog.setWindowTitle(title)
1333+
self.materialPropsText.setPlainText(msg_str)
1334+
self.materialPropsText.moveCursor(QtGui.QTextCursor.Start)
1335+
self.materialPropsDialog.show()
1336+
self.materialPropsDialog.raise_()
1337+
self.materialPropsDialog.activateWindow()

0 commit comments

Comments
 (0)