[f721030] | 1 | # UNLESS EXEPTIONALLY REQUIRED TRY TO AVOID IMPORTING ANY MODULES HERE |
---|
| 2 | # ESPECIALLY ANYTHING IN SAS, SASMODELS NAMESPACE |
---|
[4992ff2] | 3 | #from PyQt4 import QtGui |
---|
| 4 | from PyQt5.QtWidgets import * |
---|
| 5 | from PyQt5.QtGui import * |
---|
[f721030] | 6 | |
---|
| 7 | # Local UI |
---|
[cd2cc745] | 8 | from sas.qtgui.UI import main_resources_rc |
---|
[b3e8629] | 9 | from .UI.MainWindowUI import Ui_MainWindow |
---|
[f721030] | 10 | |
---|
[0cd8612] | 11 | # Initialize logging |
---|
[83eb5208] | 12 | import sas.qtgui.Utilities.SasviewLogger |
---|
[0cd8612] | 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 | |
---|
| 24 | # Create the gui manager |
---|
[b3e8629] | 25 | from .GuiManager import GuiManager |
---|
[4992ff2] | 26 | try: |
---|
| 27 | self.guiManager = GuiManager(self) |
---|
| 28 | except Exception as ex: |
---|
[53c771e] | 29 | import logging |
---|
| 30 | logging.error("Application failed with: ", ex) |
---|
| 31 | print("Application failed with: ", ex) |
---|
[f721030] | 32 | |
---|
[9e426c1] | 33 | def closeEvent(self, event): |
---|
[7451b88] | 34 | if self.guiManager.quitApplication(): |
---|
| 35 | event.accept() |
---|
| 36 | else: |
---|
| 37 | event.ignore() |
---|
[481ff26] | 38 | |
---|
[a95260d] | 39 | |
---|
[f721030] | 40 | def SplashScreen(): |
---|
| 41 | """ |
---|
| 42 | Displays splash screen as soon as humanely possible. |
---|
| 43 | The screen will disappear as soon as the event loop starts. |
---|
| 44 | """ |
---|
[31c5b58] | 45 | # TODO: standardize path to images |
---|
[4992ff2] | 46 | pixmap = QPixmap("src/sas/qtgui/images/SVwelcome_mini.png") |
---|
| 47 | splashScreen = QSplashScreen(pixmap) |
---|
[f721030] | 48 | return splashScreen |
---|
| 49 | |
---|
[31c5b58] | 50 | def run(): |
---|
[4992ff2] | 51 | app = QApplication([]) |
---|
[f721030] | 52 | |
---|
| 53 | # Main must have reference to the splash screen, so making it explicit |
---|
| 54 | splash = SplashScreen() |
---|
| 55 | splash.show() |
---|
| 56 | |
---|
[2a8bd705] | 57 | # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError |
---|
| 58 | import sys |
---|
| 59 | if 'twisted.internet.reactor' in sys.modules: |
---|
| 60 | del sys.modules['twisted.internet.reactor'] |
---|
| 61 | |
---|
[f721030] | 62 | # DO NOT move the following import to the top! |
---|
| 63 | # (unless you know what you're doing) |
---|
[4992ff2] | 64 | import qt5reactor |
---|
[d6b8a1d] | 65 | # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor |
---|
[4992ff2] | 66 | qt5reactor.install() |
---|
[f721030] | 67 | |
---|
| 68 | # DO NOT move the following import to the top! |
---|
| 69 | from twisted.internet import reactor |
---|
| 70 | |
---|
| 71 | # Show the main SV window |
---|
[6fd4e36] | 72 | mainwindow = MainSasViewWindow() |
---|
[fbfc488] | 73 | mainwindow.show() |
---|
[f721030] | 74 | |
---|
| 75 | # no more splash screen |
---|
| 76 | splash.finish(mainwindow) |
---|
| 77 | |
---|
| 78 | # No need to .exec_ - the reactor takes care of it. |
---|
| 79 | reactor.run() |
---|
| 80 | |
---|
[31c5b58] | 81 | if __name__ == "__main__": |
---|
| 82 | run() |
---|