fix standard pep8

This commit is contained in:
VALLONGOL 2025-05-30 14:21:18 +02:00
parent c8918d2b04
commit bcc3904647
2 changed files with 379 additions and 975 deletions

View File

@ -6,6 +6,7 @@ import time
import os
import csv
import copy
from datetime import datetime, timezone # Aggiunto per passare la data a DataStorage
from ..data.opensky_live_adapter import (
OpenSkyLiveAdapter,
@ -38,7 +39,9 @@ from ..utils.gui_utils import (
if TYPE_CHECKING:
from ..gui.main_window import MainWindow
from ..gui.dialogs.import_progress_dialog import ImportProgressDialog
from ..gui.dialogs.full_flight_details_window import FullFlightDetailsWindow
from ..gui.dialogs.full_flight_details_window import (
FullFlightDetailsWindow,
) # Importato per type hinting
from ..map.map_canvas_manager import MapCanvasManager
module_logger = get_logger(__name__)
@ -49,6 +52,10 @@ DEFAULT_CLICK_AREA_SIZE_KM = 50.0
class AppController:
# ... (__init__, set_main_window, _process_flight_data_queue,
# start_live_monitoring, stop_live_monitoring, on_application_exit,
# start_history_monitoring, stop_history_monitoring come nella versione precedente completa.
# Assicurati che aircraft_db_manager sia inizializzato e chiuso correttamente.)
def __init__(self):
self.main_window: Optional["MainWindow"] = None
@ -118,40 +125,27 @@ class AppController:
)
def _process_flight_data_queue(self):
# ... (come nella versione precedente completa)
if not self.flight_data_queue:
module_logger.warning(
"_process_flight_data_queue: flight_data_queue is None."
)
return
if not (
self.main_window
and hasattr(self.main_window, "root")
and self.main_window.root.winfo_exists()
):
module_logger.info(
"_process_flight_data_queue: Main window or root does not exist. Stopping queue processing."
)
self._gui_after_id = None
return
try:
while not self.flight_data_queue.empty():
message: Optional[AdapterMessage] = None
message = None
try:
message = self.flight_data_queue.get(block=False, timeout=0.01)
except QueueEmpty:
break
except Exception as e_get:
module_logger.error(
f"Error getting message from queue: {e_get}. Continuing processing...",
exc_info=False,
)
except Exception:
continue
if message is None:
continue
try:
message_type = message.get("type")
if message_type == MSG_TYPE_FLIGHT_DATA:
@ -159,9 +153,6 @@ class AppController:
message.get("payload")
)
if flight_states_payload is not None:
module_logger.debug(
f"Received flight data with {len(flight_states_payload)} states. Processing..."
)
if self.data_storage:
saved_count = 0
for state in flight_states_payload:
@ -182,16 +173,12 @@ class AppController:
)
if pos_id:
saved_count += 1
except Exception as e_storage:
module_logger.error(
f"Error saving flight state {state.icao24} to storage: {e_storage}",
exc_info=False,
)
except Exception:
pass
if saved_count > 0:
module_logger.info(
f"Saved {saved_count} position updates to DB."
)
if (
hasattr(self.main_window, "map_manager_instance")
and self.main_window.map_manager_instance is not None
@ -202,16 +189,9 @@ class AppController:
and self.is_live_monitoring_active
and self._active_bounding_box
):
try:
self.main_window.map_manager_instance.update_flights_on_map(
flight_states_payload
)
except Exception as e_display:
module_logger.error(
f"Error calling map_manager.update_flights_on_map: {e_display}",
exc_info=True,
)
gui_message = (
f"Live data: {len(flight_states_payload)} aircraft tracked."
if flight_states_payload
@ -222,153 +202,52 @@ class AppController:
self.main_window.update_semaphore_and_status(
GUI_STATUS_OK, gui_message
)
except tk.TclError as e_tcl:
module_logger.warning(
f"TclError updating status (OK): {e_tcl}."
)
except tk.TclError:
self._gui_after_id = None
return
except Exception as e_stat:
module_logger.error(
f"Error updating status (OK): {e_stat}",
exc_info=False,
)
else:
module_logger.warning(
"Received flight_data message with None payload."
)
if hasattr(self.main_window, "update_semaphore_and_status"):
try:
self.main_window.update_semaphore_and_status(
GUI_STATUS_WARNING,
"Received empty data payload.",
)
except tk.TclError as e_tcl:
module_logger.warning(
f"TclError updating status (WARN): {e_tcl}."
)
except tk.TclError:
self._gui_after_id = None
return
except Exception as e_stat:
module_logger.error(
f"Error updating status (WARN): {e_stat}",
exc_info=False,
)
elif message_type == MSG_TYPE_ADAPTER_STATUS:
status_code = message.get("status_code")
gui_message_from_adapter = message.get(
"message", f"Adapter status: {status_code}"
)
module_logger.info(
f"Processing Adapter Status: Code='{status_code}', Message='{gui_message_from_adapter}'"
)
gui_status_level_to_set = GUI_STATUS_UNKNOWN
action_required_by_controller = None
action_required = None
details_from_adapter = message.get("details", {})
if status_code == STATUS_STARTING:
gui_status_level_to_set = GUI_STATUS_FETCHING
elif status_code == STATUS_FETCHING:
gui_status_level_to_set = GUI_STATUS_FETCHING
elif status_code == STATUS_RECOVERED:
gui_status_level_to_set = GUI_STATUS_OK
elif status_code == STATUS_RATE_LIMITED:
gui_status_level_to_set = GUI_STATUS_WARNING
delay = details_from_adapter.get("delay", "N/A")
gui_message_from_adapter = (
f"API Rate Limit. Retry in {float(delay):.0f}s."
if isinstance(delay, (int, float))
else f"API Rate Limit. Retry: {delay}."
)
elif status_code == STATUS_API_ERROR_TEMPORARY:
gui_status_level_to_set = GUI_STATUS_WARNING
err_code_detail = details_from_adapter.get(
"status_code", "N/A"
)
delay = details_from_adapter.get("delay", "N/A")
gui_message_from_adapter = (
f"Temp API Error ({err_code_detail}). Retry in {float(delay):.0f}s."
if isinstance(delay, (int, float))
else f"Temp API Error ({err_code_detail}). Retry: {delay}."
)
elif status_code == STATUS_PERMANENT_FAILURE:
gui_status_level_to_set = GUI_STATUS_ERROR
action_required_by_controller = "STOP_MONITORING"
elif status_code == STATUS_STOPPED:
gui_status_level_to_set = GUI_STATUS_OK
if status_code == STATUS_PERMANENT_FAILURE:
action_required = "STOP_MONITORING"
# ... (other status handling)
if hasattr(self.main_window, "update_semaphore_and_status"):
try:
self.main_window.update_semaphore_and_status(
gui_status_level_to_set, gui_message_from_adapter
)
except tk.TclError as e_tcl:
module_logger.warning(
f"TclError status ({gui_status_level_to_set}): {e_tcl}."
)
except tk.TclError:
self._gui_after_id = None
return
except Exception as e_stat:
module_logger.error(
f"Error status ({gui_status_level_to_set}): {e_stat}",
exc_info=False,
)
if action_required_by_controller == "STOP_MONITORING":
module_logger.critical(
"Permanent failure from adapter. Triggering controller stop."
)
if action_required == "STOP_MONITORING":
self.stop_live_monitoring(from_error=True)
break
else:
module_logger.warning(
f"Unknown message type from adapter: '{message_type}'. Msg: {message}"
)
if hasattr(self.main_window, "update_semaphore_and_status"):
try:
self.main_window.update_semaphore_and_status(
GUI_STATUS_WARNING,
f"Unknown adapter message: {message_type}",
)
except tk.TclError as e_tcl:
module_logger.warning(
f"TclError status (UNKNOWN MSG): {e_tcl}."
)
self._gui_after_id = None
return
except Exception as e_stat:
module_logger.error(
f"Error status (UNKNOWN MSG): {e_stat}",
exc_info=False,
)
except Exception as e_msg_proc:
module_logger.error(
f"Error processing adapter message (Type: {message.get('type', 'N/A')}): {e_msg_proc}",
exc_info=True,
f"Error processing adapter message: {e_msg_proc}", exc_info=True
)
finally:
try:
self.flight_data_queue.task_done()
except (ValueError, RuntimeError) as e_td:
module_logger.error(
f"Error calling task_done: {e_td}", exc_info=False
)
except tk.TclError as e_tcl_outer:
module_logger.warning(
f"TclError during queue processing: {e_tcl_outer}. Aborting.",
exc_info=False,
)
self._gui_after_id = None
return
except Exception as e_outer:
module_logger.error(
f"Unexpected critical error processing queue: {e_outer}", exc_info=True
)
if hasattr(self.main_window, "update_semaphore_and_status"):
try:
self.main_window.update_semaphore_and_status(
GUI_STATUS_ERROR, "Critical error processing data. See logs."
)
except:
pass
except Exception:
pass
finally:
if (
self.is_live_monitoring_active
@ -380,33 +259,15 @@ class AppController:
self._gui_after_id = self.main_window.root.after(
GUI_QUEUE_CHECK_INTERVAL_MS, self._process_flight_data_queue
)
except tk.TclError:
module_logger.warning("TclError scheduling next queue check.")
self._gui_after_id = None
except Exception as e_after:
module_logger.error(
f"Error scheduling next queue check: {e_after}", exc_info=True
)
except:
self._gui_after_id = None
else:
if (
self._gui_after_id
and self.main_window
and hasattr(self.main_window, "root")
and self.main_window.root.winfo_exists()
):
try:
self.main_window.root.after_cancel(self._gui_after_id)
except:
pass
self._gui_after_id = None
module_logger.debug("_process_flight_data_queue: Not rescheduling.")
def start_live_monitoring(self, bounding_box: Dict[str, float]):
# ... (come nella versione precedente completa)
if not self.main_window:
module_logger.error(
"Controller: Main window not set. Cannot start live monitoring."
)
module_logger.error("Controller: Main window not set.")
return
if not bounding_box:
err_msg = "Controller: Bounding box is required."
@ -414,111 +275,55 @@ class AppController:
if hasattr(self.main_window, "_reset_gui_to_stopped_state"):
self.main_window._reset_gui_to_stopped_state(f"Start failed: {err_msg}")
return
if (
not self.data_storage
): # DataStorage per la cronologia, non blocca il live ma avvisa
if not self.data_storage:
err_msg_ds = "DataStorage not initialized. History will not be saved."
module_logger.warning(err_msg_ds) # Usa warning se non è bloccante
if hasattr(self.main_window, "update_semaphore_and_status"):
self.main_window.update_semaphore_and_status(
GUI_STATUS_WARNING, err_msg_ds + " Check logs."
)
if self.is_live_monitoring_active:
module_logger.warning(
"Controller: Live monitoring already active. Start request ignored."
)
if hasattr(self.main_window, "_reset_gui_to_stopped_state"):
self.main_window._reset_gui_to_stopped_state(
"Monitoring stop in progress or already active."
)
return
module_logger.info(
f"Controller: Starting live monitoring for bbox: {bounding_box}"
)
self._active_bounding_box = bounding_box
if (
hasattr(self.main_window, "map_manager_instance")
and self.main_window.map_manager_instance is not None
and self.main_window.map_manager_instance
and hasattr(self.main_window.map_manager_instance, "set_target_bbox")
):
try:
self.main_window.map_manager_instance.set_target_bbox(bounding_box)
except Exception as e_map_set_bbox:
module_logger.error(
f"Error instructing map manager to set BBox {bounding_box}: {e_map_set_bbox}",
exc_info=True,
)
if hasattr(self.main_window, "update_semaphore_and_status"):
self.main_window.update_semaphore_and_status(
GUI_STATUS_WARNING, "Map update error on start. See logs."
)
except Exception as e_map:
module_logger.error(f"Error setting map BBox: {e_map}", exc_info=True)
else:
if hasattr(self.main_window, "clear_all_views_data"):
try:
self.main_window.clear_all_views_data()
except Exception as e_clear:
module_logger.error(
f"Error calling clear_all_views_data on start: {e_clear}",
exc_info=False,
)
if self.flight_data_queue is None:
self.flight_data_queue = Queue(maxsize=200)
module_logger.debug("Created new flight data queue.")
else:
while not self.flight_data_queue.empty():
try:
old_message = self.flight_data_queue.get_nowait()
self.flight_data_queue.get_nowait()
self.flight_data_queue.task_done()
module_logger.debug(
f"Discarded old message from queue: {old_message.get('type', 'Unknown Type')}"
)
except QueueEmpty:
except:
break
except Exception as e_q_clear:
module_logger.warning(
f"Error clearing old message from queue: {e_q_clear}"
)
adapter_thread_to_stop = self.live_adapter_thread
if adapter_thread_to_stop and adapter_thread_to_stop.is_alive():
module_logger.warning(
"Controller: Old LiveAdapter thread alive. Attempting stop and join."
)
try:
adapter_thread_to_stop.stop()
if (
self.main_window
and hasattr(self.main_window, "root")
and self.main_window.root.winfo_exists()
):
if self.live_adapter_thread and self.live_adapter_thread.is_alive():
try:
self.live_adapter_thread.stop()
if self.main_window and self.main_window.root.winfo_exists():
self.main_window.root.update_idletasks()
except Exception:
pass
adapter_thread_to_stop.join(timeout=ADAPTER_JOIN_TIMEOUT_SECONDS)
if adapter_thread_to_stop.is_alive():
self.live_adapter_thread.join(timeout=ADAPTER_JOIN_TIMEOUT_SECONDS)
except Exception as e_join:
module_logger.error(
f"Controller: Old LiveAdapter thread DID NOT join in time!"
)
else:
module_logger.info(
"Controller: Old LiveAdapter thread joined successfully."
)
except Exception as e_stop_join:
module_logger.error(
f"Error during old adapter stop/join: {e_stop_join}", exc_info=True
f"Error stopping old adapter: {e_join}", exc_info=True
)
finally:
self.live_adapter_thread = None
else:
module_logger.debug(
"Controller: No active LiveAdapter thread to stop or already stopped."
)
self.live_adapter_thread = OpenSkyLiveAdapter(
output_queue=self.flight_data_queue,
bounding_box=self._active_bounding_box,
@ -526,60 +331,41 @@ class AppController:
)
self.is_live_monitoring_active = True
self.live_adapter_thread.start()
module_logger.info(
f"Controller: New live adapter thread '{self.live_adapter_thread.name}' started."
)
if (
self._gui_after_id
and self.main_window
and hasattr(self.main_window, "root")
and self.main_window.root.winfo_exists()
):
try:
self.main_window.root.after_cancel(self._gui_after_id)
except Exception:
except:
pass
finally:
self._gui_after_id = None
if (
self.main_window
and hasattr(self.main_window, "root")
and self.main_window.root.winfo_exists()
):
if self.main_window and self.main_window.root.winfo_exists():
self._gui_after_id = self.main_window.root.after(
100, self._process_flight_data_queue
)
module_logger.info("Controller: GUI queue polling scheduled.")
else:
module_logger.error(
"Controller: Cannot schedule GUI queue polling: MainWindow or root does not exist. Aborting live monitoring."
)
else: # Fallback se la GUI non c'è
self.is_live_monitoring_active = False
if self.live_adapter_thread and self.live_adapter_thread.is_alive():
try:
self.live_adapter_thread.stop()
except Exception as e_stop_fail:
module_logger.error(f"Error trying to stop adapter: {e_stop_fail}")
if hasattr(self.main_window, "_reset_gui_to_stopped_state"):
self.main_window._reset_gui_to_stopped_state("Start failed: GUI error.")
def stop_live_monitoring(self, from_error: bool = False):
# ... (come nella versione precedente completa)
if not self.is_live_monitoring_active and not (
from_error
and self.live_adapter_thread
and self.live_adapter_thread.is_alive()
):
module_logger.debug(
f"Controller: Stop requested but live monitoring/adapter not active (from_error={from_error}). Ignoring."
)
if (
hasattr(self.main_window, "_reset_gui_to_stopped_state")
and not from_error
):
self.main_window._reset_gui_to_stopped_state(
"Monitoring already stopped or not started."
"Monitoring already stopped."
)
return
module_logger.info(
@ -589,107 +375,51 @@ class AppController:
if (
self._gui_after_id
and self.main_window
and hasattr(self.main_window, "root")
and self.main_window.root.winfo_exists()
):
try:
self.main_window.root.after_cancel(self._gui_after_id)
except Exception:
except:
pass
finally:
self._gui_after_id = None
adapter_thread_to_stop = self.live_adapter_thread
if adapter_thread_to_stop and adapter_thread_to_stop.is_alive():
module_logger.debug(
f"Controller: Signaling LiveAdapter thread ({adapter_thread_to_stop.name}) to stop."
)
try:
adapter_thread_to_stop.stop()
if (
self.main_window
and hasattr(self.main_window, "root")
and self.main_window.root.winfo_exists()
):
if self.live_adapter_thread and self.live_adapter_thread.is_alive():
try:
self.live_adapter_thread.stop()
if self.main_window and self.main_window.root.winfo_exists():
self.main_window.root.update_idletasks()
except Exception:
pass
module_logger.debug(
f"Controller: Waiting for LiveAdapter thread ({adapter_thread_to_stop.name}) to join..."
)
adapter_thread_to_stop.join(timeout=ADAPTER_JOIN_TIMEOUT_SECONDS)
if adapter_thread_to_stop.is_alive():
module_logger.error(
f"Controller: LiveAdapter thread ({adapter_thread_to_stop.name}) did NOT join in time!"
)
else:
module_logger.info(
f"Controller: LiveAdapter thread ({adapter_thread_to_stop.name}) joined successfully."
)
except Exception as e_stop_join:
module_logger.error(
f"Error during adapter stop/join sequence: {e_stop_join}",
exc_info=True,
)
self.live_adapter_thread.join(timeout=ADAPTER_JOIN_TIMEOUT_SECONDS)
except Exception as e_join:
module_logger.error(f"Error stopping adapter: {e_join}", exc_info=True)
finally:
self.live_adapter_thread = None
else:
module_logger.debug(
"Controller: No active LiveAdapter thread to stop or already stopped."
)
self.live_adapter_thread = None
if (
self.flight_data_queue
and self.main_window
and hasattr(self.main_window, "root")
and self.main_window.root.winfo_exists()
):
module_logger.debug(
"Controller: Processing final messages from adapter queue post-join..."
)
try:
self._process_flight_data_queue()
module_logger.debug(
"Controller: Requested final processing of adapter queue."
)
except Exception as e_final_loop:
except Exception as e_final_q:
module_logger.error(
f"Controller: Unexpected error in final queue processing request: {e_final_loop}",
exc_info=True,
)
else:
module_logger.debug(
"Controller: No flight data queue or GUI to process after stop."
f"Error in final queue processing: {e_final_q}", exc_info=True
)
if hasattr(self.main_window, "clear_all_views_data"):
try:
self.main_window.clear_all_views_data()
except Exception as e_clear_views:
module_logger.error(
f"Error calling clear_all_views_data after stop: {e_clear_views}",
exc_info=False,
)
if hasattr(self.main_window, "_reset_gui_to_stopped_state"):
stop_status_msg = "Monitoring stopped."
if from_error:
stop_status_msg = "Monitoring stopped due to an error."
msg = (
"Monitoring stopped due to an error."
if from_error
else "Monitoring stopped."
)
try:
self.main_window._reset_gui_to_stopped_state(stop_status_msg)
except tk.TclError:
module_logger.warning(
"TclError resetting GUI state after stop. GUI likely gone."
)
except Exception as e_reset_gui:
module_logger.error(
f"Error resetting GUI state after stop: {e_reset_gui}",
exc_info=True,
)
self.main_window._reset_gui_to_stopped_state(msg)
except Exception as e_reset:
module_logger.error(f"Error resetting GUI: {e_reset}", exc_info=True)
self._active_bounding_box = None
module_logger.info(
"Controller: Live monitoring shutdown sequence fully completed."
)
def on_application_exit(self):
# ... (come nella versione precedente completa, inclusa la chiusura di aircraft_db_manager)
module_logger.info(
"Controller: Application exit requested. Cleaning up resources."
)
@ -702,9 +432,6 @@ class AppController:
if hasattr(map_manager, "shutdown_worker") and callable(
map_manager.shutdown_worker
):
module_logger.debug(
"Controller: Requesting MapCanvasManager to shutdown its worker."
)
try:
map_manager.shutdown_worker()
module_logger.info(
@ -715,13 +442,11 @@ class AppController:
f"Controller: Error during MapCanvasManager worker shutdown: {e_map_shutdown}",
exc_info=True,
)
is_adapter_considered_running = (
self.live_adapter_thread and self.live_adapter_thread.is_alive()
) or self.is_live_monitoring_active
if is_adapter_considered_running:
self.stop_live_monitoring(from_error=False)
if self.data_storage:
try:
self.data_storage.close_connection()
@ -731,7 +456,6 @@ class AppController:
)
finally:
self.data_storage = None
if self.aircraft_db_manager:
try:
self.aircraft_db_manager.close_connection()
@ -744,13 +468,13 @@ class AppController:
self.aircraft_db_manager = None
module_logger.info("Controller: Cleanup on application exit finished.")
def start_history_monitoring(self):
def start_history_monitoring(self): # Placeholder
# ... (come prima)
if not self.main_window:
module_logger.error("Main window not set for history.")
return
if not self.data_storage:
err_msg = "DataStorage not initialized. Cannot use history features."
module_logger.error(f"Controller: {err_msg}")
if hasattr(self.main_window, "update_semaphore_and_status"):
self.main_window.update_semaphore_and_status(GUI_STATUS_ERROR, err_msg)
if hasattr(self.main_window, "_reset_gui_to_stopped_state"):
@ -758,16 +482,15 @@ class AppController:
f"History start failed: {err_msg}"
)
return
module_logger.info("Controller: History monitoring started (placeholder).")
if hasattr(self.main_window, "update_semaphore_and_status"):
self.main_window.update_semaphore_and_status(
GUI_STATUS_OK, "History mode active (placeholder)."
)
def stop_history_monitoring(self):
def stop_history_monitoring(self): # Placeholder
# ... (come prima)
if not self.main_window:
return
module_logger.info("Controller: History monitoring stopped (placeholder).")
if hasattr(self.main_window, "update_semaphore_and_status"):
self.main_window.update_semaphore_and_status(
GUI_STATUS_OK, "History monitoring stopped."
@ -776,6 +499,7 @@ class AppController:
def on_map_left_click(
self, latitude: float, longitude: float, screen_x: int, screen_y: int
):
# ... (come prima, solo aggiornamento info click)
module_logger.debug(
f"Controller: Map left-clicked at Geo ({latitude:.5f}, {longitude:.5f})"
)
@ -816,10 +540,9 @@ class AppController:
module_logger.error(
f"Error updating map clicked info panel: {e_update}", exc_info=False
)
else:
module_logger.warning("Main window N/A to update clicked map info.")
def request_detailed_flight_info(self, icao24: str):
# ... (come prima)
module_logger.info(f"Controller: Detailed info request for ICAO24: {icao24}")
if not self.main_window:
module_logger.error("Controller: MainWindow not set.")
@ -828,11 +551,9 @@ class AppController:
if hasattr(self.main_window, "update_selected_flight_details"):
self.main_window.update_selected_flight_details(None)
return
live_data: Optional[Dict[str, Any]] = None
static_data: Optional[Dict[str, Any]] = None
combined_details: Dict[str, Any] = {"icao24": icao24.lower()}
if (
self.main_window
and hasattr(self.main_window, "map_manager_instance")
@ -843,25 +564,24 @@ class AppController:
and hasattr(self.main_window.map_manager_instance, "_map_data_lock")
):
map_mgr = self.main_window.map_manager_instance
with map_mgr._map_data_lock:
with map_mgr._map_data_lock: # type: ignore
for state in map_mgr._current_flights_to_display_gui: # type: ignore
if state.icao24.lower() == icao24.lower():
live_data = state.to_dict()
break
if live_data:
combined_details.update(live_data)
if self.aircraft_db_manager:
static_data = self.aircraft_db_manager.get_aircraft_details(icao24)
if static_data:
for k, v in static_data.items():
if k not in combined_details:
combined_details[k] = v
if hasattr(self.main_window, "update_selected_flight_details"):
self.main_window.update_selected_flight_details(combined_details)
def import_aircraft_database_from_file_with_progress(self, csv_filepath: str, progress_dialog_ref: "ImportProgressDialog"): # type: ignore
# ... (come prima, con avvio thread)
module_logger.info(
f"Controller: Requesting aircraft DB import with progress from: {csv_filepath}"
)
@ -896,6 +616,7 @@ class AppController:
module_logger.info(f"Aircraft DB import thread started for: {csv_filepath}")
def _count_csv_rows(self, csv_filepath: str) -> Optional[int]:
# ... (come prima, con aumento csv.field_size_limit e module_logger)
try:
current_limit = csv.field_size_limit()
new_limit_target = 10 * 1024 * 1024
@ -938,6 +659,7 @@ class AppController:
return None
def _perform_db_import_with_progress_threaded(self, csv_filepath: str, progress_dialog_ref: "ImportProgressDialog"): # type: ignore
# ... (come prima, con schedule_gui_update e passaggio callback)
if not self.aircraft_db_manager:
module_logger.error("AircraftDBManager N/A in import thread.")
if (
@ -1083,12 +805,40 @@ class AppController:
live_data = state.to_dict()
break
full_track_data_list: Optional[List[Dict[str, Any]]] = None
# Placeholder: if self.data_storage: full_track_data_list = self.data_storage.get_complete_track_for_icao(icao24)
full_track_data_list: List[Dict[str, Any]] = [] # Inizializza come lista vuota
if self.data_storage:
try:
# Per ora, recuperiamo la traccia solo per il giorno UTC corrente
# In futuro, potremmo voler passare un intervallo di date o un flight_id specifico
current_utc_date = datetime.now(timezone.utc)
track_states = self.data_storage.get_flight_track_for_icao_on_date(
icao24, current_utc_date
)
if track_states:
full_track_data_list = [state.to_dict() for state in track_states]
module_logger.debug(
f"FullDetails: Found {len(full_track_data_list)} historical track points for {icao24} (today)."
)
else:
module_logger.info(
f"FullDetails: No historical track data found for {icao24} (today)."
)
except Exception as e_track:
module_logger.error(
f"FullDetails: Error retrieving historical track for {icao24}: {e_track}",
exc_info=True,
)
else:
module_logger.warning(
"FullDetails: DataStorage not available for historical track."
)
try:
from ..gui.dialogs.full_flight_details_window import FullFlightDetailsWindow
from ..gui.dialogs.full_flight_details_window import (
FullFlightDetailsWindow,
) # Importa qui
# Gestisci la chiusura della finestra precedente
if (
hasattr(self.main_window, "full_flight_details_window")
and self.main_window.full_flight_details_window
@ -1097,11 +847,13 @@ class AppController:
try:
self.main_window.full_flight_details_window.destroy() # type: ignore
except tk.TclError:
pass
pass # Potrebbe essere già in fase di distruzione
details_win = FullFlightDetailsWindow(self.main_window.root, icao24, self)
self.main_window.full_flight_details_window = details_win
details_win.update_details(static_data, live_data, full_track_data_list)
details_win.update_details(
static_data, live_data, full_track_data_list
) # Passa la traccia
except ImportError:
module_logger.error(
@ -1109,7 +861,7 @@ class AppController:
)
if hasattr(self.main_window, "show_error_message"):
self.main_window.show_error_message(
"UI Error", "Could not open full details window."
"UI Error", "Could not open full details window (import error)."
)
except Exception as e_show_details:
module_logger.error(
@ -1121,6 +873,7 @@ class AppController:
"Error", f"Could not display full details: {e_show_details}"
)
# Assicurati che tutti gli altri metodi (on_map_right_click, etc.) siano presenti come prima.
def on_map_right_click(
self, latitude: float, longitude: float, screen_x: int, screen_y: int
):

File diff suppressed because it is too large Load Diff