Skip to content

Commit

Permalink
Merge pull request #135 from paulromano/scorebox-fixes
Browse files Browse the repository at this point in the history
Immediate updates to score selection for tally plotting
  • Loading branch information
pshriwise authored Feb 20, 2024
2 parents a6c5fd5 + e4b41a5 commit e772fb9
Showing 1 changed file with 26 additions and 42 deletions.
68 changes: 26 additions & 42 deletions openmc_plotter/docks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -502,18 +503,11 @@ def selectTally(self, tally_label=None):

# scores
self.score_map = {}
self.score_map.clear()
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)
Expand Down Expand Up @@ -628,39 +622,29 @@ 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)
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 = []
Expand Down

0 comments on commit e772fb9

Please sign in to comment.