source: sasview/src/sas/qtgui/MainWindow/MainWindow.py @ 8137a02

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

Reverting menu items on OSX

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