feat: Enhance export functionality with DataFrame support and UI improvements

This commit is contained in:
William Valentin
2025-08-08 12:26:21 -07:00
parent b039447a1f
commit f5c9b79a33
6 changed files with 253 additions and 17 deletions
+62
View File
@@ -12,6 +12,7 @@ from PIL import Image, ImageTk
from medicine_manager import MedicineManager
from pathology_manager import PathologyManager
from preferences import get_pref, save_preferences, set_pref
from tooltip_system import TooltipManager
@@ -410,6 +411,28 @@ class UIManager:
for col, width, anchor in col_settings:
tree.column(col, width=width, anchor=anchor)
# Apply saved column widths if available
try:
saved_widths = get_pref("column_widths", {}) or {}
if isinstance(saved_widths, dict):
for col in tree["columns"]:
w = saved_widths.get(col)
if isinstance(w, int) and w > 0:
tree.column(col, width=w)
except Exception:
pass
# Initialize last sort from preferences
try:
last_sort = get_pref("last_sort", {}) or {}
col = last_sort.get("column")
asc = last_sort.get("ascending", True)
if col in tree["columns"]:
self._last_sorted_column = col
self._last_sorted_ascending = bool(asc)
except Exception:
pass
tree.pack(side="left", fill="both", expand=True)
# Add scrollbars with optimized scroll handling
@@ -422,6 +445,9 @@ class UIManager:
# Optimize tree scrolling performance
self._optimize_tree_scrolling(tree)
# Install debounced save of column widths
self._install_column_width_persistence(tree)
return {"frame": table_frame, "tree": tree}
# ------------------------------------------------------------------
@@ -462,6 +488,13 @@ class UIManager:
# Re-apply alternating row tags after sort
self.normalize_tree_stripes(tree)
# Persist last sort
try:
set_pref("last_sort", {"column": column, "ascending": ascending})
save_preferences()
except Exception:
pass
def _sort_tree_column_direction(
self, tree: ttk.Treeview, column: str, ascending: bool
) -> None:
@@ -572,6 +605,35 @@ class UIManager:
# Ensure alternating stripes are normalized after updates
self.normalize_tree_stripes(tree)
# --- Column width persistence helpers ---
def _install_column_width_persistence(self, tree: ttk.Treeview) -> None:
import contextlib
self._col_width_save_after_id = None
def _debounced_save(*_args):
if getattr(self, "_col_width_save_after_id", None):
with contextlib.suppress(Exception):
self.root.after_cancel(self._col_width_save_after_id)
self._col_width_save_after_id = self.root.after(600, _save_now)
def _save_now():
widths = {}
for col in tree["columns"]:
try:
widths[col] = int(tree.column(col, option="width"))
except Exception:
continue
try:
set_pref("column_widths", widths)
save_preferences()
except Exception:
pass
self._col_width_save_after_id = None
tree.bind("<ButtonRelease-1>", _debounced_save, add="+")
tree.bind("<Configure>", _debounced_save, add="+")
def normalize_tree_stripes(self, tree: ttk.Treeview) -> None:
"""Normalize alternating row tags based on current visual order.