1 | # UNLESS EXEPTIONALLY REQUIRED TRY TO AVOID IMPORTING ANY MODULES HERE |
---|
2 | # ESPECIALLY ANYTHING IN SAS, SASMODELS NAMESPACE |
---|
3 | #from PyQt4 import QtGui |
---|
4 | from PyQt5.QtWidgets import * |
---|
5 | from PyQt5.QtGui import * |
---|
6 | |
---|
7 | # Local UI |
---|
8 | from sas.qtgui.UI import main_resources_rc |
---|
9 | from .UI.MainWindowUI import Ui_MainWindow |
---|
10 | |
---|
11 | # Initialize logging |
---|
12 | import sas.qtgui.Utilities.SasviewLogger |
---|
13 | |
---|
14 | class MainSasViewWindow(QMainWindow, Ui_MainWindow): |
---|
15 | # Main window of the application |
---|
16 | def __init__(self, parent=None): |
---|
17 | super(MainSasViewWindow, self).__init__(parent) |
---|
18 | self.setupUi(self) |
---|
19 | |
---|
20 | # define workspace for dialogs. |
---|
21 | self.workspace = QMdiArea(self) |
---|
22 | self.setCentralWidget(self.workspace) |
---|
23 | |
---|
24 | # Create the gui manager |
---|
25 | from .GuiManager import GuiManager |
---|
26 | try: |
---|
27 | self.guiManager = GuiManager(self) |
---|
28 | except Exception as ex: |
---|
29 | print("EXCEPTION: ", ex) |
---|
30 | |
---|
31 | def closeEvent(self, event): |
---|
32 | if self.guiManager.quitApplication(): |
---|
33 | event.accept() |
---|
34 | else: |
---|
35 | event.ignore() |
---|
36 | |
---|
37 | |
---|
38 | def SplashScreen(): |
---|
39 | """ |
---|
40 | Displays splash screen as soon as humanely possible. |
---|
41 | The screen will disappear as soon as the event loop starts. |
---|
42 | """ |
---|
43 | # TODO: standardize path to images |
---|
44 | pixmap = QPixmap("src/sas/qtgui/images/SVwelcome_mini.png") |
---|
45 | splashScreen = QSplashScreen(pixmap) |
---|
46 | return splashScreen |
---|
47 | |
---|
48 | def run(): |
---|
49 | app = QApplication([]) |
---|
50 | |
---|
51 | # Main must have reference to the splash screen, so making it explicit |
---|
52 | splash = SplashScreen() |
---|
53 | splash.show() |
---|
54 | |
---|
55 | # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError |
---|
56 | import sys |
---|
57 | if 'twisted.internet.reactor' in sys.modules: |
---|
58 | del sys.modules['twisted.internet.reactor'] |
---|
59 | |
---|
60 | # DO NOT move the following import to the top! |
---|
61 | # (unless you know what you're doing) |
---|
62 | import qt5reactor |
---|
63 | # Using the Qt4 reactor wrapper from https://github.com/ghtdak/qtreactor |
---|
64 | qt5reactor.install() |
---|
65 | |
---|
66 | # DO NOT move the following import to the top! |
---|
67 | from twisted.internet import reactor |
---|
68 | |
---|
69 | # Show the main SV window |
---|
70 | mainwindow = MainSasViewWindow() |
---|
71 | mainwindow.showMaximized() |
---|
72 | |
---|
73 | # no more splash screen |
---|
74 | splash.finish(mainwindow) |
---|
75 | |
---|
76 | # No need to .exec_ - the reactor takes care of it. |
---|
77 | reactor.run() |
---|
78 | |
---|
79 | if __name__ == "__main__": |
---|
80 | run() |
---|