Skip to content

Commit

Permalink
Merge pull request #180 from Quantomatic/refresh-panel
Browse files Browse the repository at this point in the history
add button to refresh custom rules
  • Loading branch information
RazinShaikh authored Nov 13, 2023
2 parents dba9c5d + 138f5a1 commit a5c88cc
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions zxlive/proof_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ def _toolbar_sections(self) -> Iterator[ToolbarSection]:
self.identity_choice[1].setText("X")
self.identity_choice[1].setCheckable(True)

self.refresh_rules = QToolButton(self)
self.refresh_rules.setText("Refresh rules")
self.refresh_rules.clicked.connect(self._refresh_rules)

yield ToolbarSection(*self.identity_choice, exclusive=True)
yield ToolbarSection(*self.actions())
yield ToolbarSection(self.refresh_rules)

def init_action_groups(self) -> None:
self.action_groups = [group.copy() for group in proof_actions.action_groups]
Expand Down Expand Up @@ -362,6 +367,28 @@ def _proof_step_selected(self, selected: QItemSelection, deselected: QItemSelect
cmd = GoToRewriteStep(self.graph_view, self.step_view, deselected.first().topLeft().row(), selected.first().topLeft().row())
self.undo_stack.push(cmd)

def _refresh_rules(self):
self.actions_bar.removeTab(self.actions_bar.count() - 1)
custom_rules = []
for root, dirs, files in os.walk(get_custom_rules_path()):
for file in files:
if file.endswith(".zxr"):
zxr_file = os.path.join(root, file)
with open(zxr_file, "r") as f:
rule = CustomRule.from_json(f.read()).to_proof_action()
custom_rules.append(rule)
group = proof_actions.ProofActionGroup("Custom rules", *custom_rules).copy()
hlayout = QHBoxLayout()
group.init_buttons(self)
for action in group.actions:
assert action.button is not None
hlayout.addWidget(action.button)
hlayout.addStretch()
widget = QWidget()
widget.setLayout(hlayout)
widget.action_group = group
self.actions_bar.addTab(widget, group.name)


class ProofStepItemDelegate(QStyledItemDelegate):
"""This class controls the painting of items in the proof steps list view.
Expand Down

0 comments on commit a5c88cc

Please sign in to comment.