Skip to content

Commit c797a72

Browse files
committed
1.3.x-beta config.json file check
1 parent 30bcabc commit c797a72

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

code/export-msaccess-sql.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import webbrowser
44
import win32com.client
55
from tkextras import *
6-
import pandas as pd
7-
import io
86
import json
97

108

@@ -43,7 +41,6 @@ def __init__(self, render_params=None, *args, **options):
4341
self.tree.bind("<<TreeFilterUpdated>>", self.on_filter_updated)
4442
self.tree.bind("<<TreeCheckAllUpdated>>", self.on_check_all_updated)
4543
self.tree.bind("<<TreeToggleCell>>", self.on_toggle_cell)
46-
4744
self.scrollbar = ttk.Scrollbar(self.frame1, orient="vertical", command=self.tree.yview)
4845
self.tree.configure(yscrollcommand=self.scrollbar.set)
4946
self.create_widgets()
@@ -133,14 +130,42 @@ def btn_openf(self):
133130
self.db_path.set(db_path)
134131
self.update_widgets()
135132

133+
def save_config(self):
134+
config = {
135+
"info": "MS Access to SQL Export configuration file",
136+
"db_path": self.db_path.get(),
137+
"tree": self.tree.df.to_dict()
138+
}
139+
with open('config.json', 'w') as f:
140+
json.dump(config, f, indent = 4)
141+
142+
def load_config(self, fpath='config.json'):
143+
try:
144+
with open(fpath, 'r') as f:
145+
config = json.load(f)
146+
if config['info'] and (config['info'] == "MS Access to SQL Export configuration file"):
147+
self.db_path.set(config["db_path"])
148+
self.update_widgets()
149+
self.tree.df = self.tree.df.from_dict(config["tree"])
150+
self.tree.rebuild_tree()
151+
self.update_column_style()
152+
else:
153+
raise
154+
except:
155+
fpath = filedialog.askopenfilename(filetypes=[("JSON files", "*.json")])
156+
if fpath:
157+
self.load_config(fpath)
158+
159+
136160
def update_widgets(self):
137-
self.label1['text'] = f"MS Access database for export: \"{self.db_path.get().split('/')[-1]}\""
138-
self.label1.update()
139161
self.db_connect()
140162
if self.check_permissions():
163+
self.label1['text'] = f"MS Access database for export: \"{self.db_path.get().split('/')[-1]}\""
164+
self.label1.update()
141165
self.make_tree()
142166
self.recreate_widgets()
143167

168+
144169
def show_permission_warning(self):
145170
def open_link(event):
146171
warning_window.destroy()
@@ -249,24 +274,6 @@ def export_prepare(self):
249274

250275
return final_list, upload_list, output_sql_path
251276

252-
def save_config(self):
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-
260-
261-
def load_config(self):
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"])
267-
self.tree.rebuild_tree()
268-
self.update_column_style()
269-
270277
def export(self):
271278
export_lists = self.export_prepare()
272279
if not export_lists:

0 commit comments

Comments
 (0)