4.6 KiB
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:
-
Create Custom Log Handler:
- New File/Location: Potentially add this to a new
gui/log_handler.pyor keep it withingui/main_window.pyif simple enough. - Implementation:
- Define a class
QtLogHandler(logging.Handler, QObject)that inherits from bothlogging.HandlerandQObject(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_receivedsignal with the formatted string.
- Format the log record using
- Define a class
- New File/Location: Potentially add this to a new
-
Modify
gui/main_window.py:- Imports: Add
QMenuBar,QMenu,QActionfromPySide6.QtWidgets. Import the newQtLogHandler. - UI Elements (
__init__/setup_editor_panel_ui):- Menu Bar:
- Create
self.menu_bar = self.menuBar(). - Create
view_menu = self.menu_bar.addMenu("&View").
- Create
- 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 addself.log_console_outputto this layout. - In
setup_editor_panel_ui, insertself.log_console_widgetinto theeditor_layoutbefore adding thelist_layout(the preset list). - Initially hide the console:
self.log_console_widget.setVisible(False).
- Create
- Menu Actions:
- Create
self.toggle_log_action = QAction("Show Log Console", self, checkable=True). Connectself.toggle_log_action.toggled.connect(self._toggle_log_console_visibility). Add it toview_menu. - Create
self.toggle_preview_action = QAction("Disable Detailed Preview", self, checkable=True). Connectself.toggle_preview_action.toggled.connect(self.update_preview). Add it toview_menu.
- Create
- Remove Old Checkbox: Delete the lines creating and adding
self.disable_preview_checkbox.
- Menu Bar:
- 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)).
- Instantiate the custom handler:
- New Slots:
- Implement
_toggle_log_console_visibility(self, checked): This slot will simply callself.log_console_widget.setVisible(checked). - Implement
_append_log_message(self, message):- Append the
messagestring toself.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.
- Append the
- Implement
- Modify
update_preview:- Replace the check for
self.disable_preview_checkbox.isChecked()withself.toggle_preview_action.isChecked(). - Update the log messages within this method to reflect checking the action state.
- Replace the check for
- Imports: Add
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