Skip to content

Commit 30bcabc

Browse files
committed
1.3.0-beta save-load to config.json
1 parent 26fd80e commit 30bcabc

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

code/export-msaccess-sql.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from tkextras import *
66
import pandas as pd
77
import io
8+
import json
89

910

1011
class GetWidgetsFrame(WidgetsRender, ttk.Frame):
@@ -34,14 +35,15 @@ def __init__(self, render_params=None, *args, **options):
3435
12: "Text"
3536
}}
3637
self.db_path = tk.StringVar(self, "")
38+
self.config_path = tk.StringVar(self, "")
3739
self.label1 = ttk.Label(self, text="", font=("Helvetica", 12))
3840
self.frame0 = ttk.Frame(self, width=240, borderwidth=1, relief="solid", padding=(2, 2))
3941
self.frame1 = ttk.Frame(self, width=100, borderwidth=1, relief="solid", padding=(2, 2))
4042
self.tree = TreeviewDataFrame(self.frame1, columns=("table", "export", "data"), show="headings")
4143
self.tree.bind("<<TreeFilterUpdated>>", self.on_filter_updated)
4244
self.tree.bind("<<TreeCheckAllUpdated>>", self.on_check_all_updated)
4345
self.tree.bind("<<TreeToggleCell>>", self.on_toggle_cell)
44-
self.json_str = ""
46+
4547
self.scrollbar = ttk.Scrollbar(self.frame1, orient="vertical", command=self.tree.yview)
4648
self.tree.configure(yscrollcommand=self.scrollbar.set)
4749
self.create_widgets()
@@ -129,6 +131,9 @@ def btn_openf(self):
129131
"""
130132
db_path = filedialog.askopenfilename(filetypes=[("MS Access files", "*.mdb, *.accdb")])
131133
self.db_path.set(db_path)
134+
self.update_widgets()
135+
136+
def update_widgets(self):
132137
self.label1['text'] = f"MS Access database for export: \"{self.db_path.get().split('/')[-1]}\""
133138
self.label1.update()
134139
self.db_connect()
@@ -245,11 +250,20 @@ def export_prepare(self):
245250
return final_list, upload_list, output_sql_path
246251

247252
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+
250260

251261
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"])
253267
self.tree.rebuild_tree()
254268
self.update_column_style()
255269

0 commit comments

Comments
 (0)