From 73da7b8ebbd3eaf193cc76af572c036a5f3bdec5 Mon Sep 17 00:00:00 2001 From: giodefelice Date: Mon, 13 Nov 2023 17:29:40 +0000 Subject: [PATCH 1/2] add button to refresh custom rules --- zxlive/proof_panel.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/zxlive/proof_panel.py b/zxlive/proof_panel.py index 08b436e1..d1bcb45e 100644 --- a/zxlive/proof_panel.py +++ b/zxlive/proof_panel.py @@ -98,11 +98,16 @@ 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] + # self.action_groups = [group.copy() for group in proof_actions.action_groups] custom_rules = [] for root, dirs, files in os.walk(get_custom_rules_path()): for file in files: @@ -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. From 138f5a1e2c88b1f8c69d83381e7a6d5aba3f94ad Mon Sep 17 00:00:00 2001 From: giodefelice Date: Mon, 13 Nov 2023 18:43:20 +0000 Subject: [PATCH 2/2] uncomment action_groups copying --- zxlive/proof_panel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zxlive/proof_panel.py b/zxlive/proof_panel.py index d1bcb45e..a78f3254 100644 --- a/zxlive/proof_panel.py +++ b/zxlive/proof_panel.py @@ -107,7 +107,7 @@ def _toolbar_sections(self) -> Iterator[ToolbarSection]: yield ToolbarSection(self.refresh_rules) def init_action_groups(self) -> None: - # self.action_groups = [group.copy() for group in proof_actions.action_groups] + self.action_groups = [group.copy() for group in proof_actions.action_groups] custom_rules = [] for root, dirs, files in os.walk(get_custom_rules_path()): for file in files: