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