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_MainWindow |
---|
14 | |
---|
15 | class MainSasViewWindow(QMainWindow, Ui_MainWindow): |
---|
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 | # Main must have reference to the splash screen, so making it explicit |
---|
59 | splash = SplashScreen() |
---|
60 | splash.show() |
---|
61 | app.setAttribute(Qt.AA_EnableHighDpiScaling) |
---|
62 | # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError |
---|
63 | import sys |
---|
64 | if 'twisted.internet.reactor' in sys.modules: |
---|
65 | del sys.modules['twisted.internet.reactor'] |
---|
66 | |
---|
67 | # DO NOT move the following import to the top! |
---|
68 | # (unless you know what you're doing) |
---|
69 | import qt5reactor |
---|
70 | # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor |
---|
71 | qt5reactor.install() |
---|
72 | |
---|
73 | # DO NOT move the following import to the top! |
---|
74 | from twisted.internet import reactor |
---|
75 | |
---|
76 | # Show the main SV window |
---|
77 | mainwindow = MainSasViewWindow() |
---|
78 | mainwindow.showMaximized() |
---|
79 | |
---|
80 | # no more splash screen |
---|
81 | splash.finish(mainwindow) |
---|
82 | |
---|
83 | # Time for the welcome window |
---|
84 | mainwindow.guiManager.showWelcomeMessage() |
---|
85 | |
---|
86 | # No need to .exec_ - the reactor takes care of it. |
---|
87 | reactor.run() |
---|
88 | |
---|
89 | if __name__ == "__main__": |
---|
90 | run_sasview() |
---|