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 | from PyQt5.QtCore import Qt |
---|
9 | import os |
---|
10 | import sys |
---|
11 | # Local UI |
---|
12 | from sas.qtgui.UI import main_resources_rc |
---|
13 | from .UI.MainWindowUI import Ui_SasView |
---|
14 | |
---|
15 | class MainSasViewWindow(QMainWindow, Ui_SasView): |
---|
16 | # Main window of the application |
---|
17 | def __init__(self, parent=None): |
---|
18 | super(MainSasViewWindow, self).__init__(parent) |
---|
19 | self.setupUi(self) |
---|
20 | |
---|
21 | # define workspace for dialogs. |
---|
22 | self.workspace = QMdiArea(self) |
---|
23 | self.setCentralWidget(self.workspace) |
---|
24 | |
---|
25 | # Temporary solution for problem with menubar on Mac |
---|
26 | if sys.platform == "darwin": # Mac |
---|
27 | self.menubar.setNativeMenuBar(False) |
---|
28 | |
---|
29 | # Create the gui manager |
---|
30 | from .GuiManager import GuiManager |
---|
31 | try: |
---|
32 | self.guiManager = GuiManager(self) |
---|
33 | except Exception as ex: |
---|
34 | import logging |
---|
35 | logging.error("Application failed with: "+str(ex)) |
---|
36 | |
---|
37 | def closeEvent(self, event): |
---|
38 | if self.guiManager.quitApplication(): |
---|
39 | event.accept() |
---|
40 | else: |
---|
41 | event.ignore() |
---|
42 | |
---|
43 | def SplashScreen(): |
---|
44 | """ |
---|
45 | Displays splash screen as soon as humanely possible. |
---|
46 | The screen will disappear as soon as the event loop starts. |
---|
47 | """ |
---|
48 | pixmap_path = "images/SVwelcome_mini.png" |
---|
49 | if os.path.splitext(sys.argv[0])[1].lower() == ".py": |
---|
50 | pixmap_path = "src/sas/qtgui/images/SVwelcome_mini.png" |
---|
51 | pixmap = QPixmap(pixmap_path) |
---|
52 | splashScreen = QSplashScreen(pixmap) |
---|
53 | return splashScreen |
---|
54 | |
---|
55 | def run_sasview(): |
---|
56 | app = QApplication([]) |
---|
57 | |
---|
58 | # Make the event loop interruptable quickly |
---|
59 | import signal |
---|
60 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
---|
61 | |
---|
62 | # Main must have reference to the splash screen, so making it explicit |
---|
63 | splash = SplashScreen() |
---|
64 | splash.show() |
---|
65 | app.setAttribute(Qt.AA_EnableHighDpiScaling) |
---|
66 | |
---|
67 | # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError |
---|
68 | import sys |
---|
69 | if 'twisted.internet.reactor' in sys.modules: |
---|
70 | del sys.modules['twisted.internet.reactor'] |
---|
71 | |
---|
72 | # DO NOT move the following import to the top! |
---|
73 | # (unless you know what you're doing) |
---|
74 | import qt5reactor |
---|
75 | # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor |
---|
76 | qt5reactor.install() |
---|
77 | |
---|
78 | # DO NOT move the following import to the top! |
---|
79 | from twisted.internet import reactor |
---|
80 | |
---|
81 | # Show the main SV window |
---|
82 | mainwindow = MainSasViewWindow() |
---|
83 | mainwindow.showMaximized() |
---|
84 | |
---|
85 | # no more splash screen |
---|
86 | splash.finish(mainwindow) |
---|
87 | |
---|
88 | # Time for the welcome window |
---|
89 | mainwindow.guiManager.showWelcomeMessage() |
---|
90 | |
---|
91 | # No need to .exec_ - the reactor takes care of it. |
---|
92 | reactor.run() |
---|
93 | |
---|
94 | if __name__ == "__main__": |
---|
95 | run_sasview() |
---|