Asset-Frameworker/ProjectNotes/GUI_LOG_CONSOLE_PLAN.md
2025-04-29 18:26:13 +02:00

4.6 KiB

GUI Log Console Feature Plan

Overall Goal: Add a log console panel to the GUI's editor panel, controlled by a "View" menu action. Move the "Disable Detailed Preview" control to the same "View" menu.

Detailed Plan:

  1. Create Custom Log Handler:

    • New File/Location: Potentially add this to a new gui/log_handler.py or keep it within gui/main_window.py if simple enough.
    • Implementation:
      • Define a class QtLogHandler(logging.Handler, QObject) that inherits from both logging.Handler and QObject (for signals).
      • Add a Qt signal, e.g., log_record_received = Signal(str).
      • Override the emit(self, record) method:
        • Format the log record using self.format(record).
        • Emit the log_record_received signal with the formatted string.
  2. Modify gui/main_window.py:

    • Imports: Add QMenuBar, QMenu, QAction from PySide6.QtWidgets. Import the new QtLogHandler.
    • UI Elements (__init__ / setup_editor_panel_ui):
      • Menu Bar:
        • Create self.menu_bar = self.menuBar().
        • Create view_menu = self.menu_bar.addMenu("&View").
      • Log Console:
        • Create self.log_console_output = QTextEdit(). Set it to read-only (self.log_console_output.setReadOnly(True)).
        • Create a container widget, e.g., self.log_console_widget = QWidget(). Create a layout for it (e.g., QVBoxLayout) and add self.log_console_output to this layout.
        • In setup_editor_panel_ui, insert self.log_console_widget into the editor_layout before adding the list_layout (the preset list).
        • Initially hide the console: self.log_console_widget.setVisible(False).
      • Menu Actions:
        • Create self.toggle_log_action = QAction("Show Log Console", self, checkable=True). Connect self.toggle_log_action.toggled.connect(self._toggle_log_console_visibility). Add it to view_menu.
        • Create self.toggle_preview_action = QAction("Disable Detailed Preview", self, checkable=True). Connect self.toggle_preview_action.toggled.connect(self.update_preview). Add it to view_menu.
      • Remove Old Checkbox: Delete the lines creating and adding self.disable_preview_checkbox.
    • Logging Setup (__init__):
      • Instantiate the custom handler: self.log_handler = QtLogHandler().
      • Connect its signal: self.log_handler.log_record_received.connect(self._append_log_message).
      • Add the handler to the logger: log.addHandler(self.log_handler). Set an appropriate level if needed (e.g., self.log_handler.setLevel(logging.INFO)).
    • New Slots:
      • Implement _toggle_log_console_visibility(self, checked): This slot will simply call self.log_console_widget.setVisible(checked).
      • Implement _append_log_message(self, message):
        • Append the message string to self.log_console_output.
        • Optional: Add logic to limit the number of lines in the text edit to prevent performance issues.
        • Optional: Add basic HTML formatting for colors based on log level.
    • Modify update_preview:
      • Replace the check for self.disable_preview_checkbox.isChecked() with self.toggle_preview_action.isChecked().
      • Update the log messages within this method to reflect checking the action state.

Mermaid Diagram:

graph TD
    subgraph MainWindow
        A[Initialization] --> B(Create Menu Bar);
        B --> C(Add View Menu);
        C --> D(Add 'Show Log Console' Action);
        C --> E(Add 'Disable Detailed Preview' Action);
        A --> F(Create Log Console QTextEdit);
        F --> G(Place Log Console Widget in Layout [Hidden]);
        A --> H(Create & Add QtLogHandler);
        H --> I(Connect Log Handler Signal to _append_log_message);

        D -- Toggled --> J[_toggle_log_console_visibility];
        J --> K(Show/Hide Log Console Widget);

        E -- Toggled --> L[update_preview];

        M[update_preview] --> N{Is 'Disable Preview' Action Checked?};
        N -- Yes --> O[Show Simple List View];
        N -- No --> P[Start PredictionHandler];

        Q[Any Log Message] -- Emitted by Logger --> H;
        I --> R[_append_log_message];
        R --> S(Append Message to Log Console QTextEdit);
    end

    subgraph QtLogHandler
        style QtLogHandler fill:#lightgreen,stroke:#333,stroke-width:2px
        T1[emit(record)] --> T2(Format Record);
        T2 --> T3(Emit log_record_received Signal);
        T3 --> I;
    end