Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add button to refresh custom rules #180

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions zxlive/proof_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,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 @@ -327,6 +332,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
Loading