source: sasview/src/sas/qtgui/MainWindow/MainWindow.py @ 6c7ebb88

Last change on this file since 6c7ebb88 was d541324e, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 6 years ago

Make the event loop interruptable quickly.

  • Property mode set to 100644
File size: 2.9 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
8from PyQt5.QtCore import Qt
9import os
10import sys
11# Local UI
12from sas.qtgui.UI import main_resources_rc
13from .UI.MainWindowUI import Ui_SasView
14
15class MainSasViewWindow(QMainWindow, Ui_SasView):
16    # Main window of the application
17    def __init__(self, parent=None):
18        super(MainSasViewWindow, self).__init__(parent)
19        self.setupUi(self)
20
21        # define workspace for dialogs.
22        self.workspace = QMdiArea(self)
23        self.setCentralWidget(self.workspace)
24
25        # Temporary solution for problem with menubar on Mac
26        if sys.platform == "darwin":  # Mac
27            self.menubar.setNativeMenuBar(False)
28
29        # Create the gui manager
30        from .GuiManager import GuiManager
31        try:
32            self.guiManager = GuiManager(self)
33        except Exception as ex:
34            import logging
35            logging.error("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
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    pixmap_path = "images/SVwelcome_mini.png"
49    if os.path.splitext(sys.argv[0])[1].lower() == ".py":
50        pixmap_path = "src/sas/qtgui/images/SVwelcome_mini.png"
51    pixmap = QPixmap(pixmap_path)
52    splashScreen = QSplashScreen(pixmap)
53    return splashScreen
54
55def run_sasview():
56    app = QApplication([])
57
58    # Make the event loop interruptable quickly
59    import signal
60    signal.signal(signal.SIGINT, signal.SIG_DFL)
61
62    # Main must have reference to the splash screen, so making it explicit
63    splash = SplashScreen()
64    splash.show()
65    app.setAttribute(Qt.AA_EnableHighDpiScaling)
66
67    # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
68    import sys
69    if 'twisted.internet.reactor' in sys.modules:
70        del sys.modules['twisted.internet.reactor']
71
72    # DO NOT move the following import to the top!
73    # (unless you know what you're doing)
74    import qt5reactor
75    # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor
76    qt5reactor.install()
77
78    # DO NOT move the following import to the top!
79    from twisted.internet import reactor
80
81    # Show the main SV window
82    mainwindow = MainSasViewWindow()
83    mainwindow.showMaximized()
84
85    # no more splash screen
86    splash.finish(mainwindow)
87
88    # Time for the welcome window
89    mainwindow.guiManager.showWelcomeMessage()
90
91    # No need to .exec_ - the reactor takes care of it.
92    reactor.run()
93
94if __name__ == "__main__":
95    run_sasview()
Note: See TracBrowser for help on using the repository browser.