SXXXXXXX_RadarDataReader/radar_data_reader/gui/main_window.py
VALLONGOL 0399e98b79 Chore: Stop tracking files based on .gitignore update.
Untracked files matching the following rules:
- Rule "!.vscode/launch.json": 1 file
2025-06-18 11:18:36 +02:00

98 lines
3.4 KiB
Python

"""
Main View for the Radar Data Reader application.
"""
import tkinter as tk
from tkinter import scrolledtext, filedialog, ttk
from pathlib import Path
from typing import Dict, Any
from ..utils import logger
from ..core.data_structures import DataBatch
log = logger.get_logger(__name__)
class MainWindow(tk.Frame):
"""The main application window (View)."""
def __init__(self, master: tk.Tk, controller, logging_config: Dict[str, Any]):
super().__init__(master)
self.master = master
self.controller = controller
self._init_vars()
self.pack(fill=tk.BOTH, expand=True)
self.master.title("Radar Data Reader")
self.master.geometry("800x700")
self._create_widgets()
self._setup_gui_logging(logging_config)
self.master.protocol("WM_DELETE_WINDOW", self.on_close)
log.info("Main window View initialized.")
def _init_vars(self):
self.filepath_var = tk.StringVar()
self.batch_id_var = tk.StringVar(value="N/A")
self.timetag_var = tk.StringVar(value="N/A")
self.progress_var = tk.DoubleVar(value=0)
self.total_blocks_for_progress = 0
self.batches_processed_count = 0
def _create_widgets(self):
# ... (identico a prima) ...
pass
def _setup_gui_logging(self, logging_config):
logger.add_tkinter_handler(self.log_widget, self.master, logging_config)
def set_filepath(self, path: str):
self.filepath_var.set(path)
def get_filepath(self) -> str:
return self.filepath_var.get()
def ask_open_filename(self, current_path: str) -> str:
initial_dir = Path(current_path).parent if current_path and Path(current_path).exists() else Path.cwd()
return filedialog.askopenfilename(initialdir=initial_dir, filetypes=[("Radar Output", "*.out"), ("All files", "*.*")])
def update_ui_for_processing(self, is_processing: bool):
state = tk.DISABLED if is_processing else tk.NORMAL
self.browse_button.config(state=state)
self.process_button.config(state=state)
self.stop_button.config(state=tk.NORMAL if is_processing else tk.DISABLED)
if not is_processing:
self.progress_var.set(0)
self.batch_id_var.set("Done")
else:
self.batches_processed_count = 0
def set_total_progress(self, total_blocks: int):
"""Sets the total number of blocks for the progress bar calculation."""
self.total_blocks_for_progress = total_blocks
def update_progress(self, batch: DataBatch):
"""Updates the GUI with progress info for a new batch."""
self.batches_processed_count += 1
self.batch_id_var.set(f"{self.batches_processed_count}")
self.timetag_var.set(f"{batch.header.header_data.signal_descr.ttag}")
if self.total_blocks_for_progress > 0:
# A better progress estimate based on header counter
blocks_done_count = batch.header.header_sw.header_sw_part1.counter
progress = (blocks_done_count / self.total_blocks_for_progress) * 100
self.progress_var.set(progress)
def on_browse_click(self):
self.controller.select_file()
def on_process_click(self):
self.controller.start_processing()
def on_stop_click(self):
self.controller.stop_processing()
def on_close(self):
self.controller.shutdown()
self.master.destroy()