Skip to content

Commit

Permalink
Merge pull request #212 from dlyongemallo/save_lemma_default_name
Browse files Browse the repository at this point in the history
Default filename to lemma's name when saving.
  • Loading branch information
jvdwetering authored Dec 11, 2023
2 parents 836272f + cf83f3e commit 9822dda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions zxlive/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ def write_to_file(file_path: str, data: str) -> bool:
return True


def get_file_path_and_format(parent: QWidget, filter: str) -> Optional[tuple[str, FileFormat]]:
def get_file_path_and_format(parent: QWidget, filter: str, default_input: str = "") -> Optional[tuple[str, FileFormat]]:
file_path, selected_filter = QFileDialog.getSaveFileName(
parent=parent,
caption="Save File",
dir=default_input,
filter=filter,
)
if selected_filter == "":
Expand Down Expand Up @@ -227,8 +228,8 @@ def save_diagram_dialog(graph: GraphT, parent: QWidget) -> Optional[tuple[str, F

return file_path, selected_format

def _save_rule_or_proof_dialog(data: str, parent: QWidget, filter: str) -> Optional[tuple[str, FileFormat]]:
file_path_and_format = get_file_path_and_format(parent, filter)
def _save_rule_or_proof_dialog(data: str, parent: QWidget, filter: str, filename: str = "") -> Optional[tuple[str, FileFormat]]:
file_path_and_format = get_file_path_and_format(parent, filter, filename)
if file_path_and_format is None or not file_path_and_format[0]:
return None
file_path, selected_format = file_path_and_format
Expand All @@ -239,8 +240,8 @@ def _save_rule_or_proof_dialog(data: str, parent: QWidget, filter: str) -> Optio
def save_proof_dialog(proof_model: ProofModel, parent: QWidget) -> Optional[tuple[str, FileFormat]]:
return _save_rule_or_proof_dialog(proof_model.to_json(), parent, FileFormat.ZXProof.filter)

def save_rule_dialog(rule: CustomRule, parent: QWidget) -> Optional[tuple[str, FileFormat]]:
return _save_rule_or_proof_dialog(rule.to_json(), parent, FileFormat.ZXRule.filter)
def save_rule_dialog(rule: CustomRule, parent: QWidget, filename: str ="") -> Optional[tuple[str, FileFormat]]:
return _save_rule_or_proof_dialog(rule.to_json(), parent, FileFormat.ZXRule.filter, filename)

def export_proof_dialog(parent: QWidget) -> Optional[str]:
file_path_and_format = get_file_path_and_format(parent, FileFormat.TikZ.filter)
Expand Down
2 changes: 1 addition & 1 deletion zxlive/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def proof_as_lemma(self) -> None:
lhs_graph = self.active_panel.proof_model.graphs[0]
rhs_graph = self.active_panel.proof_model.graphs[-1]
rule = CustomRule(lhs_graph, rhs_graph, name, description)
save_rule_dialog(rule, self)
save_rule_dialog(rule, self, name + ".zxr" if name else "")

def update_colors(self) -> None:
if self.active_panel is not None:
Expand Down

0 comments on commit 9822dda

Please sign in to comment.