source: sasview/src/sas/qtgui/MainWindow/MainWindow.py @ 09b7da68

ESS_GUIESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_sync_sascalc
Last change on this file since 09b7da68 was 09b7da68, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 5 years ago

Move menu items around SASVIEW-1220 and trac-941.
Renamed main window name from MainWindow? to SasView?.

  • Property mode set to 100644
File size: 2.8 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    # Main must have reference to the splash screen, so making it explicit
59    splash = SplashScreen()
60    splash.show()
61    app.setAttribute(Qt.AA_EnableHighDpiScaling)
62    # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
63    import sys
64    if 'twisted.internet.reactor' in sys.modules:
65        del sys.modules['twisted.internet.reactor']
66
67    # DO NOT move the following import to the top!
68    # (unless you know what you're doing)
69    import qt5reactor
70    # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor
71    qt5reactor.install()
72
73    # DO NOT move the following import to the top!
74    from twisted.internet import reactor
75
76    # Show the main SV window
77    mainwindow = MainSasViewWindow()
78    mainwindow.showMaximized()
79
80    # no more splash screen
81    splash.finish(mainwindow)
82
83    # Time for the welcome window
84    mainwindow.guiManager.showWelcomeMessage()
85
86    # No need to .exec_ - the reactor takes care of it.
87    reactor.run()
88
89if __name__ == "__main__":
90    run_sasview()
Note: See TracBrowser for help on using the repository browser.