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@…>, 5 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
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
[33812c3]8from PyQt5.QtCore import Qt
[b14db78]9import os
[a80e182]10import sys
[f721030]11# Local UI
[cd2cc745]12from sas.qtgui.UI import main_resources_rc
[09b7da68]13from .UI.MainWindowUI import Ui_SasView
[f721030]14
[09b7da68]15class MainSasViewWindow(QMainWindow, Ui_SasView):
[f721030]16    # Main window of the application
[6fd4e36]17    def __init__(self, parent=None):
[f721030]18        super(MainSasViewWindow, self).__init__(parent)
[f51ed67]19        self.setupUi(self)
[a95260d]20
[f721030]21        # define workspace for dialogs.
[4992ff2]22        self.workspace = QMdiArea(self)
[f721030]23        self.setCentralWidget(self.workspace)
24
[a80e182]25        # Temporary solution for problem with menubar on Mac
26        if sys.platform == "darwin":  # Mac
27            self.menubar.setNativeMenuBar(False)
28
[f721030]29        # Create the gui manager
[b3e8629]30        from .GuiManager import GuiManager
[4992ff2]31        try:
32            self.guiManager = GuiManager(self)
33        except Exception as ex:
[53c771e]34            import logging
[3d18691]35            logging.error("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
[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    """
[b14db78]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)
[4992ff2]52    splashScreen = QSplashScreen(pixmap)
[f721030]53    return splashScreen
54
[a3221b6]55def run_sasview():
[4992ff2]56    app = QApplication([])
[f721030]57
58    # Main must have reference to the splash screen, so making it explicit
59    splash = SplashScreen()
60    splash.show()
[33812c3]61    app.setAttribute(Qt.AA_EnableHighDpiScaling)
[33c0561]62
[2a8bd705]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
[f721030]68    # DO NOT move the following import to the top!
69    # (unless you know what you're doing)
[4992ff2]70    import qt5reactor
[d6b8a1d]71    # Using the Qt5 reactor wrapper from https://github.com/ghtdak/qtreactor
[4992ff2]72    qt5reactor.install()
[f721030]73
74    # DO NOT move the following import to the top!
75    from twisted.internet import reactor
76
77    # Show the main SV window
[6fd4e36]78    mainwindow = MainSasViewWindow()
[8353d90]79    mainwindow.showMaximized()
[f721030]80
81    # no more splash screen
82    splash.finish(mainwindow)
83
[8353d90]84    # Time for the welcome window
85    mainwindow.guiManager.showWelcomeMessage()
86
[f721030]87    # No need to .exec_ - the reactor takes care of it.
88    reactor.run()
89
[31c5b58]90if __name__ == "__main__":
[a3221b6]91    run_sasview()
Note: See TracBrowser for help on using the repository browser.