|
3 | 3 | import webbrowser |
4 | 4 | import win32com.client |
5 | 5 | from tkextras import * |
6 | | -import pandas as pd |
7 | | -import io |
8 | 6 | import json |
9 | 7 |
|
10 | 8 |
|
@@ -43,7 +41,6 @@ def __init__(self, render_params=None, *args, **options): |
43 | 41 | self.tree.bind("<<TreeFilterUpdated>>", self.on_filter_updated) |
44 | 42 | self.tree.bind("<<TreeCheckAllUpdated>>", self.on_check_all_updated) |
45 | 43 | self.tree.bind("<<TreeToggleCell>>", self.on_toggle_cell) |
46 | | - |
47 | 44 | self.scrollbar = ttk.Scrollbar(self.frame1, orient="vertical", command=self.tree.yview) |
48 | 45 | self.tree.configure(yscrollcommand=self.scrollbar.set) |
49 | 46 | self.create_widgets() |
@@ -133,14 +130,42 @@ def btn_openf(self): |
133 | 130 | self.db_path.set(db_path) |
134 | 131 | self.update_widgets() |
135 | 132 |
|
| 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 | + |
136 | 160 | def update_widgets(self): |
137 | | - self.label1['text'] = f"MS Access database for export: \"{self.db_path.get().split('/')[-1]}\"" |
138 | | - self.label1.update() |
139 | 161 | self.db_connect() |
140 | 162 | if self.check_permissions(): |
| 163 | + self.label1['text'] = f"MS Access database for export: \"{self.db_path.get().split('/')[-1]}\"" |
| 164 | + self.label1.update() |
141 | 165 | self.make_tree() |
142 | 166 | self.recreate_widgets() |
143 | 167 |
|
| 168 | + |
144 | 169 | def show_permission_warning(self): |
145 | 170 | def open_link(event): |
146 | 171 | warning_window.destroy() |
@@ -249,24 +274,6 @@ def export_prepare(self): |
249 | 274 |
|
250 | 275 | return final_list, upload_list, output_sql_path |
251 | 276 |
|
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 | | - |
270 | 277 | def export(self): |
271 | 278 | export_lists = self.export_prepare() |
272 | 279 | if not export_lists: |
|
0 commit comments