source: sasview/src/sas/qtgui/MainWindow/MainWindow.py @ 1431dab

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 1431dab was a3221b6, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Package SasView? with pyinstaller now. SASVIEW-906.
Minor issue with JupyterConsole? remaining.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1# UNLESS EXEPTIONALLY REQUIRED TRY TO AVOID IMPORTING ANY MODULES HERE
2# ESPECIALLY ANYTHING IN SAS, SASMODELS NAMESPACE
3from PyQt5.QtWidgets import QMainWindow
4from PyQt5.QtWidgets import QMdiArea
5from PyQt5.QtWidgets import QSplashScreen
6from PyQt5.QtWidgets import QApplication
7from PyQt5.QtGui import QPixmap
8
9# Local UI
10from sas.qtgui.UI import main_resources_rc
11from .UI.MainWindowUI import Ui_MainWindow
12
13# Initialize logging
14import sas.qtgui.Utilities.SasviewLogger
15
16class MainSasViewWindow(QMainWindow, Ui_MainWindow):
17    # Main window of the application
18    def __init__(self, parent=None):
19        super(MainSasViewWindow, self).__init__(parent)
20        self.setupUi(self)
21
22        # define workspace for dialogs.
23        self.workspace = QMdiArea(self)
24        self.setCentralWidget(self.workspace)
25
26        # Create the gui manager
27        from .GuiManager import GuiManager
28        try:
29            self.guiManager = GuiManager(self)
30        except Exception as ex:
31            import logging
32            logging.error("Application failed with: " + str(ex))
33            print("Application failed with: ", ex)
34
35    def closeEvent(self, event):
36        if self.guiManager.quitApplication():
37            event.accept()
38        else:
39            event.ignore()
40
41
42def SplashScreen():
43    """
44    Displays splash screen as soon as humanely possible.
45    The screen will disappear as soon as the event loop starts.
46    """
47    # TODO: standardize path to images
48    pixmap = QPixmap("src/sas/qtgui/images/SVwelcome_mini.png")
49    splashScreen = QSplashScreen(pixmap)
50    return splashScreen
51
52def run_sasview():
53    app = QApplication([])
54
55    # Main must have reference to the splash screen, so making it explicit
56    splash = SplashScreen()
57    splash.show()
58
59    # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
60    import sys
61    if 'twisted.internet.reactor' in sys.modules:
62        del sys.modules['twisted.internet.reactor']
63
64    # DO NOT move the following import to the top!
65    # (unless you know what you're doing)
66    import qt5reactor
67    # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor
68    qt5reactor.install()
69
70    # DO NOT move the following import to the top!
71    from twisted.internet import reactor
72
73    # Show the main SV window
74    mainwindow = MainSasViewWindow()
75    mainwindow.showMaximized()
76
77    # no more splash screen
78    splash.finish(mainwindow)
79
80    # Time for the welcome window
81    mainwindow.guiManager.showWelcomeMessage()
82
83    # No need to .exec_ - the reactor takes care of it.
84    reactor.run()
85
86if __name__ == "__main__":
87    run_sasview()
Note: See TracBrowser for help on using the repository browser.