Basic GUI infrastructure

This commit is contained in:
2025-07-28 15:00:25 +02:00
commit 4e1a9f0182
8 changed files with 180 additions and 0 deletions

0
widgets/__init__.py Normal file
View File

20
widgets/base_widget.py Normal file
View File

@ -0,0 +1,20 @@
import dearpygui.dearpygui as dpg
import logging
class BaseWidget:
"""A base class to handle common functionality for all widgets."""
def __init__(self, widget_type: str, config: dict, layout_manager):
self.widget_type = widget_type
self.config = config
self.layout_manager = layout_manager
self.window_tag = f"widget_win_{self.widget_type}"
def create(self):
raise NotImplementedError
def get_config(self) -> dict:
return self.config
def _on_window_close(self, sender, app_data, user_data):
logging.info(f"Hiding widget: {self.widget_type}")
dpg.configure_item(self.window_tag, show=False)

17
widgets/log_widget.py Normal file
View File

@ -0,0 +1,17 @@
import dearpygui.dearpygui as dpg
from .base_widget import BaseWidget
class LogWidget(BaseWidget):
"""A widget to display captured log messages."""
def create(self):
if dpg.does_item_exist(self.window_tag): return
with dpg.window(label="Log Viewer", tag=self.window_tag, on_close=self._on_window_close, width=500, height=300):
self.text_item_tag = dpg.add_input_text(
multiline=True, readonly=True, width=-1, height=-1, default_value="Log initialized.\n"
)
def update_logs(self, log_handler):
"""Called every frame to update the text with new logs."""
if dpg.is_item_visible(self.window_tag):
log_content = log_handler.get_all_logs()
dpg.set_value(self.text_item_tag, log_content)

10
widgets/simple_widget.py Normal file
View File

@ -0,0 +1,10 @@
import dearpygui.dearpygui as dpg
from .base_widget import BaseWidget
class SimpleWidget(BaseWidget):
"""A basic text widget to demonstrate dynamic loading."""
def create(self):
if dpg.does_item_exist(self.window_tag): return
with dpg.window(label="Simple Widget", tag=self.window_tag, on_close=self._on_window_close, width=300, height=120):
dpg.add_text("This widget was loaded dynamically!")
dpg.add_button(label="A Button")