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

ESS_GUI_iss879
Last change on this file since c0de493 was c0de493, checked in by celinedurniak <celine.durniak@…>, 10 months ago

Changed Setting of NativeMenuBar? for MacOS

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