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