SXXXXXXX_CppPythonDebug/cpp_python_debug/__main__.py
VALLONGOL e66ce1683a Chore: Stop tracking files based on .gitignore update.
Untracked files matching the following rules:
- Rule ".metadata/": 72 files
2025-05-20 14:19:43 +02:00

102 lines
4.6 KiB
Python

# File: cpp_python_debug/__main__.py
# Main entry point for the Cpp-Python Debug Helper application.
# This script initializes logging and starts the Tkinter GUI.
import logging
import sys # For stream handler to output to console
# Use relative import to get the GDBGui class from the gui subpackage
from .gui.main_window import GDBGui
# --- Application Constants (Optional) ---
APP_NAME = "Cpp-Python GDB Debug Helper"
APP_VERSION = "1.1.0" # Example version
def setup_global_logging():
"""
Configures basic logging for the application.
- Logs to console (stdout).
- GUI will have its own handler to display logs within the application window.
"""
# Define the root logger level. DEBUG will capture everything.
# Specific handlers can have their own, more restrictive levels.
log_level = logging.DEBUG # Or logging.INFO for less verbosity in console
# Basic configuration for the root logger
# This will set up a default StreamHandler to sys.stderr if no handlers are added.
# We will add our own StreamHandler to sys.stdout for better control.
logging.basicConfig(level=log_level,
format='%(asctime)s - %(name)-25s - %(levelname)-8s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
# If you want to ensure console output goes to stdout instead of stderr (default for basicConfig warnings/errors)
# and have more control over the console handler:
# 1. Get the root logger
root_logger = logging.getLogger()
# 2. Remove any default handlers basicConfig might have added (if any, depends on Python version behavior)
# For safety, clear existing handlers if you want to be sure only yours are present.
# for handler in root_logger.handlers[:]:
# root_logger.removeHandler(handler)
# 3. Add your custom console StreamHandler
# console_handler = logging.StreamHandler(sys.stdout)
# console_formatter = logging.Formatter('%(asctime)s - %(name)-25s - %(levelname)-8s - %(message)s',
# datefmt='%Y-%m-%d %H:%M:%S')
# console_handler.setFormatter(console_formatter)
# console_handler.setLevel(log_level) # Set level for this specific handler
# root_logger.addHandler(console_handler)
# The ScrolledTextLogHandler in main_window.py will be added to the root logger
# when the GDBGui instance is created, so logs will also go to the GUI.
logger = logging.getLogger(__name__) # Get a logger for this module
logger.info(f"Global logging initialized. Console log level: {logging.getLevelName(log_level)}.")
logger.info(f"Starting {APP_NAME} v{APP_VERSION}")
def main():
"""
Main function to set up logging and launch the GDB GUI.
"""
setup_global_logging() # Initialize logging first
# Get a logger for the main execution scope
# (using __name__ here would give 'cpp_python_debug.__main__')
app_logger = logging.getLogger(APP_NAME) # Or use a more generic name
try:
app_logger.info("Creating GDBGui instance...")
app = GDBGui() # Create the main application window
app_logger.info("Starting Tkinter main event loop.")
app.mainloop() # Start the Tkinter event loop
app_logger.info("Tkinter main event loop finished.")
except Exception as e:
# Catch any unhandled exceptions during GUI initialization or runtime
# that might not be caught by Tkinter's own error handling.
app_logger.critical(f"An unhandled critical error occurred: {e}", exc_info=True)
# Optionally, show a simple error dialog if Tkinter is still somewhat functional
# or if it fails before Tkinter is even up.
# For console-based launch, the log to console is key.
try:
import tkinter as tk
from tkinter import messagebox
# Check if a root window exists or can be created
# This is a bit of a hack; ideally, errors are caught within the GUI logic.
root_for_error = tk.Tk()
root_for_error.withdraw() # Hide the empty root window
messagebox.showerror("Critical Application Error",
f"A critical error occurred:\n{e}\n\nPlease check the logs for more details.")
root_for_error.destroy()
except Exception:
pass # If Tkinter itself is broken, can't show a Tkinter messagebox
finally:
app_logger.info(f"{APP_NAME} is shutting down.")
logging.shutdown() # Cleanly close all logging handlers
if __name__ == "__main__":
# This allows the script to be run directly (e.g., python __main__.py)
# as well as via `python -m cpp_python_debug`.
main()