execsql2 2.37.0__py3-none-any.whl → 2.39.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- execsql/api.py +95 -45
- execsql/cli/commands/run.py +2 -2
- execsql/cli/lint.py +46 -9
- execsql/cli/run.py +128 -56
- execsql/config.py +7 -0
- execsql/data/execsql.conf.template +26 -2
- execsql/db/base.py +61 -24
- execsql/db/dsn.py +2 -3
- execsql/db/duckdb.py +43 -4
- execsql/db/firebird.py +39 -22
- execsql/db/mysql.py +22 -23
- execsql/db/oracle.py +11 -4
- execsql/db/postgres.py +15 -20
- execsql/db/sqlite.py +117 -10
- execsql/db/sqlserver.py +11 -7
- execsql/db/target_types.py +151 -4
- execsql/debug/repl.py +2 -1
- execsql/exceptions.py +19 -0
- execsql/exporters/html.py +26 -42
- execsql/exporters/ods.py +93 -21
- execsql/exporters/sqlite.py +82 -47
- execsql/format.py +12 -4
- execsql/gui/__init__.py +13 -10
- execsql/gui/base.py +131 -8
- execsql/gui/console.py +77 -30
- execsql/gui/desktop.py +290 -119
- execsql/gui/tui.py +384 -129
- execsql/importers/base.py +15 -19
- execsql/importers/csv.py +3 -5
- execsql/importers/json.py +37 -13
- execsql/importers/ods.py +22 -2
- execsql/lsp/document.py +6 -1
- execsql/lsp/hover.py +2 -1
- execsql/metacommands/conditions.py +3 -1
- execsql/metacommands/connect.py +18 -3
- execsql/metacommands/control.py +20 -5
- execsql/metacommands/data.py +11 -9
- execsql/metacommands/dispatch.py +10 -0
- execsql/metacommands/io.py +1 -0
- execsql/metacommands/io_export.py +1 -2
- execsql/metacommands/io_fileops.py +27 -91
- execsql/metacommands/io_import.py +26 -8
- execsql/metacommands/io_write.py +0 -9
- execsql/metacommands/prompt.py +94 -42
- execsql/metacommands/reference.py +7 -0
- execsql/metacommands/system.py +0 -2
- execsql/parser.py +132 -45
- execsql/script/control.py +17 -7
- execsql/script/engine.py +1 -1
- execsql/script/executor.py +184 -37
- execsql/script/preparation.py +42 -0
- execsql/types.py +6 -5
- execsql/utils/auth.py +11 -6
- execsql/utils/errors.py +2 -2
- execsql/utils/fileio.py +342 -134
- execsql/utils/gui.py +162 -53
- execsql/utils/spreadsheet.py +74 -0
- execsql/utils/strings.py +13 -7
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/README.md +5 -5
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/example_config_prompt.sql +2 -2
- {execsql2-2.37.0.dist-info → execsql2-2.39.1.dist-info}/METADATA +32 -119
- {execsql2-2.37.0.dist-info → execsql2-2.39.1.dist-info}/RECORD +77 -75
- {execsql2-2.37.0.dist-info → execsql2-2.39.1.dist-info}/WHEEL +1 -1
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/config_settings.sqlite +0 -0
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/make_config_db.sql +0 -0
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/md_compare.sql +0 -0
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/md_glossary.sql +0 -0
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/md_upsert.sql +0 -0
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/pg_compare.sql +0 -0
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/pg_glossary.sql +0 -0
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/script_template.sql +0 -0
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/ss_compare.sql +0 -0
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/ss_glossary.sql +0 -0
- {execsql2-2.37.0.data → execsql2-2.39.1.data}/data/execsql2_extras/ss_upsert.sql +0 -0
- {execsql2-2.37.0.dist-info → execsql2-2.39.1.dist-info}/entry_points.txt +0 -0
- {execsql2-2.37.0.dist-info → execsql2-2.39.1.dist-info}/licenses/LICENSE.txt +0 -0
- {execsql2-2.37.0.dist-info → execsql2-2.39.1.dist-info}/licenses/NOTICE +0 -0
execsql/gui/desktop.py
CHANGED
|
@@ -15,7 +15,7 @@ import time
|
|
|
15
15
|
from typing import Any, cast
|
|
16
16
|
from collections.abc import Callable
|
|
17
17
|
|
|
18
|
-
from execsql.gui.base import GuiBackend
|
|
18
|
+
from execsql.gui.base import GuiBackend, _key_column_indices, normalize_text_entry, selected_row_values
|
|
19
19
|
|
|
20
20
|
# ---------------------------------------------------------------------------
|
|
21
21
|
# Tkinter import guard
|
|
@@ -224,6 +224,7 @@ class PauseDialog:
|
|
|
224
224
|
class DisplayDialog:
|
|
225
225
|
def __init__(self, root: tk.Tk, args: dict) -> None:
|
|
226
226
|
self.result: dict = {}
|
|
227
|
+
self._args = args
|
|
227
228
|
|
|
228
229
|
win = tk.Toplevel(root)
|
|
229
230
|
win.title(args.get("title", ""))
|
|
@@ -282,10 +283,20 @@ class DisplayDialog:
|
|
|
282
283
|
root.wait_window(win)
|
|
283
284
|
|
|
284
285
|
def _close(self, win: tk.Toplevel, value: int | None) -> None:
|
|
285
|
-
self.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
return_value = self._text_var.get() if self._text_var else None
|
|
287
|
+
if value is not None and return_value is not None:
|
|
288
|
+
try:
|
|
289
|
+
return_value = normalize_text_entry(
|
|
290
|
+
return_value,
|
|
291
|
+
self._args.get("textentrytype"),
|
|
292
|
+
self._args.get("textentrycase"),
|
|
293
|
+
)
|
|
294
|
+
except ValueError as exc:
|
|
295
|
+
from tkinter import messagebox
|
|
296
|
+
|
|
297
|
+
messagebox.showerror("Invalid entry", str(exc), parent=win)
|
|
298
|
+
return
|
|
299
|
+
self.result = {"button": value, "return_value": return_value}
|
|
289
300
|
if win.winfo_exists():
|
|
290
301
|
win.destroy()
|
|
291
302
|
|
|
@@ -520,14 +531,13 @@ class CompareDialog:
|
|
|
520
531
|
|
|
521
532
|
tree1 = _add_tree(tables_frame, "Table 1", headers1, rows1)
|
|
522
533
|
tree2 = _add_tree(tables_frame, "Table 2", headers2, rows2)
|
|
534
|
+
iids1 = tree1.get_children()
|
|
535
|
+
iids2 = tree2.get_children()
|
|
523
536
|
|
|
524
537
|
# Cross-table row highlighting based on key columns
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
key_idx1 = [i for i, h in enumerate(headers1_str) if h in keylist]
|
|
529
|
-
key_idx2 = [i for i, h in enumerate(headers2_str) if h in keylist]
|
|
530
|
-
|
|
538
|
+
key_idx1 = _key_column_indices([str(h) for h in headers1], keylist)
|
|
539
|
+
key_idx2 = _key_column_indices([str(h) for h in headers2], keylist)
|
|
540
|
+
if key_idx1 and key_idx2:
|
|
531
541
|
# Syncing uses display-consistent string normalization (treeview
|
|
532
542
|
# values are strings). The diff engine in base.py has its own
|
|
533
543
|
# _pk_tuple with native-equality semantics — it does not share
|
|
@@ -535,8 +545,6 @@ class CompareDialog:
|
|
|
535
545
|
def _kv(row, idxs):
|
|
536
546
|
return tuple(str(row[i]) if row[i] is not None else "" for i in idxs)
|
|
537
547
|
|
|
538
|
-
iids1 = tree1.get_children()
|
|
539
|
-
iids2 = tree2.get_children()
|
|
540
548
|
iid_to_kv1 = {iid: _kv(rows1[i], key_idx1) for i, iid in enumerate(iids1)}
|
|
541
549
|
iid_to_kv2 = {iid: _kv(rows2[i], key_idx2) for i, iid in enumerate(iids2)}
|
|
542
550
|
# First occurrence wins for duplicate PKs (consistent with compute_row_diffs).
|
|
@@ -674,6 +682,7 @@ class CompareDialog:
|
|
|
674
682
|
class SelectRowsDialog:
|
|
675
683
|
def __init__(self, root: tk.Tk, args: dict) -> None:
|
|
676
684
|
self.result: dict = {}
|
|
685
|
+
self._selected_rows: list[list[Any]] = []
|
|
677
686
|
|
|
678
687
|
win = tk.Toplevel(root)
|
|
679
688
|
win.title(args.get("title", "Select rows"))
|
|
@@ -689,7 +698,10 @@ class SelectRowsDialog:
|
|
|
689
698
|
anchor="w",
|
|
690
699
|
pady=(0, 4),
|
|
691
700
|
)
|
|
692
|
-
ttk.Label(
|
|
701
|
+
ttk.Label(
|
|
702
|
+
frame,
|
|
703
|
+
text="Double-click a source row to add it; double-click an added destination row to remove that copy. Existing rows are kept.",
|
|
704
|
+
).pack(
|
|
693
705
|
anchor="w",
|
|
694
706
|
pady=(0, 8),
|
|
695
707
|
)
|
|
@@ -713,19 +725,40 @@ class SelectRowsDialog:
|
|
|
713
725
|
tree.configure(yscrollcommand=vsb.set)
|
|
714
726
|
tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
|
715
727
|
vsb.pack(side=tk.RIGHT, fill=tk.Y)
|
|
716
|
-
ttk.Label(lf, text=_row_count_text(len(rows)))
|
|
717
|
-
|
|
728
|
+
count = ttk.Label(lf, text=_row_count_text(len(rows)))
|
|
729
|
+
count.pack(anchor="w")
|
|
730
|
+
return tree, count
|
|
718
731
|
|
|
719
|
-
src_tree = _add_tree_frame(tables_frame, "Source", headers1, rows1)
|
|
720
|
-
dst_tree = _add_tree_frame(tables_frame, "Destination", headers2, rows2)
|
|
732
|
+
src_tree, _ = _add_tree_frame(tables_frame, "Source", headers1, rows1)
|
|
733
|
+
dst_tree, dst_count = _add_tree_frame(tables_frame, "Destination", headers2, rows2)
|
|
734
|
+
source_rows = {key: list(row) for key, row in zip(src_tree.get_children(), rows1)}
|
|
735
|
+
|
|
736
|
+
pending_rows = {}
|
|
721
737
|
|
|
722
738
|
def _on_double_click(event):
|
|
723
739
|
sel = src_tree.selection()
|
|
724
740
|
if sel:
|
|
725
741
|
row_id = sel[0]
|
|
726
|
-
values =
|
|
727
|
-
|
|
728
|
-
|
|
742
|
+
values = source_rows[row_id]
|
|
743
|
+
selected = list(values)
|
|
744
|
+
self._selected_rows.append(selected)
|
|
745
|
+
display = selected_row_values(headers1, values, headers2)
|
|
746
|
+
key = dst_tree.insert("", "end", values=[str(value) if value is not None else "" for value in display])
|
|
747
|
+
pending_rows[key] = selected
|
|
748
|
+
dst_count.configure(text=_row_count_text(len(rows2) + len(self._selected_rows)))
|
|
749
|
+
|
|
750
|
+
def _remove_row(event=None):
|
|
751
|
+
selection = dst_tree.selection()
|
|
752
|
+
key = dst_tree.identify_row(event.y) if event is not None else selection[0] if selection else None
|
|
753
|
+
selected = pending_rows.pop(key, None)
|
|
754
|
+
if selected is not None:
|
|
755
|
+
self._selected_rows = [row for row in self._selected_rows if row is not selected]
|
|
756
|
+
dst_tree.delete(key)
|
|
757
|
+
dst_count.configure(text=_row_count_text(len(rows2) + len(self._selected_rows)))
|
|
758
|
+
return "break"
|
|
759
|
+
|
|
760
|
+
dst_tree.bind("<Double-1>", _remove_row)
|
|
761
|
+
dst_tree.bind("<Return>", lambda event: _remove_row())
|
|
729
762
|
src_tree.bind("<Double-1>", _on_double_click)
|
|
730
763
|
src_tree.bind("<Return>", _on_double_click)
|
|
731
764
|
|
|
@@ -734,12 +767,13 @@ class SelectRowsDialog:
|
|
|
734
767
|
btn_frame.pack(pady=8, anchor="e")
|
|
735
768
|
_add_buttons(btn_frame, button_list, lambda v: self._close(win, v))
|
|
736
769
|
win.bind("<Escape>", lambda e: self._close(win, None))
|
|
770
|
+
win.protocol("WM_DELETE_WINDOW", lambda: self._close(win, None))
|
|
737
771
|
|
|
738
772
|
_center_window(win, 900, 500)
|
|
739
773
|
root.wait_window(win)
|
|
740
774
|
|
|
741
775
|
def _close(self, win: tk.Toplevel, value: int | None) -> None:
|
|
742
|
-
self.result = {"button": value}
|
|
776
|
+
self.result = {"button": value, "rows": self._selected_rows if value is not None else None}
|
|
743
777
|
if win.winfo_exists():
|
|
744
778
|
win.destroy()
|
|
745
779
|
|
|
@@ -775,26 +809,33 @@ class SelectSubDialog:
|
|
|
775
809
|
tree_frame.pack(fill=tk.BOTH, expand=True)
|
|
776
810
|
tree = ttk.Treeview(tree_frame, height=min(10, len(rows)))
|
|
777
811
|
_populate_treeview(tree, headers, rows)
|
|
812
|
+
source_rows = {key: list(row) for key, row in zip(tree.get_children(), rows)}
|
|
778
813
|
vsb = ttk.Scrollbar(tree_frame, orient=tk.VERTICAL, command=tree.yview)
|
|
779
814
|
tree.configure(yscrollcommand=vsb.set)
|
|
780
815
|
tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
|
781
816
|
vsb.pack(side=tk.RIGHT, fill=tk.Y)
|
|
782
817
|
ttk.Label(frame, text=_row_count_text(len(rows))).pack(anchor="w")
|
|
783
818
|
|
|
784
|
-
def _select():
|
|
785
|
-
|
|
786
|
-
if
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
819
|
+
def _select(value=1):
|
|
820
|
+
selected_row = None
|
|
821
|
+
if value == 1:
|
|
822
|
+
sel = tree.selection()
|
|
823
|
+
if not sel:
|
|
824
|
+
return
|
|
825
|
+
selected_row = source_rows[sel[0]]
|
|
826
|
+
self.result = {"button": value, "row": selected_row}
|
|
827
|
+
win.destroy()
|
|
791
828
|
|
|
792
829
|
btn_frame = ttk.Frame(frame)
|
|
793
830
|
btn_frame.pack(pady=8, anchor="e")
|
|
794
|
-
|
|
831
|
+
button_list = args.get("button_list", [("OK", 1, "<Return>")])
|
|
832
|
+
_add_buttons(btn_frame, button_list, _select)
|
|
795
833
|
ttk.Button(btn_frame, text="Cancel", command=lambda: self._close(win)).pack(side=tk.LEFT, padx=4)
|
|
796
834
|
tree.bind("<Double-1>", lambda e: _select())
|
|
835
|
+
if not any(len(button) > 2 and button[2] == "<Return>" for button in button_list):
|
|
836
|
+
win.bind("<Return>", lambda e: _select())
|
|
797
837
|
win.bind("<Escape>", lambda e: self._close(win))
|
|
838
|
+
win.protocol("WM_DELETE_WINDOW", lambda: self._close(win))
|
|
798
839
|
|
|
799
840
|
_center_window(win, 600, 350)
|
|
800
841
|
root.wait_window(win)
|
|
@@ -820,46 +861,135 @@ class ActionDialog:
|
|
|
820
861
|
|
|
821
862
|
frame = ttk.Frame(win, padding=12)
|
|
822
863
|
frame.pack(fill=tk.BOTH, expand=True)
|
|
864
|
+
frame.columnconfigure(0, weight=1)
|
|
865
|
+
frame.rowconfigure(0, weight=1)
|
|
823
866
|
_add_help_button(frame, args.get("help_url"))
|
|
824
867
|
|
|
868
|
+
canvas = tk.Canvas(frame, width=600, height=1, highlightthickness=0, yscrollincrement=20)
|
|
869
|
+
canvas.grid(row=0, column=0, sticky="nsew")
|
|
870
|
+
scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL, command=canvas.yview)
|
|
871
|
+
scrollbar.grid(row=0, column=1, sticky="ns")
|
|
872
|
+
canvas.configure(yscrollcommand=scrollbar.set)
|
|
873
|
+
content = ttk.Frame(canvas)
|
|
874
|
+
content_window = canvas.create_window((0, 0), window=content, anchor="nw")
|
|
875
|
+
content.bind("<Configure>", lambda event: canvas.configure(scrollregion=canvas.bbox("all")))
|
|
876
|
+
|
|
877
|
+
wrapped_labels = []
|
|
825
878
|
message = args.get("message", "")
|
|
826
879
|
if message:
|
|
827
|
-
ttk.Label(
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
880
|
+
message_label = ttk.Label(content, text=message, wraplength=580, anchor="w", justify="left")
|
|
881
|
+
message_label.pack(fill=tk.X, pady=(0, 8))
|
|
882
|
+
wrapped_labels.append(message_label)
|
|
883
|
+
|
|
884
|
+
def fit_width(event):
|
|
885
|
+
canvas.itemconfigure(content_window, width=event.width)
|
|
886
|
+
for label in wrapped_labels:
|
|
887
|
+
label.configure(wraplength=max(1, event.width))
|
|
831
888
|
|
|
889
|
+
canvas.bind("<Configure>", fit_width)
|
|
832
890
|
headers = args.get("column_headers")
|
|
833
891
|
rows = args.get("rowset")
|
|
892
|
+
tree = None
|
|
893
|
+
source_rows = {}
|
|
834
894
|
if headers and rows:
|
|
835
|
-
tree = ttk.Treeview(
|
|
895
|
+
tree = ttk.Treeview(content, height=min(6, len(rows)), selectmode="browse")
|
|
836
896
|
_populate_treeview(tree, headers, rows)
|
|
837
|
-
|
|
838
|
-
|
|
897
|
+
source_rows = {key: list(row) for key, row in zip(tree.get_children(), rows)}
|
|
898
|
+
tree.pack(fill=tk.X, pady=(0, 4))
|
|
899
|
+
ttk.Label(content, text=_row_count_text(len(rows))).pack(anchor="w", pady=(0, 8))
|
|
839
900
|
|
|
840
901
|
button_specs = args.get("button_specs", [])
|
|
841
|
-
|
|
842
|
-
btn_text = f"{spec.label}\n{spec.prompt}"
|
|
902
|
+
action_buttons: list[ttk.Button] = []
|
|
843
903
|
|
|
844
|
-
|
|
845
|
-
|
|
904
|
+
def selected_row():
|
|
905
|
+
selected = tree.selection() if tree is not None else ()
|
|
906
|
+
return source_rows.get(selected[0]) if selected else None
|
|
846
907
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
908
|
+
def select_action(index):
|
|
909
|
+
row = selected_row() if button_specs[index].data_required else None
|
|
910
|
+
if button_specs[index].data_required and row is None:
|
|
911
|
+
return
|
|
912
|
+
self.result = {"button": index + 1, "row": row}
|
|
913
|
+
win.destroy()
|
|
914
|
+
|
|
915
|
+
def update_buttons(event):
|
|
916
|
+
has_row = selected_row() is not None
|
|
917
|
+
for button, spec in zip(action_buttons, button_specs):
|
|
918
|
+
button.configure(state="disabled" if spec.data_required and not has_row else "normal")
|
|
919
|
+
|
|
920
|
+
def reveal_action(event):
|
|
921
|
+
top = canvas.canvasy(0)
|
|
922
|
+
y = event.widget.winfo_rooty() - content.winfo_rooty()
|
|
923
|
+
bottom = y + event.widget.winfo_height()
|
|
924
|
+
height = max(1, content.winfo_height())
|
|
925
|
+
if y < top:
|
|
926
|
+
canvas.yview_moveto(y / height)
|
|
927
|
+
elif bottom > top + canvas.winfo_height():
|
|
928
|
+
canvas.yview_moveto((bottom - canvas.winfo_height()) / height)
|
|
929
|
+
|
|
930
|
+
for i, spec in enumerate(button_specs):
|
|
931
|
+
action_row = ttk.Frame(content)
|
|
932
|
+
action_row.pack(fill=tk.X, pady=4)
|
|
933
|
+
action_row.columnconfigure(1, weight=1)
|
|
852
934
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
ttk.Button(frame, text="Continue", command=lambda: self._close(win, 1)).pack(fill=tk.X, pady=2)
|
|
935
|
+
def _button_command(index: int = i) -> None:
|
|
936
|
+
select_action(index)
|
|
856
937
|
|
|
938
|
+
button = ttk.Button(
|
|
939
|
+
action_row,
|
|
940
|
+
text=spec.label,
|
|
941
|
+
command=_button_command,
|
|
942
|
+
state="disabled" if spec.data_required else "normal",
|
|
943
|
+
)
|
|
944
|
+
button.grid(row=0, column=0, sticky="nw", padx=(0, 8))
|
|
945
|
+
button.bind("<FocusIn>", reveal_action)
|
|
946
|
+
description = ttk.Label(action_row, text=spec.prompt, wraplength=360, anchor="w", justify="left")
|
|
947
|
+
description.grid(row=0, column=1, sticky="ew")
|
|
948
|
+
description.bind("<Configure>", lambda event: event.widget.configure(wraplength=max(1, event.width)))
|
|
949
|
+
action_buttons.append(button)
|
|
950
|
+
|
|
951
|
+
if tree is not None:
|
|
952
|
+
tree.bind("<<TreeviewSelect>>", update_buttons)
|
|
953
|
+
|
|
954
|
+
footer = ttk.Frame(frame)
|
|
955
|
+
footer.grid(row=1, column=0, columnspan=2, sticky="ew", pady=(8, 0))
|
|
956
|
+
ttk.Button(footer, text="Cancel", command=lambda: self._close(win, None)).pack(side=tk.RIGHT, padx=4)
|
|
957
|
+
if args.get("include_continue_button"):
|
|
958
|
+
ttk.Button(footer, text="Continue", command=lambda: self._close(win, 0)).pack(side=tk.RIGHT, padx=4)
|
|
959
|
+
|
|
960
|
+
def scroll(event):
|
|
961
|
+
if content.winfo_height() > canvas.winfo_height():
|
|
962
|
+
if event.num in (4, 5):
|
|
963
|
+
units = -1 if event.num == 4 else 1
|
|
964
|
+
else:
|
|
965
|
+
units = -int(event.delta / 120) if abs(event.delta) >= 120 else -event.delta
|
|
966
|
+
canvas.yview_scroll(units, "units")
|
|
967
|
+
return "break"
|
|
968
|
+
|
|
969
|
+
win.bind("<MouseWheel>", scroll)
|
|
970
|
+
win.bind("<Button-4>", scroll)
|
|
971
|
+
win.bind("<Button-5>", scroll)
|
|
972
|
+
win.bind("<Prior>", lambda event: canvas.yview_scroll(-1, "pages"))
|
|
973
|
+
win.bind("<Next>", lambda event: canvas.yview_scroll(1, "pages"))
|
|
857
974
|
win.bind("<Escape>", lambda e: self._close(win, None))
|
|
858
|
-
|
|
975
|
+
win.protocol("WM_DELETE_WINDOW", lambda: self._close(win, None))
|
|
976
|
+
|
|
977
|
+
width = min(640, win.winfo_screenwidth() - 80)
|
|
978
|
+
win.update_idletasks()
|
|
979
|
+
canvas.configure(width=max(1, width - 24 - scrollbar.winfo_reqwidth()))
|
|
980
|
+
win.update_idletasks()
|
|
981
|
+
canvas.itemconfigure(content_window, width=canvas.winfo_reqwidth())
|
|
982
|
+
win.update_idletasks()
|
|
983
|
+
available_height = max(80, win.winfo_screenheight() - 150 - footer.winfo_reqheight())
|
|
984
|
+
canvas.configure(height=min(content.winfo_reqheight(), available_height))
|
|
985
|
+
win.update_idletasks()
|
|
986
|
+
height = min(win.winfo_reqheight(), win.winfo_screenheight() - 100)
|
|
987
|
+
_center_window(win, width, height)
|
|
988
|
+
win.minsize(min(width, 400), min(height, 180))
|
|
859
989
|
root.wait_window(win)
|
|
860
990
|
|
|
861
991
|
def _close(self, win: tk.Toplevel, value: int | None) -> None:
|
|
862
|
-
self.result = {"button": value}
|
|
992
|
+
self.result = {"button": value, "row": None}
|
|
863
993
|
if win.winfo_exists():
|
|
864
994
|
win.destroy()
|
|
865
995
|
|
|
@@ -1056,31 +1186,39 @@ class CredentialsDialog:
|
|
|
1056
1186
|
pady=(0, 8),
|
|
1057
1187
|
)
|
|
1058
1188
|
|
|
1189
|
+
form = ttk.Frame(frame)
|
|
1190
|
+
form.pack(fill=tk.BOTH, expand=True)
|
|
1191
|
+
|
|
1059
1192
|
user_var = tk.StringVar()
|
|
1060
1193
|
pw_var = tk.StringVar()
|
|
1061
1194
|
|
|
1062
|
-
ttk.Label(
|
|
1063
|
-
ttk.Entry(
|
|
1195
|
+
ttk.Label(form, text="Username:").grid(row=0, column=0, sticky="e", padx=4, pady=4)
|
|
1196
|
+
ttk.Entry(form, textvariable=user_var, width=30).grid(row=0, column=1, sticky="ew", pady=4)
|
|
1064
1197
|
|
|
1065
|
-
ttk.Label(
|
|
1066
|
-
ttk.Entry(
|
|
1067
|
-
|
|
1198
|
+
ttk.Label(form, text="Password:").grid(row=1, column=0, sticky="e", padx=4, pady=4)
|
|
1199
|
+
ttk.Entry(form, textvariable=pw_var, show="*", width=30).grid(row=1, column=1, sticky="ew", pady=4)
|
|
1200
|
+
form.columnconfigure(1, weight=1)
|
|
1068
1201
|
|
|
1069
|
-
btn_frame = ttk.Frame(
|
|
1202
|
+
btn_frame = ttk.Frame(form)
|
|
1070
1203
|
btn_frame.grid(row=2, column=0, columnspan=2, pady=8, sticky="e")
|
|
1071
1204
|
ttk.Button(btn_frame, text="OK", command=lambda: self._close(win, user_var.get(), pw_var.get())).pack(
|
|
1072
1205
|
side=tk.LEFT,
|
|
1073
1206
|
padx=4,
|
|
1074
1207
|
)
|
|
1075
|
-
ttk.Button(btn_frame, text="Cancel", command=lambda: self._close(win, "", "")).pack(
|
|
1208
|
+
ttk.Button(btn_frame, text="Cancel", command=lambda: self._close(win, "", "", cancelled=True)).pack(
|
|
1209
|
+
side=tk.LEFT,
|
|
1210
|
+
padx=4,
|
|
1211
|
+
)
|
|
1076
1212
|
win.bind("<Return>", lambda e: self._close(win, user_var.get(), pw_var.get()))
|
|
1077
|
-
win.bind("<Escape>", lambda e: self._close(win, "", ""))
|
|
1213
|
+
win.bind("<Escape>", lambda e: self._close(win, "", "", cancelled=True))
|
|
1214
|
+
|
|
1215
|
+
win.protocol("WM_DELETE_WINDOW", lambda: self._close(win, "", "", cancelled=True))
|
|
1078
1216
|
|
|
1079
1217
|
_center_window(win, 380, 180)
|
|
1080
1218
|
root.wait_window(win)
|
|
1081
1219
|
|
|
1082
|
-
def _close(self, win: tk.Toplevel, username: str, password: str) -> None:
|
|
1083
|
-
self.result = {"username": username, "password": password}
|
|
1220
|
+
def _close(self, win: tk.Toplevel, username: str, password: str, *, cancelled: bool = False) -> None:
|
|
1221
|
+
self.result = {"button": None if cancelled else 1, "username": username, "password": password}
|
|
1084
1222
|
if win.winfo_exists():
|
|
1085
1223
|
win.destroy()
|
|
1086
1224
|
|
|
@@ -1121,56 +1259,88 @@ class ConnectDialog:
|
|
|
1121
1259
|
pady=(0, 8),
|
|
1122
1260
|
)
|
|
1123
1261
|
|
|
1124
|
-
|
|
1125
|
-
server_var = tk.StringVar()
|
|
1126
|
-
db_var = tk.StringVar()
|
|
1127
|
-
user_var = tk.StringVar()
|
|
1128
|
-
|
|
1129
|
-
def _make_row(parent, row, label, widget_factory):
|
|
1130
|
-
ttk.Label(parent, text=label, anchor="e").grid(row=row, column=0, sticky="e", padx=4, pady=4)
|
|
1131
|
-
w = widget_factory(parent)
|
|
1132
|
-
w.grid(row=row, column=1, sticky="ew", pady=4)
|
|
1133
|
-
return w
|
|
1262
|
+
from execsql.gui.base import CONNECTION_ENCODINGS, FILE_DATABASES, connection_result
|
|
1134
1263
|
|
|
1264
|
+
variables = {
|
|
1265
|
+
name: tk.StringVar() for name in ("server", "database", "username", "password", "port", "encoding")
|
|
1266
|
+
}
|
|
1135
1267
|
form = ttk.Frame(frame)
|
|
1136
1268
|
form.pack(fill=tk.BOTH, expand=True)
|
|
1137
1269
|
form.columnconfigure(1, weight=1)
|
|
1138
|
-
|
|
1139
|
-
type_labels = [f"{k} — {v}" for k, v in _DB_TYPE_OPTIONS]
|
|
1140
1270
|
type_values = [k for k, v in _DB_TYPE_OPTIONS]
|
|
1141
|
-
|
|
1271
|
+
ttk.Label(form, text="Database type:").grid(row=0, column=0, sticky="e", padx=4, pady=4)
|
|
1272
|
+
type_combo = ttk.Combobox(form, values=[f"{k} — {v}" for k, v in _DB_TYPE_OPTIONS], state="readonly", width=35)
|
|
1142
1273
|
type_combo.current(0)
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1274
|
+
type_combo.grid(row=0, column=1, sticky="ew", pady=4)
|
|
1275
|
+
rows = {}
|
|
1276
|
+
for row, (name, label) in enumerate(
|
|
1277
|
+
(
|
|
1278
|
+
("server", "Server:"),
|
|
1279
|
+
("database", "Database:"),
|
|
1280
|
+
("username", "Username:"),
|
|
1281
|
+
("password", "Password:"),
|
|
1282
|
+
("port", "Port (optional):"),
|
|
1283
|
+
("encoding", "Encoding (optional):"),
|
|
1284
|
+
),
|
|
1285
|
+
1,
|
|
1286
|
+
):
|
|
1287
|
+
caption = ttk.Label(form, text=label)
|
|
1288
|
+
caption.grid(row=row, column=0, sticky="e", padx=4, pady=4)
|
|
1289
|
+
entry: ttk.Entry
|
|
1290
|
+
if name == "encoding":
|
|
1291
|
+
entry = ttk.Combobox(form, textvariable=variables[name], values=CONNECTION_ENCODINGS, width=35)
|
|
1292
|
+
else:
|
|
1293
|
+
entry = ttk.Entry(form, textvariable=variables[name], width=35, show="*" if name == "password" else "")
|
|
1294
|
+
entry.grid(row=row, column=1, sticky="ew", pady=4)
|
|
1295
|
+
rows[name] = (caption, entry)
|
|
1296
|
+
|
|
1297
|
+
def kind():
|
|
1298
|
+
idx = type_combo.current()
|
|
1299
|
+
return type_values[idx] if idx >= 0 else "p"
|
|
1300
|
+
|
|
1301
|
+
def browse():
|
|
1302
|
+
selected = filedialog.askopenfilename(parent=win, title="Select database file")
|
|
1303
|
+
if selected:
|
|
1304
|
+
variables["database"].set(selected)
|
|
1305
|
+
|
|
1306
|
+
browse_button = ttk.Button(form, text="Browse…", command=browse)
|
|
1307
|
+
browse_button.grid(row=2, column=2, padx=4)
|
|
1308
|
+
|
|
1309
|
+
def update_fields(*_):
|
|
1310
|
+
db_type = kind()
|
|
1311
|
+
file_based = db_type in FILE_DATABASES
|
|
1312
|
+
for name in ("server", "username", "password", "port", "encoding"):
|
|
1313
|
+
visible = not file_based and not (db_type == "d" and name in ("server", "port"))
|
|
1314
|
+
for widget in rows[name]:
|
|
1315
|
+
widget.grid() if visible else widget.grid_remove()
|
|
1316
|
+
rows["database"][0].configure(
|
|
1317
|
+
text="File path:" if file_based else "DSN:" if db_type == "d" else "Database:",
|
|
1318
|
+
)
|
|
1319
|
+
browse_button.grid() if file_based else browse_button.grid_remove()
|
|
1151
1320
|
|
|
1321
|
+
type_combo.bind("<<ComboboxSelected>>", update_fields)
|
|
1322
|
+
update_fields()
|
|
1323
|
+
ttk.Label(frame, text="Blank password: no additional password prompt.").pack(anchor="w", pady=4)
|
|
1324
|
+
error = ttk.Label(frame, text="", wraplength=440)
|
|
1325
|
+
error.pack(anchor="w")
|
|
1152
1326
|
btn_frame = ttk.Frame(frame)
|
|
1153
1327
|
btn_frame.pack(pady=8, anchor="e")
|
|
1154
1328
|
|
|
1155
1329
|
def _on_connect():
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
"
|
|
1161
|
-
|
|
1162
|
-
"database": db,
|
|
1163
|
-
"db_file": db if db_type in ("l", "k", "a") else None,
|
|
1164
|
-
"username": user_var.get().strip() or None,
|
|
1165
|
-
}
|
|
1330
|
+
try:
|
|
1331
|
+
self.result = dict(connection_result(kind(), **{name: var.get() for name, var in variables.items()}))
|
|
1332
|
+
except ValueError as exc:
|
|
1333
|
+
error.configure(text=str(exc))
|
|
1334
|
+
rows["port"][1].focus_set()
|
|
1335
|
+
return
|
|
1166
1336
|
win.destroy()
|
|
1167
1337
|
|
|
1168
1338
|
ttk.Button(btn_frame, text="Connect", command=_on_connect).pack(side=tk.LEFT, padx=4)
|
|
1169
1339
|
ttk.Button(btn_frame, text="Cancel", command=lambda: self._close(win)).pack(side=tk.LEFT, padx=4)
|
|
1170
1340
|
win.bind("<Return>", lambda e: _on_connect())
|
|
1171
1341
|
win.bind("<Escape>", lambda e: self._close(win))
|
|
1172
|
-
|
|
1173
|
-
_center_window(win,
|
|
1342
|
+
win.protocol("WM_DELETE_WINDOW", lambda: self._close(win))
|
|
1343
|
+
_center_window(win, 560, 450)
|
|
1174
1344
|
root.wait_window(win)
|
|
1175
1345
|
|
|
1176
1346
|
def _close(self, win: tk.Toplevel) -> None:
|
|
@@ -1240,7 +1410,20 @@ class ConsoleWindow:
|
|
|
1240
1410
|
)
|
|
1241
1411
|
|
|
1242
1412
|
self._running = True
|
|
1243
|
-
|
|
1413
|
+
self._win.update_idletasks()
|
|
1414
|
+
_center_window(self._win, self._win.winfo_reqwidth(), self._win.winfo_reqheight())
|
|
1415
|
+
|
|
1416
|
+
def resize(self, width: int, height: int) -> None:
|
|
1417
|
+
"""Apply requested text dimensions and let Tk fit the window around them.
|
|
1418
|
+
|
|
1419
|
+
Clearing the explicit pixel size also handles windows resized manually.
|
|
1420
|
+
The existing position and hidden/visible state are preserved.
|
|
1421
|
+
"""
|
|
1422
|
+
self._width, self._height = width, height
|
|
1423
|
+
if self._text is not None and self._win is not None:
|
|
1424
|
+
self._text.configure(width=width, height=height)
|
|
1425
|
+
self._win.geometry("")
|
|
1426
|
+
self._win.update_idletasks()
|
|
1244
1427
|
|
|
1245
1428
|
def _on_close(self) -> None:
|
|
1246
1429
|
self._running = False
|
|
@@ -1333,15 +1516,24 @@ class TkinterBackend(GuiBackend):
|
|
|
1333
1516
|
# ------------------------------------------------------------------
|
|
1334
1517
|
|
|
1335
1518
|
def console_on(self) -> None:
|
|
1519
|
+
from execsql.utils.gui import gui_console_height, gui_console_width
|
|
1520
|
+
|
|
1336
1521
|
root = self._root_or_raise()
|
|
1522
|
+
width, height = gui_console_width(), gui_console_height()
|
|
1337
1523
|
if self._console is None:
|
|
1338
|
-
self._console = ConsoleWindow(root)
|
|
1524
|
+
self._console = ConsoleWindow(root, width=width, height=height)
|
|
1525
|
+
else:
|
|
1526
|
+
self._console.resize(width, height)
|
|
1339
1527
|
self._console.start()
|
|
1340
1528
|
import execsql.state as _state
|
|
1341
1529
|
|
|
1342
1530
|
_state.output.redir_stdout(self._console.write)
|
|
1343
1531
|
_state.output.redir_stderr(self._console.write)
|
|
1344
1532
|
|
|
1533
|
+
def console_resize(self, width: int, height: int) -> None:
|
|
1534
|
+
if self._console is not None:
|
|
1535
|
+
self._console.resize(width, height)
|
|
1536
|
+
|
|
1345
1537
|
def console_off(self) -> None:
|
|
1346
1538
|
if self._console:
|
|
1347
1539
|
self._console.stop()
|
|
@@ -1454,15 +1646,14 @@ class TkinterBackend(GuiBackend):
|
|
|
1454
1646
|
|
|
1455
1647
|
|
|
1456
1648
|
# ---------------------------------------------------------------------------
|
|
1457
|
-
# _TkinterSyncQueue — synchronous gui_manager_queue replacement
|
|
1649
|
+
# _TkinterSyncQueue — synchronous gui_manager_queue replacement
|
|
1458
1650
|
# ---------------------------------------------------------------------------
|
|
1459
1651
|
|
|
1460
1652
|
|
|
1461
1653
|
class _TkinterSyncQueue:
|
|
1462
1654
|
"""Drop-in replacement for ``_state.gui_manager_queue`` on the Tkinter path.
|
|
1463
1655
|
|
|
1464
|
-
|
|
1465
|
-
thread, ``put()`` dispatches the dialog synchronously in the calling
|
|
1656
|
+
``put()`` dispatches native Tk dialogs synchronously in the calling
|
|
1466
1657
|
(main) thread. After ``put()`` returns, the result is already on
|
|
1467
1658
|
``spec.return_queue`` so the calling metacommand's ``get()`` unblocks
|
|
1468
1659
|
immediately.
|
|
@@ -1476,24 +1667,6 @@ class _TkinterSyncQueue:
|
|
|
1476
1667
|
def __init__(self, backend: TkinterBackend) -> None:
|
|
1477
1668
|
self._backend = backend
|
|
1478
1669
|
|
|
1479
|
-
# GUI types for which a None/cancelled result means the user wants to exit.
|
|
1480
|
-
# File/directory/credentials/connect dialogs are intentionally excluded
|
|
1481
|
-
# because cancelling those just means "no selection" rather than "quit".
|
|
1482
|
-
_EXIT_ON_CANCEL = frozenset(
|
|
1483
|
-
[
|
|
1484
|
-
"halt",
|
|
1485
|
-
"msg",
|
|
1486
|
-
"pause",
|
|
1487
|
-
"display",
|
|
1488
|
-
"entry",
|
|
1489
|
-
"compare",
|
|
1490
|
-
"selectrows",
|
|
1491
|
-
"selectsub",
|
|
1492
|
-
"action",
|
|
1493
|
-
"map",
|
|
1494
|
-
],
|
|
1495
|
-
)
|
|
1496
|
-
|
|
1497
1670
|
def put(self, spec: Any, block: bool = True, timeout: Any = None) -> None:
|
|
1498
1671
|
if spec is None:
|
|
1499
1672
|
return
|
|
@@ -1512,8 +1685,6 @@ class _TkinterSyncQueue:
|
|
|
1512
1685
|
pass # Tk event loop may be torn down.
|
|
1513
1686
|
except Exception as exc:
|
|
1514
1687
|
result = {"error": str(exc), "button": None}
|
|
1515
|
-
if result is not None and spec.gui_type in self._EXIT_ON_CANCEL and result.get("button") is None:
|
|
1516
|
-
raise SystemExit(2)
|
|
1517
1688
|
spec.return_queue.put(result if result is not None else {})
|
|
1518
1689
|
|
|
1519
1690
|
def get_nowait(self) -> Any:
|