[f721030] | 1 | # UNLESS EXEPTIONALLY REQUIRED TRY TO AVOID IMPORTING ANY MODULES HERE |
---|
| 2 | # ESPECIALLY ANYTHING IN SAS, SASMODELS NAMESPACE |
---|
[8353d90] | 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 |
---|
[33812c3] | 8 | from PyQt5.QtCore import Qt |
---|
[b14db78] | 9 | import os |
---|
[a80e182] | 10 | import sys |
---|
[f721030] | 11 | # Local UI |
---|
[cd2cc745] | 12 | from sas.qtgui.UI import main_resources_rc |
---|
[09b7da68] | 13 | from .UI.MainWindowUI import Ui_SasView |
---|
[f721030] | 14 | |
---|
[09b7da68] | 15 | class MainSasViewWindow(QMainWindow, Ui_SasView): |
---|
[f721030] | 16 | # Main window of the application |
---|
[6fd4e36] | 17 | def __init__(self, parent=None): |
---|
[f721030] | 18 | super(MainSasViewWindow, self).__init__(parent) |
---|
[f51ed67] | 19 | self.setupUi(self) |
---|
[a95260d] | 20 | |
---|
[f721030] | 21 | # define workspace for dialogs. |
---|
[4992ff2] | 22 | self.workspace = QMdiArea(self) |
---|
[f721030] | 23 | self.setCentralWidget(self.workspace) |
---|
| 24 | |
---|
[a80e182] | 25 | # Temporary solution for problem with menubar on Mac |
---|
| 26 | if sys.platform == "darwin": # Mac |
---|
| 27 | self.menubar.setNativeMenuBar(False) |
---|
| 28 | |
---|
[f721030] | 29 | # Create the gui manager |
---|
[b3e8629] | 30 | from .GuiManager import GuiManager |
---|
[4992ff2] | 31 | try: |
---|
| 32 | self.guiManager = GuiManager(self) |
---|
| 33 | except Exception as ex: |
---|
[53c771e] | 34 | import logging |
---|
[3d18691] | 35 | logging.error("Application failed with: "+str(ex)) |
---|
[f721030] | 36 | |
---|
[9e426c1] | 37 | def closeEvent(self, event): |
---|
[7451b88] | 38 | if self.guiManager.quitApplication(): |
---|
| 39 | event.accept() |
---|
| 40 | else: |
---|
| 41 | event.ignore() |
---|
[481ff26] | 42 | |
---|
[f721030] | 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 | """ |
---|
[b14db78] | 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) |
---|
[4992ff2] | 52 | splashScreen = QSplashScreen(pixmap) |
---|
[f721030] | 53 | return splashScreen |
---|
| 54 | |
---|
[a3221b6] | 55 | def run_sasview(): |
---|
[4992ff2] | 56 | app = QApplication([]) |
---|
[f721030] | 57 | |
---|
[d541324e] | 58 | # Make the event loop interruptable quickly |
---|
| 59 | import signal |
---|
| 60 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
---|
| 61 | |
---|
[f721030] | 62 | # Main must have reference to the splash screen, so making it explicit |
---|
| 63 | splash = SplashScreen() |
---|
| 64 | splash.show() |
---|
[33812c3] | 65 | app.setAttribute(Qt.AA_EnableHighDpiScaling) |
---|
[33c0561] | 66 | |
---|
[2a8bd705] | 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 | |
---|
[f721030] | 72 | # DO NOT move the following import to the top! |
---|
| 73 | # (unless you know what you're doing) |
---|
[4992ff2] | 74 | import qt5reactor |
---|
[d6b8a1d] | 75 | # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor |
---|
[4992ff2] | 76 | qt5reactor.install() |
---|
[f721030] | 77 | |
---|
| 78 | # DO NOT move the following import to the top! |
---|
| 79 | from twisted.internet import reactor |
---|
| 80 | |
---|
| 81 | # Show the main SV window |
---|
[6fd4e36] | 82 | mainwindow = MainSasViewWindow() |
---|
[8353d90] | 83 | mainwindow.showMaximized() |
---|
[f721030] | 84 | |
---|
| 85 | # no more splash screen |
---|
| 86 | splash.finish(mainwindow) |
---|
| 87 | |
---|
[8353d90] | 88 | # Time for the welcome window |
---|
| 89 | mainwindow.guiManager.showWelcomeMessage() |
---|
| 90 | |
---|
[f721030] | 91 | # No need to .exec_ - the reactor takes care of it. |
---|
| 92 | reactor.run() |
---|
| 93 | |
---|
[31c5b58] | 94 | if __name__ == "__main__": |
---|
[a3221b6] | 95 | run_sasview() |
---|