Skip to content

Commit 168cad6

Browse files
committed
1.3.x log_path added
1 parent e518f24 commit 168cad6

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

code/export-msaccess-sql.py

+44-3
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ def __init__(self, render_params=None, *args, **options):
3838
}}
3939
self.db_path = tk.StringVar(self, "")
4040
self.sql_path = tk.StringVar(self, "")
41+
self.log_path = tk.StringVar(self, "")
4142
self.config_path = tk.StringVar(self, "")
4243
self.lable_frame = ttk.Frame(self, padding=(2, 2))
4344
self.label_db_path = ttk.Label(self.lable_frame, text="MS Access database", font=("Helvetica", 12),
4445
wraplength=650)
4546
self.label_sql_path = ttk.Label(self.lable_frame, text="Exported SQL script:", font=("Helvetica", 12),
4647
wraplength=650)
48+
self.log_frame = ttk.Frame(self, borderwidth=1, relief="solid", padding=(2, 2))
49+
self.label_log_path = ttk.Label(self.log_frame, text="...", font=("Helvetica", 12), wraplength=650)
4750
self.frame0 = ttk.Frame(self, width=240, borderwidth=1, relief="solid", padding=(2, 2))
4851
self.frame1 = ttk.Frame(self, width=100, borderwidth=1, relief="solid", padding=(2, 2))
4952
self.tree = TreeviewDataFrame(self.frame1, columns=("table", "export", "data"), show="headings")
@@ -56,7 +59,11 @@ def __init__(self, render_params=None, *args, **options):
5659
self.load_config('config.json', True)
5760

5861
def create_widgets(self):
59-
"""Building the main widgets at the beginning of program execution"""
62+
"""
63+
Building the main widgets at the beginning of program execution
64+
Returns:
65+
66+
"""
6067
grid = self.rgrid
6168
grid(self)
6269
grid(tk.Label(self, text="MS Access to SQL Export Tool", font=("Helvetica", 14)),
@@ -79,8 +86,15 @@ def create_widgets(self):
7986
dict(row=5, column=1, ))
8087
grid(tk.Button(self, text=" Load config ", command=self.load_config, font=("Helvetica", 11)),
8188
dict(row=5, column=2, ))
89+
grid(self.log_frame, dict(row=6, column=0, columnspan=3, pady=5))
90+
self.log_frame.grid_columnconfigure(1, weight=1)
91+
grid(tk.Button(self.log_frame, text=" Logging in file: ", command=self.btn_log, font=("Helvetica", 11)),
92+
dict(row=0, column=0, pady=5))
93+
grid(self.label_log_path, dict(row=0, column=1, pady=5))
94+
grid(tk.Button(self.log_frame, text="X", command=self.btn_log_delete, font=("Helvetica", 11)),
95+
dict(row=0, column=2, padx=5, pady=5, sticky="e"))
8296
grid(tk.Button(self, text=" Run! ", command=self.btn_run, font=("Helvetica", 12, "bold")),
83-
dict(row=6, column=0, columnspan=3, pady=5))
97+
dict(row=7, column=0, columnspan=3, pady=5))
8498

8599
def recreate_widgets(self):
86100
grid = self.rgrid
@@ -119,6 +133,14 @@ def update_column_style(self):
119133
self.tree.item(item_id, tags=("normal",))
120134

121135
def on_filter_updated(self, event):
136+
"""
137+
138+
Args:
139+
event:
140+
141+
Returns:
142+
143+
"""
122144
pass
123145

124146
def on_check_all_updated(self, event):
@@ -128,6 +150,18 @@ def on_toggle_cell(self, event):
128150
"""Handles cell clicks to change flags."""
129151
self.update_column_style()
130152

153+
def btn_log(self):
154+
log_path = filedialog.asksaveasfilename(
155+
filetypes=[("Log files", "*.log")],
156+
initialfile="export-msaccess-sql.log"
157+
)
158+
self.log_path.set(log_path)
159+
self.update_label_log()
160+
161+
def btn_log_delete(self):
162+
self.log_path.set("")
163+
self.update_label_log()
164+
131165
def btn_run(self):
132166
"""
133167
Implementation of the "Run" button
@@ -160,6 +194,7 @@ def save_config(self, file_path='config.json'):
160194
"info": "MS Access to SQL Export configuration file",
161195
"db_path": self.db_path.get(),
162196
"sql_path": self.sql_path.get(),
197+
"log_path": self.log_path.get(),
163198
"tree": self.tree.df.to_dict()
164199
}
165200
with open(file_path, 'w') as f:
@@ -181,9 +216,11 @@ def load_config(self, fpath='config.json', loadbyinit=False):
181216
with open(fpath, 'r') as f:
182217
config = json.load(f)
183218

184-
if config['info'] and (config['info'] == "MS Access to SQL Export configuration file"):
219+
if ('info' in config) and (config['info'] == "MS Access to SQL Export configuration file"):
185220
self.db_path.set(config["db_path"])
186221
self.sql_path.set(config["sql_path"])
222+
if "log_path" in config:
223+
self.log_path.set(config["log_path"])
187224
self.update_widgets()
188225
self.tree.df = self.tree.df.from_dict(config["tree"])
189226
self.tree.rebuild_tree()
@@ -207,9 +244,13 @@ def update_label_db(self):
207244
def update_label_sql(self):
208245
self.label_sql_path['text'] = f"Exported SQL script: {self.sql_path.get()}"
209246

247+
def update_label_log(self):
248+
self.label_log_path['text'] = f"{self.log_path.get()}"
249+
210250
def update_widgets(self):
211251
self.update_label_db()
212252
self.update_label_sql()
253+
self.update_label_log()
213254

214255
def show_permission_warning(self):
215256
def open_link(event):

0 commit comments

Comments
 (0)