source: sasview/src/sas/qtgui/MainWindow/MainWindow.py @ a80e182

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since a80e182 was a80e182, checked in by wojciech, 6 years ago

Reverting menu items on OSX

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