Repository navigation
Expand file tree
/
Copy pathsettings_panel.py
More file actions
498 lines (382 loc) · 19.4 KB
/
Copy pathsettings_panel.py
File metadata and controls
498 lines (382 loc) · 19.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
"""
Settings Panel for NoSQL2SQL
Provides UI for configuring application settings
"""
import tkinter as tk
from tkinter import ttk, messagebox
from animated_toggle import LabeledToggle
from config_manager import SettingsManager
class SettingsPanel(tk.Toplevel):
"""Settings configuration window"""
def __init__(self, parent, config_manager, theme_manager, on_settings_changed=None):
super().__init__(parent)
self.config = config_manager
self.theme = theme_manager
self.on_settings_changed = on_settings_changed
self.title("Settings - NoSQL2SQL")
self.geometry("700x750")
self.resizable(True, True)
# Set minimum size
self.minsize(650, 700)
# Make modal
self.transient(parent)
self.grab_set()
self._create_ui()
self._load_settings()
# Center window
self.update_idletasks()
x = (self.winfo_screenwidth() // 2) - (self.winfo_width() // 2)
y = (self.winfo_screenheight() // 2) - (self.winfo_height() // 2)
self.geometry(f"+{x}+{y}")
def _create_ui(self):
"""Create settings UI"""
# Main container
main_frame = ttk.Frame(self, padding="15")
main_frame.pack(fill=tk.BOTH, expand=True)
# Title
title = ttk.Label(main_frame, text="⚙️ Settings",
font=("Arial", 16, "bold"))
title.pack(pady=(0, 15))
# Notebook for categories
notebook = ttk.Notebook(main_frame)
notebook.pack(fill=tk.BOTH, expand=True, pady=(0, 15))
# Create scrollable frames for each tab
appearance_frame = self._create_scrollable_frame(notebook)
notebook.add(appearance_frame, text="Appearance")
self._create_appearance_settings(appearance_frame.interior)
features_frame = self._create_scrollable_frame(notebook)
notebook.add(features_frame, text="Features")
self._create_features_settings(features_frame.interior)
ai_frame = self._create_scrollable_frame(notebook)
notebook.add(ai_frame, text="AI & MCP")
self._create_ai_settings(ai_frame.interior)
db_frame = self._create_scrollable_frame(notebook)
notebook.add(db_frame, text="Database")
self._create_database_settings(db_frame.interior)
advanced_frame = self._create_scrollable_frame(notebook)
notebook.add(advanced_frame, text="Advanced")
self._create_advanced_settings(advanced_frame.interior)
# Buttons
button_frame = ttk.Frame(main_frame)
button_frame.pack(fill=tk.X, pady=(10, 0))
ttk.Button(button_frame, text="Reset to Defaults",
command=self._reset_to_defaults).pack(side=tk.LEFT)
ttk.Button(button_frame, text="Cancel",
command=self.destroy).pack(side=tk.RIGHT, padx=(5, 0))
ttk.Button(button_frame, text="Save & Close",
command=self._save_and_close,
style="Accent.TButton").pack(side=tk.RIGHT)
def _create_scrollable_frame(self, parent):
"""Create a scrollable frame for settings"""
container = ttk.Frame(parent)
canvas = tk.Canvas(container, highlightthickness=0)
scrollbar = ttk.Scrollbar(container, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas, padding="15")
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(scrollregion=canvas.bbox("all"))
)
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)
canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
# Store interior frame for access
container.interior = scrollable_frame
# Bind mousewheel
def _on_mousewheel(event):
canvas.yview_scroll(int(-1*(event.delta/120)), "units")
canvas.bind_all("<MouseWheel>", _on_mousewheel)
return container
def _create_appearance_settings(self, parent):
"""Create appearance settings"""
# Theme selection
theme_label = ttk.Label(parent, text="Theme", font=("Arial", 11, "bold"))
theme_label.pack(anchor=tk.W, pady=(0, 10))
self.theme_var = tk.StringVar()
theme_options = ttk.Frame(parent)
theme_options.pack(fill=tk.X, pady=(0, 20))
ttk.Radiobutton(theme_options, text="🌞 Light",
variable=self.theme_var, value="light").pack(anchor=tk.W, pady=2)
ttk.Radiobutton(theme_options, text="🌙 Dark",
variable=self.theme_var, value="dark").pack(anchor=tk.W, pady=2)
ttk.Radiobutton(theme_options, text="💻 Auto (Follow System)",
variable=self.theme_var, value="auto").pack(anchor=tk.W, pady=2)
ttk.Label(parent, text="The theme will update when you save.",
style="Secondary.TLabel").pack(anchor=tk.W, pady=(0, 10))
def _create_features_settings(self, parent):
"""Create features settings"""
ttk.Label(parent, text="Enable/Disable Features",
font=("Arial", 11, "bold")).pack(anchor=tk.W, pady=(0, 15))
# Visualization
viz_frame = ttk.Frame(parent)
viz_frame.pack(fill=tk.X, pady=10)
self.viz_toggle = LabeledToggle(
viz_frame,
text="Schema Visualization",
on_color=self.theme.get_color("success"),
callback=None
)
self.viz_toggle.pack(side=tk.LEFT)
ttk.Label(viz_frame, text="Show ERD diagrams",
style="Secondary.TLabel").pack(side=tk.LEFT, padx=(20, 0))
# Chat History
chat_frame = ttk.Frame(parent)
chat_frame.pack(fill=tk.X, pady=10)
self.chat_history_toggle = LabeledToggle(
chat_frame,
text="Chat History",
on_color=self.theme.get_color("success"),
callback=None
)
self.chat_history_toggle.pack(side=tk.LEFT)
ttk.Label(chat_frame, text="Save conversation history",
style="Secondary.TLabel").pack(side=tk.LEFT, padx=(20, 0))
# Auto Backup
backup_frame = ttk.Frame(parent)
backup_frame.pack(fill=tk.X, pady=10)
self.backup_toggle = LabeledToggle(
backup_frame,
text="Auto Backup",
on_color=self.theme.get_color("success"),
callback=None
)
self.backup_toggle.pack(side=tk.LEFT)
ttk.Label(backup_frame, text="Create database backups",
style="Secondary.TLabel").pack(side=tk.LEFT, padx=(20, 0))
def _create_ai_settings(self, parent):
"""Create AI and MCP settings"""
# MCP Enable
ttk.Label(parent, text="Model Context Protocol",
font=("Arial", 11, "bold")).pack(anchor=tk.W, pady=(0, 15))
mcp_frame = ttk.Frame(parent)
mcp_frame.pack(fill=tk.X, pady=10)
self.mcp_toggle = LabeledToggle(
mcp_frame,
text="Enable MCP",
on_color=self.theme.get_color("accent"),
callback=self._on_mcp_toggle
)
self.mcp_toggle.pack(side=tk.LEFT)
ttk.Label(mcp_frame, text="Use MCP servers for migration",
style="Secondary.TLabel").pack(side=tk.LEFT, padx=(20, 0))
# Auto Start MCP
auto_start_frame = ttk.Frame(parent)
auto_start_frame.pack(fill=tk.X, pady=10)
self.mcp_auto_start_toggle = LabeledToggle(
auto_start_frame,
text="Auto-start MCP Servers",
on_color=self.theme.get_color("accent"),
callback=None
)
self.mcp_auto_start_toggle.pack(side=tk.LEFT)
ttk.Label(auto_start_frame, text="Start servers on app launch",
style="Secondary.TLabel").pack(side=tk.LEFT, padx=(20, 0))
ttk.Separator(parent, orient=tk.HORIZONTAL).pack(fill=tk.X, pady=20)
# AI Recommendations
ttk.Label(parent, text="AI-Powered Features",
font=("Arial", 11, "bold")).pack(anchor=tk.W, pady=(0, 15))
ai_frame = ttk.Frame(parent)
ai_frame.pack(fill=tk.X, pady=10)
self.ai_toggle = LabeledToggle(
ai_frame,
text="AI Recommendations",
on_color=self.theme.get_color("accent"),
callback=self._on_ai_toggle
)
self.ai_toggle.pack(side=tk.LEFT)
ttk.Label(ai_frame, text="Schema analysis with Gemini AI",
style="Secondary.TLabel").pack(side=tk.LEFT, padx=(20, 0))
# API Key
ttk.Label(parent, text="Gemini API Key:",
font=("Arial", 10)).pack(anchor=tk.W, pady=(20, 5))
api_key_frame = ttk.Frame(parent)
api_key_frame.pack(fill=tk.X, pady=(0, 10))
self.api_key_entry = ttk.Entry(api_key_frame, show="•", width=40)
self.api_key_entry.pack(side=tk.LEFT, fill=tk.X, expand=True)
self.show_api_key_var = tk.BooleanVar()
ttk.Checkbutton(api_key_frame, text="Show",
variable=self.show_api_key_var,
command=self._toggle_api_key_visibility).pack(side=tk.LEFT, padx=(10, 0))
ttk.Label(parent, text="⚠️ API key is encrypted and stored securely",
style="Secondary.TLabel", foreground=self.theme.get_color("warning")).pack(anchor=tk.W)
ttk.Label(parent, text="Get your free API key at: https://makersuite.google.com/app/apikey",
style="Secondary.TLabel", foreground=self.theme.get_color("link")).pack(anchor=tk.W, pady=(5, 0))
def _create_database_settings(self, parent):
"""Create database connection settings"""
ttk.Label(parent, text="MySQL Target Database",
font=("Arial", 11, "bold")).pack(anchor=tk.W, pady=(0, 15))
# MySQL Host
ttk.Label(parent, text="MySQL Host:").pack(anchor=tk.W, pady=(5, 2))
self.mysql_host_entry = ttk.Entry(parent, width=40)
self.mysql_host_entry.pack(anchor=tk.W, pady=(0, 10))
self.mysql_host_entry.insert(0, "localhost")
# MySQL Username
ttk.Label(parent, text="MySQL Username:").pack(anchor=tk.W, pady=(5, 2))
self.mysql_user_entry = ttk.Entry(parent, width=40)
self.mysql_user_entry.pack(anchor=tk.W, pady=(0, 10))
self.mysql_user_entry.insert(0, "root")
# MySQL Password
ttk.Label(parent, text="MySQL Password:").pack(anchor=tk.W, pady=(5, 2))
self.mysql_password_entry = ttk.Entry(parent, show="•", width=40)
self.mysql_password_entry.pack(anchor=tk.W, pady=(0, 15))
ttk.Separator(parent, orient=tk.HORIZONTAL).pack(fill=tk.X, pady=15)
ttk.Label(parent, text="Source Database Passwords",
font=("Arial", 11, "bold")).pack(anchor=tk.W, pady=(0, 15))
# Neo4j Password
ttk.Label(parent, text="Neo4j Password:").pack(anchor=tk.W, pady=(5, 2))
self.neo4j_password_entry = ttk.Entry(parent, show="•", width=40)
self.neo4j_password_entry.pack(anchor=tk.W, pady=(0, 10))
# CouchDB Password
ttk.Label(parent, text="CouchDB Password:").pack(anchor=tk.W, pady=(5, 2))
self.couchdb_password_entry = ttk.Entry(parent, show="•", width=40)
self.couchdb_password_entry.pack(anchor=tk.W, pady=(0, 10))
ttk.Label(parent, text="Note: Redis usually doesn't require a password for local installations",
style="Secondary.TLabel").pack(anchor=tk.W, pady=(10, 0))
def _create_advanced_settings(self, parent):
"""Create advanced settings"""
ttk.Label(parent, text="Advanced Options",
font=("Arial", 11, "bold")).pack(anchor=tk.W, pady=(0, 15))
# Window geometry
ttk.Label(parent, text="Default Window Size:").pack(anchor=tk.W, pady=(10, 5))
geometry_frame = ttk.Frame(parent)
geometry_frame.pack(anchor=tk.W, pady=(0, 10))
self.window_width = ttk.Entry(geometry_frame, width=10)
self.window_width.pack(side=tk.LEFT)
self.window_width.insert(0, "700")
ttk.Label(geometry_frame, text="×").pack(side=tk.LEFT, padx=5)
self.window_height = ttk.Entry(geometry_frame, width=10)
self.window_height.pack(side=tk.LEFT)
self.window_height.insert(0, "700")
# Config location
ttk.Label(parent, text=f"Configuration Directory:",
font=("Arial", 10)).pack(anchor=tk.W, pady=(20, 5))
config_path = ttk.Label(parent, text=str(self.config.config_dir),
style="Secondary.TLabel")
config_path.pack(anchor=tk.W)
ttk.Button(parent, text="Open Config Folder",
command=self._open_config_folder).pack(anchor=tk.W, pady=(10, 0))
def _load_settings(self):
"""Load current settings into UI"""
# Theme
self.theme_var.set(self.config.get("theme", "auto"))
# Features
self.viz_toggle.set_state(self.config.get("visualization_enabled", True), animate=False)
self.chat_history_toggle.set_state(self.config.get("chat_history_enabled", True), animate=False)
self.backup_toggle.set_state(self.config.get("auto_backup", True), animate=False)
# MCP & AI
self.mcp_toggle.set_state(self.config.get("mcp_enabled", False), animate=False)
self.mcp_auto_start_toggle.set_state(self.config.get("mcp_auto_start", False), animate=False)
self.ai_toggle.set_state(self.config.get("ai_recommendations_enabled", False), animate=False)
# API Key
api_key = self.config.get_secure("gemini_api_key", "")
if api_key:
self.api_key_entry.insert(0, api_key)
# MySQL credentials
mysql_host = self.config.get("mysql_host", "localhost")
self.mysql_host_entry.delete(0, tk.END)
self.mysql_host_entry.insert(0, mysql_host)
mysql_user = self.config.get("mysql_user", "root")
self.mysql_user_entry.delete(0, tk.END)
self.mysql_user_entry.insert(0, mysql_user)
mysql_password = self.config.get_secure("mysql_password", "")
if mysql_password:
self.mysql_password_entry.insert(0, mysql_password)
# Source database passwords
neo4j_password = self.config.get_secure("neo4j_password", "")
if neo4j_password:
self.neo4j_password_entry.insert(0, neo4j_password)
couchdb_password = self.config.get_secure("couchdb_password", "")
if couchdb_password:
self.couchdb_password_entry.insert(0, couchdb_password)
# Window geometry
geometry = self.config.get("window_geometry", "1200x900")
if 'x' in geometry:
width, height = geometry.split('x')
self.window_width.delete(0, tk.END)
self.window_width.insert(0, width)
self.window_height.delete(0, tk.END)
self.window_height.insert(0, height)
def _save_and_close(self):
"""Save settings and close window"""
# Save theme
self.config.set("theme", self.theme_var.get())
# Save features
self.config.set("visualization_enabled", self.viz_toggle.get_state())
self.config.set("chat_history_enabled", self.chat_history_toggle.get_state())
self.config.set("auto_backup", self.backup_toggle.get_state())
# Save MCP & AI
self.config.set("mcp_enabled", self.mcp_toggle.get_state())
self.config.set("mcp_auto_start", self.mcp_auto_start_toggle.get_state())
self.config.set("ai_recommendations_enabled", self.ai_toggle.get_state())
# Save API key
api_key = self.api_key_entry.get().strip()
if api_key:
self.config.set_secure("gemini_api_key", api_key)
# Save MySQL credentials
mysql_host = self.mysql_host_entry.get().strip()
if mysql_host:
self.config.set("mysql_host", mysql_host)
mysql_user = self.mysql_user_entry.get().strip()
if mysql_user:
self.config.set("mysql_user", mysql_user)
mysql_password = self.mysql_password_entry.get().strip()
self.config.set_secure("mysql_password", mysql_password)
# Save source database passwords
neo4j_password = self.neo4j_password_entry.get().strip()
self.config.set_secure("neo4j_password", neo4j_password)
couchdb_password = self.couchdb_password_entry.get().strip()
self.config.set_secure("couchdb_password", couchdb_password)
# Save window geometry
try:
width = int(self.window_width.get())
height = int(self.window_height.get())
self.config.set("window_geometry", f"{width}x{height}")
except:
pass
# Notify parent of changes
if self.on_settings_changed:
self.on_settings_changed()
messagebox.showinfo("Settings", "Settings saved successfully!")
self.destroy()
def _reset_to_defaults(self):
"""Reset all settings to defaults"""
if messagebox.askyesno("Reset Settings",
"Are you sure you want to reset all settings to defaults?"):
self.config.reset_to_defaults()
self._load_settings()
messagebox.showinfo("Reset", "Settings reset to defaults")
def _on_mcp_toggle(self, state):
"""Handle MCP toggle"""
if state and not self.config.has_gemini_api_key():
messagebox.showwarning("MCP",
"Please configure your Gemini API key to use MCP features")
def _on_ai_toggle(self, state):
"""Handle AI toggle"""
if state and not self.config.has_gemini_api_key():
messagebox.showwarning("AI Recommendations",
"Please configure your Gemini API key to use AI features")
def _toggle_api_key_visibility(self):
"""Toggle API key visibility"""
if self.show_api_key_var.get():
self.api_key_entry.config(show="")
else:
self.api_key_entry.config(show="•")
def _open_config_folder(self):
"""Open configuration folder in file explorer"""
import os
import subprocess
if os.name == 'nt': # Windows
os.startfile(str(self.config.config_dir))
elif os.name == 'posix': # Linux/Mac
subprocess.call(['xdg-open', str(self.config.config_dir)])
if __name__ == "__main__":
# Test settings panel
from theme_manager import ThemeManager
root = tk.Tk()
root.withdraw()
config = SettingsManager()
theme = ThemeManager(root, config.get_theme())
def on_changed():
print("Settings changed!")
panel = SettingsPanel(root, config, theme, on_changed)
root.wait_window(panel)