-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroofwidget.py
More file actions
70 lines (53 loc) · 2.16 KB
/
roofwidget.py
File metadata and controls
70 lines (53 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from typing import Any, Optional
from PyQt5 import QtWidgets
from PyQt5.QtCore import pyqtSignal
from pyobs.interfaces import IDome, IMotion
from pyobs.utils.enums import MotionStatus
from .base import BaseWidget
from .qt.roofwidget_ui import Ui_RoofWidget
class RoofWidget(QtWidgets.QWidget, BaseWidget, Ui_RoofWidget):
signal_update_gui = pyqtSignal()
def __init__(self, **kwargs: Any):
QtWidgets.QWidget.__init__(self)
BaseWidget.__init__(self, update_func=self._update, **kwargs)
self.setupUi(self)
# status
self.motion_status: Optional[MotionStatus] = None
self.azimuth: Optional[float] = None
self.signal_update_gui.connect(self.update_gui)
async def _init(self) -> None:
# connect signals
if isinstance(self.module, IMotion):
self.buttonOpen.clicked.connect(self.open_roof)
self.buttonClose.clicked.connect(self.close_roof)
self.buttonStop.clicked.connect(self.stop_roof)
# get status and update gui
if isinstance(self.module, IMotion):
self.motion_status = await self.module.get_motion_status()
self.signal_update_gui.emit()
async def _update(self) -> None:
# azimuth and motion status
if isinstance(self.module, IMotion):
self.motion_status = await self.module.get_motion_status()
if isinstance(self.module, IDome):
_, self.azimuth = await self.module.get_altaz()
# signal GUI update
self.signal_update_gui.emit()
def update_gui(self) -> None:
"""Update the GUI."""
# enable myself
self.setEnabled(True)
# set status
if self.motion_status is not None:
self.labelStatus.setText(self.motion_status.value)
# open
if self.azimuth is None:
self.labelAzimuth.setText("N/A")
else:
self.labelAzimuth.setText("%.1f°" % self.azimuth)
def open_roof(self):
self.run_background(self.module.init)
def close_roof(self):
self.run_background(self.module.park)
def stop_roof(self):
self.run_background(self.module.stop_motion)