source: sasview/src/sas/qtgui/MainWindow/MainWindow.py @ 33c0561

ESS_GUIESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_sync_sascalc
Last change on this file since 33c0561 was 33c0561, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 4 years ago

Replace Apply button menu driven functionality with additional button.
Removed Cancel.
Removed the window system context help button from all affected widgets.
SASVIEW-1239

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