101 Zeilen
4.2 KiB
Python
101 Zeilen
4.2 KiB
Python
"""
|
|
Process Manager Handler
|
|
Handles process monitoring and management operations
|
|
"""
|
|
|
|
from typing import Optional, TYPE_CHECKING
|
|
from utils.logger import logger
|
|
|
|
if TYPE_CHECKING:
|
|
from gui.main_window import MainWindow
|
|
from project_manager import Project
|
|
|
|
|
|
class ProcessManagerHandler:
|
|
"""Handles all process management operations for MainWindow"""
|
|
|
|
def __init__(self, main_window: 'MainWindow'):
|
|
"""Initialize with reference to main window"""
|
|
self.main_window = main_window
|
|
self.root = main_window.root
|
|
self.process_manager = main_window.process_manager
|
|
self.process_tracker = main_window.process_tracker
|
|
self.project_manager = main_window.project_manager
|
|
logger.info("ProcessManagerHandler initialized")
|
|
|
|
def monitor_process(self, project: 'Project', process) -> None:
|
|
"""Monitor a process for a project"""
|
|
return self.main_window._original_monitor_process(project, process)
|
|
|
|
def check_process_status(self) -> None:
|
|
"""Check status of all processes"""
|
|
return self.main_window._original_check_process_status()
|
|
|
|
def stop_project(self, project: 'Project') -> None:
|
|
"""Stop a running project"""
|
|
return self.main_window._original_stop_project(project)
|
|
|
|
def update_status(self, message: str, error: bool = False) -> None:
|
|
"""Update status bar message"""
|
|
# Direct implementation
|
|
from gui.styles import COLORS
|
|
|
|
if hasattr(self.main_window, 'status_label'):
|
|
self.main_window.status_label.configure(
|
|
text=message,
|
|
text_color=COLORS['accent_error'] if error else COLORS['text_secondary']
|
|
)
|
|
logger.debug(f"Status updated: {message} (error={error})")
|
|
|
|
def download_log(self) -> None:
|
|
"""Download comprehensive application log with all interactions"""
|
|
# Direct implementation
|
|
from tkinter import filedialog, messagebox
|
|
import os
|
|
from datetime import datetime
|
|
|
|
logger.info(f"Download log clicked - Total entries: {len(logger.log_entries)}")
|
|
|
|
try:
|
|
# Generate default filename with timestamp
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
default_filename = f"CPM_FullLog_{timestamp}.log"
|
|
|
|
# Open file dialog to choose save location
|
|
file_path = filedialog.asksaveasfilename(
|
|
defaultextension=".log",
|
|
filetypes=[("Log files", "*.log"), ("Text files", "*.txt"), ("All files", "*.*")],
|
|
initialfile=default_filename,
|
|
title="Save Complete Application Log"
|
|
)
|
|
|
|
if file_path:
|
|
# Export logs to chosen location with system info
|
|
logger.export_logs(file_path, include_system_info=True)
|
|
|
|
# Add completion entry
|
|
logger.info(f"Log export completed - Total entries: {len(logger.log_entries)}, Interactions: {logger.interaction_count}")
|
|
|
|
# Update status
|
|
self.update_status(f"Log saved: {os.path.basename(file_path)} ({len(logger.log_entries)} entries)")
|
|
|
|
# Show success message with log details
|
|
messagebox.showinfo(
|
|
"Log Export Successful",
|
|
f"Complete application log saved to:\n{file_path}\n\n"
|
|
f"Total log entries: {len(logger.log_entries):,}\n"
|
|
f"UI interactions logged: {logger.interaction_count:,}\n"
|
|
f"File size: {os.path.getsize(file_path) / 1024:.1f} KB"
|
|
)
|
|
else:
|
|
logger.info("Log export cancelled by user")
|
|
|
|
except Exception as e:
|
|
error_msg = f"Error saving log: {str(e)}"
|
|
self.update_status(error_msg, error=True)
|
|
logger.log_exception(e, "download_log")
|
|
messagebox.showerror("Export Error", error_msg)
|
|
|
|
def _handle_process_ended(self, project: 'Project') -> None:
|
|
"""Handle process end event (private method)"""
|
|
return self.main_window._original_handle_process_ended(project) |