MainApp
- class gpype.frontend.main_app.MainApp[source]
Bases:
objectMain application class for g.Pype frontend applications.
Provides framework for creating PyQt6-based applications with widget management, window configuration, and lifecycle handling. Uses composition for better flexibility and testability.
- DEFAULT_POSITION = [100, 100, 700, 400]
Default window geometry configuration
- DEFAULT_GRID_SIZE = [3, 3]
Default grid size (rows, cols)
- ICON_PATH = PosixPath('resources/gpype.ico')
Application icon path
- classmethod end_run()[source]
End a run() that is waiting in a browser’s Web Worker.
The host’s counterpart of closing the window. A worker has none, so run() waits there until the page ends it – its Stop button, through the worker’s message handler – and the script carries on with
p.stop()as on a desktop. A Stop that comes before run() waits – while the script awaits something on its way to it – is kept, and that run() returns at once.- Returns:
True if a run() was waiting and now returns; False if none was, and the next one will not wait.
- Return type:
- __init__(caption='g.Pype Application', position=None, grid_size=None, app=None, prevent_sleep=True, theme='dark', icon=None)[source]
Initialize the main application with window and widget management.
- Parameters:
caption (
str) – Window title text displayed in the title bar.position (
list[int]) – Window geometry as [x, y, width, height] list. Uses DEFAULT_POSITION if None.grid_size (
list[int]) – Grid dimensions as [rows, cols] list. Uses DEFAULT_GRID_SIZE if None.app – Existing QApplication instance for testing or integration. Creates new QApplication if None.
prevent_sleep (
bool) – Whether to prevent system sleep/power saving. Default True for real-time applications.theme (
str) – Application theme, one of gpype.frontend.theme.THEMES. “dark” applies the bundled dark palette and style sheet to the QApplication; “system” leaves Qt’s own defaults alone, for a host application that brings its own look.icon (
str|Path|None) – The application’s icon file, for its windows and its taskbar button. If None, the one a build names inGPYPE_APP_ICON, else g.Pype’s. See gpype.frontend.identity.
- add_widget(widget, grid_positions=None)[source]
Add a widget to the application layout and management system.
Registers the widget for lifecycle management and adds it to the main window’s grid layout. Widget will be automatically started during run() and terminated during shutdown.
- run()[source]
Start the application and enter the main event loop.
Shows the main window, starts all registered widgets, enables sleep prevention if configured, and enters the Qt event loop. Blocks until the application is closed.
- Returns:
- Application exit code. 0 indicates successful execution,
non-zero values indicate errors or abnormal termination.
- Return type: