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

Default filename to lemma's name when saving. #212

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
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
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 @@ -538,7 +538,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
Loading