Source code for pyobs_gui.gui

import asyncio
import sys
from typing import Any, cast, TYPE_CHECKING
from PySide6 import QtWidgets  # type: ignore
import qasync  # type: ignore

if TYPE_CHECKING:
    from .mainwindow import MainWindow

from pyobs.interfaces import IFitsHeaderBefore
from pyobs.modules import Module


class GUI(Module, IFitsHeaderBefore):
    __module__ = "pyobs_gui"

    app: QtWidgets.QApplication | None = None

    def __init__(
        self,
        show_shell: bool = True,
        show_events: bool = True,
        show_status: bool = True,
        show_modules: list[str] | None = None,
        widgets: list[dict[str, Any]] | None = None,
        sidebar: list[dict[str, Any]] | None = None,
        *args: Any,
        **kwargs: Any,
    ):
        """Inits a new GUI.

        Args:
            show_shell: Whether to show the shell page.
            show_events: Whether to show the events page.
            show_modules: If not empty, show only listed modules.
            widgets: List of custom widgets.
            sidebar: List of custom sidebar widgets.
        """

        # init module
        Module.__init__(self, *args, **kwargs)
        self._window: MainWindow | None = None
        self._show_shell = show_shell
        self._show_events = show_events
        self._show_status = show_status
        self._show_modules = show_modules
        self._custom_widgets = widgets
        self._custom_sidebar_widgets = sidebar

    @staticmethod
    def new_event_loop() -> asyncio.AbstractEventLoop:
        GUI.app = QtWidgets.QApplication(sys.argv)
        return cast(asyncio.AbstractEventLoop, qasync.QEventLoop(GUI.app))

[docs] async def open(self) -> None: """Open module.""" from .mainwindow import MainWindow await Module.open(self) # create and show window self._window = MainWindow( show_shell=self._show_shell, show_events=self._show_events, show_status=self._show_status, show_modules=self._show_modules, widgets=self._custom_widgets, sidebar=self._custom_sidebar_widgets, ) await self._window.open( module=self, comm=self.comm, vfs=self.vfs, observer=self.observer, ) self._window.show()
[docs] async def get_fits_header_before( self, namespaces: list[str] | None = None, **kwargs: Any ) -> dict[str, tuple[Any, str]]: """Returns FITS header for the current status of this module. Args: namespaces: If given, only return FITS headers for the given namespaces. Returns: Dictionary containing FITS headers. """ if self._window is not None: return self._window.get_fits_headers(namespaces) else: return {}