|
14 | 14 | from PyQt5.QtWidgets import QWidget, QSizePolicy, QVBoxLayout, QMessageBox
|
15 | 15 | from PyQt5.QtGui import QVector3D
|
16 | 16 | from PyQt5.Qt3DExtras import Qt3DWindow, QOrbitCameraController
|
17 |
| -from PyQt5.QtCore import Qt, QThread, pyqtSlot |
| 17 | +from PyQt5.QtCore import Qt, QThread, pyqtSignal, pyqtSlot |
18 | 18 |
|
19 | 19 | # Astropy stuff
|
20 | 20 | from astropy import units as u
|
|
43 | 43 |
|
44 | 44 |
|
45 | 45 | class MainWindow(QMainWindow):
|
46 |
| - def __init__(self, view3D, camera_widget=None, dashboard_widget=None): |
| 46 | + |
| 47 | + closing = pyqtSignal() |
| 48 | + |
| 49 | + def __init__(self, view3D=None, camera_widget=None, dashboard_widget=None): |
47 | 50 | super().__init__()
|
48 | 51 |
|
49 | 52 | # Various views/widgets
|
50 | 53 | self.view3D = view3D
|
51 | 54 | self.camera_widget = camera_widget
|
| 55 | + self.closing.connect(self.camera_widget.close) |
52 | 56 | self.dashboard_widget = dashboard_widget
|
53 | 57 |
|
54 | 58 | # Change visual parameters and setup widgets on the main window
|
@@ -79,39 +83,43 @@ def init_UI(self):
|
79 | 83 | self.helpMenu.addAction(self.creditsAct)
|
80 | 84 |
|
81 | 85 | # General layout
|
82 |
| - self.layout = QVBoxLayout() |
83 |
| - |
84 |
| - # 3D view |
85 |
| - #self.dock_view3D = QDockWidget('Mount simulator', self) |
86 |
| - #self.addDockWidget(Qt.BottomDockWidgetArea, self.dock_view3D) |
87 |
| - self.widget3D = QWidget.createWindowContainer(self.view3D.window, self) |
88 |
| - #self.widget3D.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) |
89 |
| - #self.dock_view3D.setWidget(self.widget3D) |
90 |
| - self.setCentralWidget(self.widget3D) |
91 |
| - #self.layout.addWidget(self.widget3D) |
92 |
| - |
93 |
| - # Dock safety camera on the right |
| 86 | + #self.layout = QVBoxLayout() |
| 87 | + |
| 88 | + # Webbrowser for dashboard should be the main widget |
| 89 | + if self.dashboard_widget is not None: |
| 90 | + #self.dock_dashboard = QDockWidget('Main dashboard', self) |
| 91 | + #self.addDockWidget(Qt.RightDockWidgetArea, self.dock_dashboard) |
| 92 | + #self.dashboard_widget.setSizePolicy(QSizePolicy.Fixed, |
| 93 | + # QSizePolicy.Fixed) |
| 94 | + #self.dock_dashboard.setWidget(self.dashboard_widget) |
| 95 | + self.setCentralWidget(self.dashboard_widget) |
| 96 | + |
| 97 | + # Dock safety camera on the Left |
94 | 98 | if self.camera_widget is not None:
|
95 | 99 | self.dock_camera = QDockWidget('Surveillance camera', self)
|
96 | 100 | self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_camera)
|
97 | 101 | #self.camera_widget.setSizePolicy(QSizePolicy.Fixed,
|
98 | 102 | # QSizePolicy.Fixed)
|
99 | 103 | self.dock_camera.setWidget(self.camera_widget)
|
100 | 104 |
|
101 |
| - # Dock webbrowser for dashboard on the right |
102 |
| - if self.dashboard_widget is not None: |
103 |
| - self.dock_dashboard = QDockWidget('Main dashboard', self) |
104 |
| - self.addDockWidget(Qt.RightDockWidgetArea, self.dock_dashboard) |
105 |
| - #self.dashboard_widget.setSizePolicy(QSizePolicy.Fixed, |
106 |
| - # QSizePolicy.Fixed) |
107 |
| - self.dock_dashboard.setWidget(self.dashboard_widget) |
| 105 | + # 3D view set as right widget |
| 106 | + if self.view3D is not None: |
| 107 | + self.widget3D = QWidget.createWindowContainer(self.view3D.window, self) |
| 108 | + self.dock_view3D = QDockWidget('Mount simulator', self) |
| 109 | + self.addDockWidget(Qt.RightDockWidgetArea, self.dock_view3D) |
| 110 | + #self.widget3D.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) |
| 111 | + self.dock_view3D.setWidget(self.widget3D) |
| 112 | + #self.setCentralWidget(self.widget3D) |
| 113 | + #self.layout.addWidget(self.widget3D) |
108 | 114 |
|
109 | 115 | # Global stuff
|
110 |
| - self.setLayout(self.layout) |
| 116 | + #self.setLayout(self.layout) |
111 | 117 | self.setWindowTitle('Remote observatory dashboard')
|
112 | 118 | self.show()
|
113 | 119 |
|
114 | 120 | def closeEvent(self, event):
|
| 121 | + # emit a signal for registered custom slot to perform cleanup if needed |
| 122 | + self.closing.emit() |
115 | 123 | self.quit()
|
116 | 124 |
|
117 | 125 | def quit(self):
|
@@ -173,6 +181,14 @@ def update_coord(self, coord):
|
173 | 181 |
|
174 | 182 | if __name__ == "__main__":
|
175 | 183 |
|
| 184 | + def trap_exc_during_debug(*args): |
| 185 | + # when app raises uncaught exception, print info |
| 186 | + print(args) |
| 187 | + |
| 188 | + # install exception hook: without this, uncaught exception would cause |
| 189 | + # application to exit |
| 190 | + sys.excepthook = trap_exc_during_debug |
| 191 | + |
176 | 192 | # load the logging configuration
|
177 | 193 | logging.config.fileConfig('logging.ini')
|
178 | 194 |
|
|
0 commit comments