Skip to content

Commit 8be5123

Browse files
committed
1.3.x fix sql_path, code optimised
1 parent 4331452 commit 8be5123

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

code/export-msaccess-sql.py

+36-35
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class GetWidgetsFrame(WidgetsRender, ttk.Frame):
1010
"""
1111
The main class of the program is responsible for constructing the form and interaction of elements
1212
"""
13+
1314
def __init__(self, render_params=None, *args, **options):
1415
"""
1516
Initialization of the Frame, description of the main elements
@@ -49,42 +50,42 @@ def __init__(self, render_params=None, *args, **options):
4950
self.scrollbar = ttk.Scrollbar(self.frame1, orient="vertical", command=self.tree.yview)
5051
self.tree.configure(yscrollcommand=self.scrollbar.set)
5152
self.create_widgets()
52-
self.load_config('config.json',True)
53+
self.load_config('config.json', True)
5354

5455
def create_widgets(self):
5556
"""Building the main widgets at the beginning of program execution"""
56-
self.rgrid(self)
57-
self.rgrid(tk.Label(self, text="MS Access to SQL Export Tool", font=("Helvetica", 14)),
58-
dict(row=0, column=0, columnspan=3, pady=5))
59-
self.rgrid(self.lable_frame, dict(row=1, column=0, columnspan=3))
60-
self.rgrid(self.label_db_path, dict(row=0, column=0, columnspan=3, pady=5))
61-
self.rgrid(self.label_sql_path, dict(row=1, column=0, columnspan=3, pady=5))
62-
self.rgrid(tk.Button(self, text="MS Access File Open", command=self.btn_openf, font=("Helvetica", 11)),
63-
dict(row=2, column=0))
64-
self.rgrid(tk.Button(self, text="Save SQL script as...", command=self.btn_sql_path, font=("Helvetica", 11)),
65-
dict(row=2, column=1))
66-
self.rgrid(tk.Button(self, text=" Exit ", command=self.btn_exit, font=("Helvetica", 11)),
67-
dict(row=2, column=2, columnspan=2))
68-
self.rgrid(self.frame1, dict(row=4, column=0, columnspan=3))
69-
self.rgrid(self.tree, dict(row=0, column=0, pady=5))
70-
self.rgrid(self.scrollbar, dict(row=0, column=3, sticky="ns"))
71-
self.rgrid(tk.Button(self, text=" Save default config ", command=self.save_config, font=("Helvetica", 11)),
72-
dict(row=5, column=0, ))
73-
self.rgrid(tk.Button(self, text=" Save config as... ", command=self.save_config_as, font=("Helvetica", 11)),
74-
dict(row=5, column=1, ))
75-
self.rgrid(tk.Button(self, text=" Load config ", command=self.load_config, font=("Helvetica", 11)),
76-
dict(row=5, column=2, ))
77-
self.rgrid(tk.Button(self, text=" Run! ", command=self.btn_run, font=("Helvetica", 12, "bold")),
78-
dict(row=6, column=0, columnspan=3, pady=5))
57+
grid = self.rgrid
58+
grid(self)
59+
grid(tk.Label(self, text="MS Access to SQL Export Tool", font=("Helvetica", 14)),
60+
dict(row=0, column=0, columnspan=3, pady=5))
61+
grid(self.lable_frame, dict(row=1, column=0, columnspan=3))
62+
grid(self.label_db_path, dict(row=0, column=0, columnspan=3, pady=5))
63+
grid(self.label_sql_path, dict(row=1, column=0, columnspan=3, pady=5))
64+
grid(tk.Button(self, text="MS Access File Open", command=self.btn_openf, font=("Helvetica", 11)),
65+
dict(row=2, column=0))
66+
grid(tk.Button(self, text="Save SQL script as...", command=self.btn_sql_path, font=("Helvetica", 11)),
67+
dict(row=2, column=1))
68+
grid(tk.Button(self, text=" Exit ", command=self.btn_exit, font=("Helvetica", 11)),
69+
dict(row=2, column=2, columnspan=2))
70+
grid(self.frame1, dict(row=4, column=0, columnspan=3))
71+
grid(self.tree, dict(row=0, column=0, pady=5))
72+
grid(self.scrollbar, dict(row=0, column=3, sticky="ns"))
73+
grid(tk.Button(self, text=" Save default config ", command=self.save_config, font=("Helvetica", 11)),
74+
dict(row=5, column=0, ))
75+
grid(tk.Button(self, text=" Save config as... ", command=self.save_config_as, font=("Helvetica", 11)),
76+
dict(row=5, column=1, ))
77+
grid(tk.Button(self, text=" Load config ", command=self.load_config, font=("Helvetica", 11)),
78+
dict(row=5, column=2, ))
79+
grid(tk.Button(self, text=" Run! ", command=self.btn_run, font=("Helvetica", 12, "bold")),
80+
dict(row=6, column=0, columnspan=3, pady=5))
7981

8082
def recreate_widgets(self):
81-
self.rgrid(self.tree, dict(row=0, column=0, pady=5))
82-
self.rgrid(self.scrollbar, dict(row=0, column=3, sticky="ns"))
83-
self.rgrid(self.frame0, dict(row=3, column=0, columnspan=3, sticky="e"))
84-
self.rgrid(self.tree.filter_widget(self.frame0),
85-
dict(row=0, column=0, columnspan=3, padx=5, pady=5, sticky="ew"))
86-
self.rgrid(self.tree.checkbox_widget(self.frame0),
87-
dict(row=4, column=0, columnspan=3, padx=5, pady=5, sticky="e"))
83+
grid = self.rgrid
84+
grid(self.tree, dict(row=0, column=0, pady=5))
85+
grid(self.scrollbar, dict(row=0, column=3, sticky="ns"))
86+
grid(self.frame0, dict(row=3, column=0, columnspan=3, sticky="e"))
87+
grid(self.tree.filter_widget(self.frame0), dict(row=0, column=0, columnspan=3, padx=5, pady=5, sticky="ew"))
88+
grid(self.tree.checkbox_widget(self.frame0), dict(row=4, column=0, columnspan=3, padx=5, pady=5, sticky="e"))
8889

8990
def make_tree(self):
9091
self.tree.heading("table", text="Table")
@@ -162,7 +163,7 @@ def save_config(self, file_path='config.json'):
162163
"tree": self.tree.df.to_dict()
163164
}
164165
with open(file_path, 'w') as f:
165-
json.dump(config, f, indent = 4)
166+
json.dump(config, f, indent=4)
166167

167168
def save_config_as(self):
168169
file_path = filedialog.asksaveasfilename(
@@ -174,7 +175,7 @@ def save_config_as(self):
174175
if file_path:
175176
self.save_config(file_path)
176177

177-
def load_config(self, fpath='config.json', loadbyinit = False):
178+
def load_config(self, fpath='config.json', loadbyinit=False):
178179
try:
179180
with open(fpath, 'r') as f:
180181
config = json.load(f)
@@ -306,7 +307,7 @@ def resolve_dependencies(self, export_list):
306307

307308
return list(export_set), list(added_tables)
308309

309-
def export_prepare(self, output_sql_path = ""):
310+
def export_prepare(self, output_sql_path=""):
310311
df = self.tree.df
311312
export_list = df[df.iloc[:, 1] == "✔"]["table"].to_list()
312313
upload_list = df[df.iloc[:, 2] == "✔"]["table"].to_list()
@@ -327,7 +328,7 @@ def export_prepare(self, output_sql_path = ""):
327328
return final_list, upload_list, output_sql_path
328329

329330
def export(self):
330-
export_lists = self.export_prepare()
331+
export_lists = self.export_prepare(self.sql_path.get())
331332
if not export_lists:
332333
return
333334

-104 KB
Binary file not shown.

0 commit comments

Comments
 (0)