|
5 | 5 | from tkextras import * |
6 | 6 | import pandas as pd |
7 | 7 | import io |
| 8 | +import json |
8 | 9 |
|
9 | 10 |
|
10 | 11 | class GetWidgetsFrame(WidgetsRender, ttk.Frame): |
@@ -34,14 +35,15 @@ def __init__(self, render_params=None, *args, **options): |
34 | 35 | 12: "Text" |
35 | 36 | }} |
36 | 37 | self.db_path = tk.StringVar(self, "") |
| 38 | + self.config_path = tk.StringVar(self, "") |
37 | 39 | self.label1 = ttk.Label(self, text="", font=("Helvetica", 12)) |
38 | 40 | self.frame0 = ttk.Frame(self, width=240, borderwidth=1, relief="solid", padding=(2, 2)) |
39 | 41 | self.frame1 = ttk.Frame(self, width=100, borderwidth=1, relief="solid", padding=(2, 2)) |
40 | 42 | self.tree = TreeviewDataFrame(self.frame1, columns=("table", "export", "data"), show="headings") |
41 | 43 | self.tree.bind("<<TreeFilterUpdated>>", self.on_filter_updated) |
42 | 44 | self.tree.bind("<<TreeCheckAllUpdated>>", self.on_check_all_updated) |
43 | 45 | self.tree.bind("<<TreeToggleCell>>", self.on_toggle_cell) |
44 | | - self.json_str = "" |
| 46 | + |
45 | 47 | self.scrollbar = ttk.Scrollbar(self.frame1, orient="vertical", command=self.tree.yview) |
46 | 48 | self.tree.configure(yscrollcommand=self.scrollbar.set) |
47 | 49 | self.create_widgets() |
@@ -129,6 +131,9 @@ def btn_openf(self): |
129 | 131 | """ |
130 | 132 | db_path = filedialog.askopenfilename(filetypes=[("MS Access files", "*.mdb, *.accdb")]) |
131 | 133 | self.db_path.set(db_path) |
| 134 | + self.update_widgets() |
| 135 | + |
| 136 | + def update_widgets(self): |
132 | 137 | self.label1['text'] = f"MS Access database for export: \"{self.db_path.get().split('/')[-1]}\"" |
133 | 138 | self.label1.update() |
134 | 139 | self.db_connect() |
@@ -245,11 +250,20 @@ def export_prepare(self): |
245 | 250 | return final_list, upload_list, output_sql_path |
246 | 251 |
|
247 | 252 | def save_config(self): |
248 | | - df = self.tree.df |
249 | | - self.json_str = df.to_json() |
| 253 | + config = { |
| 254 | + "db_path": self.db_path.get(), |
| 255 | + "tree": self.tree.df.to_dict() |
| 256 | + } |
| 257 | + with open('config.json', 'w') as f: |
| 258 | + json.dump(config, f, indent = 4) |
| 259 | + |
250 | 260 |
|
251 | 261 | def load_config(self): |
252 | | - self.tree.df =pd.read_json(io.StringIO(self.json_str)) |
| 262 | + with open('config.json', 'r') as f: |
| 263 | + config = json.load(f) |
| 264 | + self.db_path.set(config["db_path"]) |
| 265 | + self.update_widgets() |
| 266 | + self.tree.df = self.tree.df.from_dict(config["tree"]) |
253 | 267 | self.tree.rebuild_tree() |
254 | 268 | self.update_column_style() |
255 | 269 |
|
|
0 commit comments