feat: Enhance export functionality with DataFrame support and UI improvements
This commit is contained in:
@@ -5,6 +5,7 @@ Provides a GUI interface for exporting data and graphs to various formats.
|
||||
"""
|
||||
|
||||
import tkinter as tk
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from tkinter import filedialog, messagebox, ttk
|
||||
|
||||
@@ -14,9 +15,15 @@ from export_manager import ExportManager
|
||||
class ExportWindow:
|
||||
"""Export window for data and graph export functionality."""
|
||||
|
||||
def __init__(self, parent: tk.Tk, export_manager: ExportManager) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
parent: tk.Tk,
|
||||
export_manager: ExportManager,
|
||||
get_current_filtered_df: Callable[[], object] | None = None,
|
||||
) -> None:
|
||||
self.parent = parent
|
||||
self.export_manager = export_manager
|
||||
self._get_current_filtered_df = get_current_filtered_df
|
||||
|
||||
# Create the export window
|
||||
self.window = tk.Toplevel(parent)
|
||||
@@ -113,6 +120,21 @@ Medicines: {", ".join(export_info["medicines"])}"""
|
||||
)
|
||||
graph_check.pack(anchor=tk.W, pady=(0, 10))
|
||||
|
||||
# Export scope option
|
||||
self.scope_var = tk.StringVar(value="all")
|
||||
scope_frame = ttk.Frame(options_frame)
|
||||
scope_frame.pack(fill=tk.X, pady=(0, 10))
|
||||
ttk.Label(scope_frame, text="Scope:").pack(side=tk.LEFT)
|
||||
ttk.Radiobutton(
|
||||
scope_frame, text="All data", variable=self.scope_var, value="all"
|
||||
).pack(side=tk.LEFT, padx=10)
|
||||
ttk.Radiobutton(
|
||||
scope_frame,
|
||||
text="Current (filtered) view",
|
||||
variable=self.scope_var,
|
||||
value="filtered",
|
||||
).pack(side=tk.LEFT)
|
||||
|
||||
# Format selection
|
||||
format_label = ttk.Label(options_frame, text="Export Format:")
|
||||
format_label.pack(anchor=tk.W)
|
||||
@@ -182,17 +204,27 @@ Medicines: {", ".join(export_info["medicines"])}"""
|
||||
if not filename:
|
||||
return
|
||||
|
||||
# Determine scope DataFrame (if requested and available)
|
||||
scoped_df = None
|
||||
if self.scope_var.get() == "filtered" and self._get_current_filtered_df:
|
||||
try:
|
||||
scoped_df = self._get_current_filtered_df()
|
||||
except Exception:
|
||||
scoped_df = None
|
||||
|
||||
# Perform export based on selected format
|
||||
success = False
|
||||
try:
|
||||
if selected_format == "JSON":
|
||||
success = self.export_manager.export_data_to_json(filename)
|
||||
success = self.export_manager.export_data_to_json(
|
||||
filename, df=scoped_df
|
||||
)
|
||||
elif selected_format == "XML":
|
||||
success = self.export_manager.export_data_to_xml(filename)
|
||||
success = self.export_manager.export_data_to_xml(filename, df=scoped_df)
|
||||
elif selected_format == "PDF":
|
||||
include_graph = self.include_graph_var.get()
|
||||
success = self.export_manager.export_to_pdf(
|
||||
filename, include_graph=include_graph
|
||||
filename, include_graph=include_graph, df=scoped_df
|
||||
)
|
||||
|
||||
if success:
|
||||
|
||||
Reference in New Issue
Block a user