Skip to content

Commit cef0db9

Browse files
committed
Popup destination selection dialog
1 parent ddcfb49 commit cef0db9

4 files changed

+8
-11
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# VSCode settings
55
.vscode
66

7+
# Output files
8+
*.html
9+
*.pdf
10+
711
# Byte-compiled / optimized / DLL files
812
__pycache__/
913
*.py[cod]

contract_generator.html

-7
This file was deleted.

contract_generator.pdf

-15.2 KB
Binary file not shown.

contract_generator.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import os
33
import pathlib
44
import sys
5+
from PySide2.QtCore import QFile
56

6-
from PySide2.QtWidgets import QApplication, QMainWindow
7+
from PySide2.QtWidgets import QApplication, QMainWindow, QFileDialog
78
from PySide2.QtWidgets import QMessageBox
89
from markdown import markdown
910
from weasyprint import HTML
@@ -436,16 +437,15 @@ def check_mandatory_fields(self):
436437
self.ui.generate_button.setEnabled(True)
437438

438439
def on_generate(self):
440+
pdf_path, _ = QFileDialog.getSaveFileName(self, caption="Save As", dir="Contract.pdf", filter="PDF (*.pdf)")
439441
md = self.get_markdown()
440442
html = markdown(md)
441-
# TODO decide where to store files
442-
html_path = pathlib.Path(sys.executable).parent / "contract.html"
443+
html_path = pathlib.Path(pdf_path).with_suffix(".html")
443444
with open(html_path, "w", encoding="utf-8", errors="xmlcharrefreplace") as f:
444445
f.write(html)
445446
msg = "Saved html to " + str(html_path)
446447
QMessageBox.information(self, "Info", msg)
447448

448-
pdf_path = html_path.with_suffix(".pdf")
449449
HTML(string=html).write_pdf(pdf_path)
450450
msg = "Saved pdf to " + str(pdf_path)
451451
QMessageBox.information(self, "Info", msg)

0 commit comments

Comments
 (0)