136 lines
5.4 KiB
Python
136 lines
5.4 KiB
Python
# FlightMonitor/gui/panels/function_notebook_panel.py
|
|
"""
|
|
Panel managing the function-related notebooks (Live, Historical Download, Playback)
|
|
and their associated controls.
|
|
"""
|
|
import tkinter as tk
|
|
from tkinter import ttk
|
|
from typing import Dict, Any, Optional
|
|
|
|
from ...utils.logger import get_logger
|
|
|
|
module_logger = get_logger(__name__)
|
|
|
|
class FunctionNotebookPanel:
|
|
"""
|
|
Manages the function-selection notebook (Live, Historical Download, Playback).
|
|
"""
|
|
|
|
def __init__(self, parent_frame: ttk.Frame, controller: Any):
|
|
"""
|
|
Initializes the FunctionNotebookPanel.
|
|
|
|
Args:
|
|
parent_frame: The parent ttk.Frame where this notebook will be placed.
|
|
controller: The application controller instance to delegate actions.
|
|
"""
|
|
self.parent_frame = parent_frame
|
|
self.controller = controller
|
|
|
|
# --- UI Elements ---
|
|
self.function_notebook: Optional[ttk.Notebook] = None
|
|
self.start_live_button: Optional[ttk.Button] = None
|
|
self.stop_live_button: Optional[ttk.Button] = None
|
|
|
|
# Placeholder for future controls
|
|
self.start_download_button: Optional[ttk.Button] = None
|
|
|
|
self._build_ui()
|
|
module_logger.debug("FunctionNotebookPanel initialized.")
|
|
|
|
def _build_ui(self):
|
|
"""
|
|
Builds the main notebook structure and all its tabs and controls.
|
|
"""
|
|
self.function_notebook = ttk.Notebook(self.parent_frame)
|
|
self.function_notebook.pack(fill=tk.BOTH, expand=True, padx=2, pady=2)
|
|
|
|
# --- Live Tab ---
|
|
live_tab_frame = ttk.Frame(self.function_notebook, padding=10)
|
|
self.function_notebook.add(live_tab_frame, text="Live Monitor")
|
|
|
|
self.start_live_button = ttk.Button(
|
|
live_tab_frame, text="Start Live Monitoring", command=self._on_start_live_monitoring
|
|
)
|
|
self.start_live_button.pack(side=tk.LEFT, padx=5, pady=5)
|
|
|
|
self.stop_live_button = ttk.Button(
|
|
live_tab_frame,
|
|
text="Stop Live Monitoring",
|
|
command=self._on_stop_live_monitoring,
|
|
state=tk.DISABLED,
|
|
)
|
|
self.stop_live_button.pack(side=tk.LEFT, padx=5, pady=5)
|
|
|
|
# --- Historical Download Tab ---
|
|
download_tab_frame = ttk.Frame(self.function_notebook, padding=10)
|
|
self.function_notebook.add(download_tab_frame, text="Historical Download")
|
|
|
|
ttk.Label(
|
|
download_tab_frame,
|
|
text="Historical download controls will be here.",
|
|
font=("Arial", 10, "italic")
|
|
).pack(expand=True)
|
|
|
|
# --- Playback Tab ---
|
|
playback_tab_frame = ttk.Frame(self.function_notebook, padding=10)
|
|
self.function_notebook.add(playback_tab_frame, text="Playback")
|
|
|
|
ttk.Label(
|
|
playback_tab_frame,
|
|
text="Playback controls will be here.",
|
|
font=("Arial", 10, "italic")
|
|
).pack(expand=True)
|
|
|
|
self.function_notebook.bind("<<NotebookTabChanged>>", self._on_tab_change)
|
|
|
|
def _on_start_live_monitoring(self):
|
|
"""Callback for the 'Start Live Monitoring' button."""
|
|
if not self.controller:
|
|
module_logger.error("Controller not available to start live monitoring.")
|
|
return
|
|
|
|
module_logger.info("FunctionNotebookPanel: Start Live Monitoring clicked.")
|
|
# The controller will fetch the BBox from AreaManagementPanel via MainWindow
|
|
self.controller.start_live_monitoring()
|
|
|
|
def _on_stop_live_monitoring(self):
|
|
"""Callback for the 'Stop Live Monitoring' button."""
|
|
if not self.controller:
|
|
module_logger.error("Controller not available to stop live monitoring.")
|
|
return
|
|
|
|
module_logger.info("FunctionNotebookPanel: Stop Live Monitoring clicked.")
|
|
self.controller.stop_live_monitoring()
|
|
|
|
def _on_tab_change(self, event: Optional[tk.Event] = None):
|
|
"""Handles changes in the selected function tab."""
|
|
if not self.function_notebook: return
|
|
try:
|
|
tab_text = self.function_notebook.tab(self.function_notebook.index("current"), "text")
|
|
module_logger.info(f"FunctionNotebookPanel: Switched to tab: {tab_text}")
|
|
|
|
# Delegate placeholder updates to MainWindow via controller
|
|
if self.controller and hasattr(self.controller, "on_function_tab_changed"):
|
|
self.controller.on_function_tab_changed(tab_text)
|
|
|
|
except (tk.TclError, IndexError) as e:
|
|
module_logger.warning(f"Error getting selected tab info: {e}")
|
|
|
|
def set_monitoring_button_states(self, is_monitoring_active: bool):
|
|
"""
|
|
Sets the state of the Start/Stop buttons for the Live tab.
|
|
"""
|
|
if self.start_live_button and self.start_live_button.winfo_exists():
|
|
self.start_live_button.config(state=tk.DISABLED if is_monitoring_active else tk.NORMAL)
|
|
|
|
if self.stop_live_button and self.stop_live_button.winfo_exists():
|
|
self.stop_live_button.config(state=tk.NORMAL if is_monitoring_active else tk.DISABLED)
|
|
|
|
def get_active_tab_text(self) -> Optional[str]:
|
|
"""Returns the text of the currently active tab."""
|
|
if not self.function_notebook: return None
|
|
try:
|
|
return self.function_notebook.tab(self.function_notebook.index("current"), "text")
|
|
except (tk.TclError, IndexError):
|
|
return None |