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@…>, 6 years ago

Changed Setting of NativeMenuBar? for MacOS

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[f721030]1# UNLESS EXEPTIONALLY REQUIRED TRY TO AVOID IMPORTING ANY MODULES HERE
2# ESPECIALLY ANYTHING IN SAS, SASMODELS NAMESPACE
[8353d90]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
[c0de493]8import sys
[f721030]9
10# Local UI
[cd2cc745]11from sas.qtgui.UI import main_resources_rc
[b3e8629]12from .UI.MainWindowUI import Ui_MainWindow
[f721030]13
[4992ff2]14class 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
[c0de493]20        # Temporary solution for problem with menubar on Mac
21        if sys.platform == "darwin":  # Mac
22            self.menubar.setNativeMenuBar(False)
23
[f721030]24        # define workspace for dialogs.
[4992ff2]25        self.workspace = QMdiArea(self)
[f721030]26        self.setCentralWidget(self.workspace)
27
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))
35            print("Application failed with: ", str(ex))
[f721030]36
[9e426c1]37    def closeEvent(self, event):
[7451b88]38        if self.guiManager.quitApplication():
39            event.accept()
40        else:
41            event.ignore()
[481ff26]42
[a95260d]43
[f721030]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    """
[31c5b58]49    # TODO: standardize path to images
[4992ff2]50    pixmap = QPixmap("src/sas/qtgui/images/SVwelcome_mini.png")
51    splashScreen = QSplashScreen(pixmap)
[f721030]52    return splashScreen
53
[a3221b6]54def 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]88if __name__ == "__main__":
[a3221b6]89    run_sasview()
Note: See TracBrowser for help on using the repository browser.