Skip to content

Commit 6e11c7b

Browse files
authored
v1.0.2
version 1.0.2
2 parents 427e55a + ddfe960 commit 6e11c7b

File tree

5 files changed

+111
-6
lines changed

5 files changed

+111
-6
lines changed

pyobs_gui/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
from .focuswidget import FocusWidget
1313
from .telescopewidget import TelescopeWidget
1414
from .weatherwidget import WeatherWidget
15+
from .modulegui import ModuleGUI

pyobs_gui/mainwindow.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
IVideo,
1919
IAutonomous,
2020
ISpectrograph,
21+
IFilters,
2122
)
2223
from pyobs.vfs import VirtualFileSystem
2324
from .base import BaseWindow, BaseWidget
2425
from .camerawidget import CameraWidget
26+
from .filterwidget import FilterWidget
2527
from .statuswidget import StatusWidget
2628
from .telescopewidget import TelescopeWidget
2729
from .focuswidget import FocusWidget
@@ -43,6 +45,7 @@
4345
IWeather: WeatherWidget,
4446
IVideo: VideoWidget,
4547
ISpectrograph: SpectrographWidget,
48+
IFilters: FilterWidget,
4649
}
4750

4851
DEFAULT_ICONS = {
@@ -54,6 +57,7 @@
5457
IWeather: "fa5s.cloud-sun",
5558
IVideo: "fa5s.video",
5659
ISpectrograph: "ei.graph",
60+
IFilters: "ei.graph",
5761
}
5862

5963

@@ -314,9 +318,7 @@ async def _check_warnings(self) -> None:
314318
autonomous_clients = await self.comm.clients_with_interface(IAutonomous)
315319
self.mastermind_running = False
316320
for auto_client in autonomous_clients:
317-
proxy = await self.comm.safe_proxy(
318-
auto_client, IAutonomous
319-
)
321+
proxy = await self.comm.safe_proxy(auto_client, IAutonomous)
320322
if await proxy.is_running():
321323
self.mastermind_running = True
322324
break

pyobs_gui/modulegui.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
from __future__ import annotations
2+
import asyncio
3+
import sys
4+
from typing import List, Dict, Tuple, Any, Optional
5+
6+
import qasync
7+
from qasync import QEventLoop # type: ignore
8+
from PyQt5 import QtWidgets, QtGui
9+
10+
from pyobs.interfaces import IFitsHeaderBefore
11+
from pyobs.modules import Module
12+
from .base import BaseWindow
13+
from .mainwindow import MainWindow, DEFAULT_WIDGETS
14+
15+
16+
class ModuleWindow(QtWidgets.QMainWindow, BaseWindow):
17+
def __init__(self, gui_module: ModuleGUI, **kwargs: Any):
18+
QtWidgets.QMainWindow.__init__(self)
19+
BaseWindow.__init__(self)
20+
self.gui_module = gui_module
21+
22+
async def open(self, module: Optional[Module] = None, **kwargs: Any) -> None:
23+
"""Open module."""
24+
25+
# what do we have?
26+
widget, icon = None, None
27+
for interface, klass in DEFAULT_WIDGETS.items():
28+
if isinstance(module, interface):
29+
widget = self.create_widget(klass)
30+
self.setCentralWidget(widget)
31+
break
32+
33+
# open widgets
34+
await BaseWindow.open(self, module=module, **kwargs)
35+
36+
def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
37+
self.gui_module.quit()
38+
39+
40+
class ModuleGUI(Module, IFitsHeaderBefore):
41+
__module__ = "pyobs_gui"
42+
43+
app: Optional[QtWidgets.QApplication] = None
44+
45+
def __init__(
46+
self,
47+
module: Dict[str, Any],
48+
*args: Any,
49+
**kwargs: Any,
50+
):
51+
"""Inits a new module GUI.
52+
53+
Args:
54+
show_shell: Whether to show the shell page.
55+
show_events: Whether to show the events page.
56+
show_modules: If not empty, show only listed modules.
57+
widgets: List of custom widgets.
58+
sidebar: List of custom sidebar widgets.
59+
"""
60+
61+
# init module
62+
Module.__init__(self, *args, **kwargs)
63+
self._window: Optional[MainWindow] = None
64+
self._module = self.add_child_object(module, Module, own_comm=False)
65+
66+
@staticmethod
67+
def new_event_loop() -> asyncio.AbstractEventLoop:
68+
ModuleGUI.app = QtWidgets.QApplication(sys.argv)
69+
return qasync.QEventLoop(ModuleGUI.app)
70+
71+
async def open(self) -> None:
72+
"""Open module."""
73+
await Module.open(self)
74+
75+
# open module
76+
await self._module.open()
77+
78+
# create new mainwindow
79+
self._window = ModuleWindow(self)
80+
await self._window.open(
81+
module=self._module,
82+
comm=self.comm,
83+
vfs=self.vfs,
84+
observer=self.observer,
85+
)
86+
self._window.show()
87+
88+
async def get_fits_header_before(
89+
self, namespaces: Optional[List[str]] = None, **kwargs: Any
90+
) -> Dict[str, Tuple[Any, str]]:
91+
"""Returns FITS header for the current status of this module.
92+
93+
Args:
94+
namespaces: If given, only return FITS headers for the given namespaces.
95+
96+
Returns:
97+
Dictionary containing FITS headers.
98+
"""
99+
if self._window is not None:
100+
return self._window.get_fits_headers(namespaces)
101+
else:
102+
return {}

pyobs_gui/videowidget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async def _init(self) -> None:
100100

101101
# we heed a HttpFile
102102
if not isinstance(video_file, HttpFile):
103-
log.error("VFS path to video of module %s must be an HttpFile.", cast(Module, self.module).name())
103+
log.error("VFS path to video of module %s must be an HttpFile.", cast(Module, self.module).name)
104104
return
105105

106106
# analyse URL
@@ -109,7 +109,7 @@ async def _init(self) -> None:
109109
# scheme must be http
110110
# TODO: how to do HTTPS?
111111
if o.scheme != "http":
112-
log.error("URL scheme to video of module %s must be HTTP.", cast(Module, self.module).name())
112+
log.error("URL scheme to video of module %s must be HTTP.", cast(Module, self.module).name)
113113
return
114114

115115
# get info

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pyobs-gui"
3-
version = "1.0.0"
3+
version = "1.0.2"
44
description = "A remote GUI for pyobs"
55
authors = ["Tim-Oliver Husser <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)