source: sasview/src/sas/qtgui/MainWindow/MainWindow.py @ b14db78

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since b14db78 was b14db78, checked in by piotr, 6 years ago

Fixed splash screen in release.
Fixed dQ data resolution for files with dQ.
SASVIEW-1200

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