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

Last change on this file since e4a3302 was 2a8bd705, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Changes to allow pyinstaller builds

  • Property mode set to 100644
File size: 2.2 KB
Line 
1# UNLESS EXEPTIONALLY REQUIRED TRY TO AVOID IMPORTING ANY MODULES HERE
2# ESPECIALLY ANYTHING IN SAS, SASMODELS NAMESPACE
3from PyQt4 import QtGui
4
5# Local UI
6from sas.qtgui.UI import main_resources_rc
7from UI.MainWindowUI import Ui_MainWindow
8
9# Initialize logging
10import sas.qtgui.Utilities.SasviewLogger
11
12class MainSasViewWindow(QtGui.QMainWindow, Ui_MainWindow):
13    # Main window of the application
14    def __init__(self, parent=None):
15        super(MainSasViewWindow, self).__init__(parent)
16        self.setupUi(self)
17
18        # define workspace for dialogs.
19        self.workspace = QtGui.QWorkspace(self)
20        self.setCentralWidget(self.workspace)
21
22        # Create the gui manager
23        from GuiManager import GuiManager
24        self.guiManager = GuiManager(self)
25
26    def closeEvent(self, event):
27        if self.guiManager.quitApplication():
28            event.accept()
29        else:
30            event.ignore()
31
32
33def SplashScreen():
34    """
35    Displays splash screen as soon as humanely possible.
36    The screen will disappear as soon as the event loop starts.
37    """
38    # TODO: standardize path to images
39    pixmap = QtGui.QPixmap("src/sas/qtgui/images/SVwelcome_mini.png")
40    splashScreen = QtGui.QSplashScreen(pixmap)
41    return splashScreen
42
43def run():
44    app = QtGui.QApplication([])
45
46    # Main must have reference to the splash screen, so making it explicit
47    splash = SplashScreen()
48    splash.show()
49
50    # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
51    import sys
52    if 'twisted.internet.reactor' in sys.modules:
53        del sys.modules['twisted.internet.reactor']
54
55    # DO NOT move the following import to the top!
56    # (unless you know what you're doing)
57    import qt4reactor
58    # Using the Qt4 reactor wrapper from https://github.com/ghtdak/qtreactor
59    qt4reactor.install()
60
61    # DO NOT move the following import to the top!
62    from twisted.internet import reactor
63
64    # Show the main SV window
65    mainwindow = MainSasViewWindow()
66    mainwindow.showMaximized()
67
68    # no more splash screen
69    splash.finish(mainwindow)
70
71    # No need to .exec_ - the reactor takes care of it.
72    reactor.run()
73
74if __name__ == "__main__":
75    run()
Note: See TracBrowser for help on using the repository browser.