Add `get_godw()` singleton getter for `GodWidget`

Expose `get_godw()` helper to retrieve the central `GodWidget`
instance from anywhere in the UI code. Set the singleton in
`_async_main()` on startup.

Also,
- add docstring to `run_qtractor()` explaining trio guest mode
- type annotate `instance: GodWidget` in `run_qtractor()`
- import reorg in `._app` for cleaner grouping
- whitespace cleanup: `Type | None` -> `Type|None` throughout
- fix bitwise-or alignment: `Flag | Other` -> `Flag|Other`

(this commit-msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
refresh_annots
Gud Boi 2026-01-30 15:39:25 -05:00
parent eb78437994
commit bac8317a4a
4 changed files with 72 additions and 46 deletions

View File

@ -27,15 +27,15 @@ import trio
from piker.ui.qt import (
QEvent,
)
from ..service import maybe_spawn_brokerd
from . import _chart
from . import _event
from ._exec import run_qtractor
from ..data.feed import install_brokerd_search
from ..data._symcache import open_symcache
from ..accounting import unpack_fqme
from . import _search
from ._chart import GodWidget
from ..accounting import unpack_fqme
from ..data._symcache import open_symcache
from ..data.feed import install_brokerd_search
from ..log import get_logger
from ..service import maybe_spawn_brokerd
from ._exec import run_qtractor
log = get_logger(__name__)
@ -73,8 +73,8 @@ async def load_provider_search(
async def _async_main(
# implicit required argument provided by ``qtractor_run()``
main_widget: GodWidget,
# implicit required argument provided by `qtractor_run()`
main_widget: _chart.GodWidget,
syms: list[str],
brokers: dict[str, ModuleType],
@ -87,6 +87,9 @@ async def _async_main(
Provision the "main" widget with initial symbol data and root nursery.
"""
# set as singleton
_chart._godw = main_widget
from . import _display
from ._pg_overrides import _do_overrides
_do_overrides()
@ -201,6 +204,6 @@ def _main(
brokermods,
piker_loglevel,
),
main_widget_type=GodWidget,
main_widget_type=_chart.GodWidget,
tractor_kwargs=tractor_kwargs,
)

View File

@ -82,6 +82,25 @@ if TYPE_CHECKING:
log = get_logger(__name__)
_godw: GodWidget|None = None
def get_godw() -> GodWidget:
'''
Get the top level "god widget", the root/central-most Qt
widget-object set as `QMainWindow.setCentralWidget(_godw)`.
See `piker.ui._exec` for the runtime init details and all the
machinery for running `trio` on the Qt event loop in guest mode.
'''
if _godw is None:
raise RuntimeError(
'No god-widget initialized ??\n'
'Have you called `run_qtractor()` yet?\n'
)
return _godw
class GodWidget(QWidget):
'''
"Our lord and savior, the holy child of window-shua, there is no
@ -567,8 +586,8 @@ class LinkedSplits(QWidget):
# style?
self.chart.setFrameStyle(
QFrame.Shape.StyledPanel |
QFrame.Shadow.Plain
QFrame.Shape.StyledPanel
|QFrame.Shadow.Plain
)
return self.chart

View File

@ -91,6 +91,10 @@ def run_qtractor(
window_type: QMainWindow = None,
) -> None:
'''
Run the Qt event loop and embed `trio` via guest mode on it.
'''
# avoids annoying message when entering debugger from qt loop
pyqtRemoveInputHook()
@ -170,7 +174,7 @@ def run_qtractor(
# hook into app focus change events
app.focusChanged.connect(window.on_focus_change)
instance = main_widget_type()
instance: GodWidget = main_widget_type()
instance.window = window
# override tractor's defaults