From e5660ee64cd64f33fe7bd7622f06cdb5c74dd199 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sun, 11 Feb 2024 14:57:15 -0600 Subject: [PATCH 1/2] Allow score boxes to change without applying updates --- openmc_plotter/docks.py | 66 ++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/openmc_plotter/docks.py b/openmc_plotter/docks.py index 6115deb..457d45f 100644 --- a/openmc_plotter/docks.py +++ b/openmc_plotter/docks.py @@ -349,6 +349,7 @@ def __init__(self, model, font_metric, parent=None): self.tallyColorForm = ColorForm(self.model, self.main_window, 'tally') self.scoresGroupBox = Expander(title="Scores:") self.scoresListWidget = QListWidget() + self.scoresListWidget.itemChanged.connect(self.updateScores) self.nuclidesListWidget = QListWidget() # Main layout @@ -502,7 +503,6 @@ def selectTally(self, tally_label=None): # scores self.score_map = {} - self.score_map.clear() self.scoresListWidget.clear() sorted_scores = sorted(tally.scores) @@ -628,39 +628,37 @@ def updateScores(self): applied_scores.append(score) self.model.appliedScores = tuple(applied_scores) - if not applied_scores: - # if no scores are selected, enable all scores again - for score, score_box in self.score_map.items(): - sunits = _SCORE_UNITS.get(score, _REACTION_UNITS) - empty_item = QListWidgetItem() - score_box.setFlags(empty_item.flags() | - QtCore.Qt.ItemIsUserCheckable) - score_box.setFlags(empty_item.flags() & - ~QtCore.Qt.ItemIsSelectable) - elif 'total' in applied_scores: - self.model.appliedScores = ('total',) - # if total is selected, disable all other scores - for score, score_box in self.score_map.items(): - if score != 'total': - score_box.setFlags(QtCore.Qt.ItemIsUserCheckable) - score_box.setToolTip( - "De-select 'total' to enable other scores") - else: - # get units of applied scores - selected_units = _SCORE_UNITS.get( - applied_scores[0], _REACTION_UNITS) - # disable scores with incompatible units - for score, score_box in self.score_map.items(): - sunits = _SCORE_UNITS.get(score, _REACTION_UNITS) - if sunits != selected_units: - score_box.setFlags(QtCore.Qt.ItemIsUserCheckable) - score_box.setToolTip( - "Score is incompatible with currently selected scores") - else: - score_box.setFlags(score_box.flags() | - QtCore.Qt.ItemIsUserCheckable) - score_box.setFlags(score_box.flags() & - ~QtCore.Qt.ItemIsSelectable) + with QtCore.QSignalBlocker(self.scoresListWidget): + if not applied_scores: + # if no scores are selected, enable all scores again + for score, score_box in self.score_map.items(): + score_box.setFlags(QtCore.Qt.ItemIsUserCheckable | + QtCore.Qt.ItemIsEnabled | + QtCore.Qt.ItemIsSelectable) + elif 'total' in applied_scores: + self.model.appliedScores = ('total',) + # if total is selected, disable all other scores + for score, score_box in self.score_map.items(): + if score != 'total': + score_box.setFlags(QtCore.Qt.ItemIsUserCheckable) + score_box.setToolTip( + "De-select 'total' to enable other scores") + else: + # get units of applied scores + selected_units = _SCORE_UNITS.get( + applied_scores[0], _REACTION_UNITS) + # disable scores with incompatible units + for score, score_box in self.score_map.items(): + sunits = _SCORE_UNITS.get(score, _REACTION_UNITS) + if sunits != selected_units: + score_box.setFlags(QtCore.Qt.ItemIsUserCheckable) + score_box.setToolTip( + "Score is incompatible with currently selected scores") + else: + score_box.setFlags(score_box.flags() | + QtCore.Qt.ItemIsUserCheckable) + score_box.setFlags(score_box.flags() & + ~QtCore.Qt.ItemIsSelectable) def updateNuclides(self): applied_nuclides = [] From e4b41a58d58e7bda3d679543a4d0607f6a7fa223 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 12 Feb 2024 21:44:50 -0600 Subject: [PATCH 2/2] Remove special handling of 'total' score --- openmc_plotter/docks.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/openmc_plotter/docks.py b/openmc_plotter/docks.py index 457d45f..a090131 100644 --- a/openmc_plotter/docks.py +++ b/openmc_plotter/docks.py @@ -505,15 +505,9 @@ def selectTally(self, tally_label=None): self.score_map = {} self.scoresListWidget.clear() - sorted_scores = sorted(tally.scores) - # always put total first if present - if 'total' in sorted_scores: - idx = sorted_scores.index('total') - sorted_scores.insert(0, sorted_scores.pop(idx)) - - for score in sorted_scores: + for score in tally.scores: ql = QListWidgetItem() - ql.setText(score.capitalize()) + ql.setText(score) ql.setCheckState(QtCore.Qt.Unchecked) if not spatial_filters: ql.setFlags(QtCore.Qt.ItemIsUserCheckable) @@ -635,14 +629,6 @@ def updateScores(self): score_box.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - elif 'total' in applied_scores: - self.model.appliedScores = ('total',) - # if total is selected, disable all other scores - for score, score_box in self.score_map.items(): - if score != 'total': - score_box.setFlags(QtCore.Qt.ItemIsUserCheckable) - score_box.setToolTip( - "De-select 'total' to enable other scores") else: # get units of applied scores selected_units = _SCORE_UNITS.get(