|
28 | 28 | from tkinter import filedialog, messagebox |
29 | 29 |
|
30 | 30 | import customtkinter |
| 31 | +import yaml |
31 | 32 | from PIL import Image |
32 | 33 |
|
33 | 34 | from vuegen import report_generator |
|
45 | 46 | print("output_dir:", output_dir) |
46 | 47 | output_dir.mkdir(exist_ok=True, parents=True) |
47 | 48 | _PATH = f'{os.environ["PATH"]}' |
| 49 | +### config path for app |
| 50 | +config_file = Path(Path.home() / ".vuegen_gui" / "config.yaml").resolve() |
| 51 | +if not config_file.exists(): |
| 52 | + config_file.parent.mkdir(exist_ok=True, parents=True) |
| 53 | + config_app = dict(python_dir_entry="") |
| 54 | +else: |
| 55 | + with open(config_file, "r", encoding="utf-8") as f: |
| 56 | + config_app = yaml.safe_load(f) |
| 57 | +hash_config_app = hash(yaml.dump(config_app)) |
48 | 58 | ########################################################################################## |
49 | 59 | # Path to example data dependend on how the GUI is run |
50 | 60 | if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): |
@@ -104,6 +114,8 @@ def inner(): |
104 | 114 | pprint(kwargs) |
105 | 115 |
|
106 | 116 | if python_dir_entry.get(): |
| 117 | + if python_dir_entry.get() != config_app["python_dir_entry"]: |
| 118 | + config_app["python_dir_entry"] = python_dir_entry.get() |
107 | 119 | if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): |
108 | 120 | os.environ["PATH"] = os.pathsep.join( |
109 | 121 | [ |
@@ -141,7 +153,12 @@ def inner(): |
141 | 153 | f"\n\nReport in folder:\n{report_dir}" |
142 | 154 | f"\n\nConfiguration file at:\n{gen_config_path}", |
143 | 155 | ) |
| 156 | + global hash_config_app # ! fix this |
144 | 157 | print_completion_message(report_type.get()) |
| 158 | + if hash(yaml.dump(config_app)) != hash_config_app: |
| 159 | + with open(config_file, "w", encoding="utf-8") as f: |
| 160 | + yaml.dump(config_app, f) |
| 161 | + hash_config_app = hash(yaml.dump(config_app)) |
145 | 162 | except Exception as e: |
146 | 163 | stacktrace = traceback.format_exc() |
147 | 164 | messagebox.showerror( |
@@ -305,7 +322,7 @@ def select_directory(): |
305 | 322 | ctk_label_outdir.grid(row=row_count, column=0, columnspan=1, padx=10, pady=5) |
306 | 323 | row_count += 1 |
307 | 324 | ########################################################################################## |
308 | | -python_dir_entry = tk.StringVar(value="") |
| 325 | +python_dir_entry = tk.StringVar(value=config_app["python_dir_entry"]) |
309 | 326 | select_python_bin = create_select_directory(python_dir_entry) |
310 | 327 | select_python_bin_button = customtkinter.CTkButton( |
311 | 328 | app, text="Select Python binary", command=select_python_bin |
|
0 commit comments