v1.8.57: auto-size result columns + working horizontal scrollbar

- Measure column widths from header and data (sample up to 100 rows)
- Clamp width: min 60px, max 400px per column
- Set stretch=False so columns don't compress to fit viewport
- Horizontal scrollbar now works when total column width exceeds view

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
chrome-storm-c442
2026-02-25 04:53:32 -05:00
parent 6f0bfe39f1
commit 4a6464ede9
3 changed files with 23 additions and 4 deletions

View File

@@ -650,7 +650,7 @@ class QueryTab(ctk.CTkFrame):
# ── Results Treeview population ────────────────────────────────
def _populate_results(self, columns: list[str], rows: list[list]):
"""Clear and populate the results Treeview."""
"""Clear and populate the results Treeview with auto-sized columns."""
self._results_tree.delete(*self._results_tree.get_children())
if not columns:
@@ -658,9 +658,28 @@ class QueryTab(ctk.CTkFrame):
return
self._results_tree["columns"] = columns
for col in columns:
# Measure optimal width per column: max(header, data) + padding
import tkinter.font as tkfont
heading_font = tkfont.Font(family="Segoe UI", size=10, weight="bold")
data_font = tkfont.Font(family="Consolas", size=11)
col_widths = []
for i, col in enumerate(columns):
max_w = heading_font.measure(col) + 20 # header + sort arrow space
# Sample up to 100 rows to avoid slow measuring on huge result sets
for row in rows[:100]:
val = str(row[i]) if i < len(row) and row[i] is not None else "NULL"
w = data_font.measure(val) + 16 # data + padding
if w > max_w:
max_w = w
# Clamp: min 60px, max 400px
col_widths.append(max(60, min(400, max_w)))
for col, width in zip(columns, col_widths):
self._results_tree.heading(col, text=col, anchor="w")
self._results_tree.column(col, width=120, minwidth=60, anchor="w")
self._results_tree.column(col, width=width, minwidth=60,
anchor="w", stretch=False)
for row in rows:
display = [str(v) if v is not None else "NULL" for v in row]

Binary file not shown.

View File

@@ -1,6 +1,6 @@
"""Version info for ServerManager."""
__version__ = "1.8.56"
__version__ = "1.8.57"
__app_name__ = "ServerManager"
__author__ = "aibot777"
__description__ = "Desktop GUI for managing remote servers"