[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 |
---|
[b3e8629] | 13 | from .UI.MainWindowUI import Ui_MainWindow |
---|
[f721030] | 14 | |
---|
[4992ff2] | 15 | class MainSasViewWindow(QMainWindow, Ui_MainWindow): |
---|
[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 | |
---|
| 58 | # Main must have reference to the splash screen, so making it explicit |
---|
| 59 | splash = SplashScreen() |
---|
| 60 | splash.show() |
---|
[33812c3] | 61 | app.setAttribute(Qt.AA_EnableHighDpiScaling) |
---|
[2a8bd705] | 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 | |
---|
[f721030] | 67 | # DO NOT move the following import to the top! |
---|
| 68 | # (unless you know what you're doing) |
---|
[4992ff2] | 69 | import qt5reactor |
---|
[d6b8a1d] | 70 | # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor |
---|
[4992ff2] | 71 | qt5reactor.install() |
---|
[f721030] | 72 | |
---|
| 73 | # DO NOT move the following import to the top! |
---|
| 74 | from twisted.internet import reactor |
---|
| 75 | |
---|
| 76 | # Show the main SV window |
---|
[6fd4e36] | 77 | mainwindow = MainSasViewWindow() |
---|
[8353d90] | 78 | mainwindow.showMaximized() |
---|
[f721030] | 79 | |
---|
| 80 | # no more splash screen |
---|
| 81 | splash.finish(mainwindow) |
---|
| 82 | |
---|
[8353d90] | 83 | # Time for the welcome window |
---|
| 84 | mainwindow.guiManager.showWelcomeMessage() |
---|
| 85 | |
---|
[f721030] | 86 | # No need to .exec_ - the reactor takes care of it. |
---|
| 87 | reactor.run() |
---|
| 88 | |
---|
[31c5b58] | 89 | if __name__ == "__main__": |
---|
[a3221b6] | 90 | run_sasview() |
---|