source: sasview/src/sas/qtgui/MainWindow.py @ 2366fb2

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 2366fb2 was 2366fb2, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Added a temporary solution for running the new GUI in place.

  • Property mode set to 100644
File size: 3.3 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 UI.MainWindowUI import Ui_MainWindow
7
8# Initialize logging
9import SasviewLogger
10
11def updatePaths():
12    # Update paths
13    # TEMPORARY KLUDGE TO ALLOW INSTALL-LESS RUNS
14    # THIS WILL GO AWAY ONCE MERGED
15    #######################################################################
16    import imp
17    import os
18    import sys
19    def addpath(path):
20        """
21        Add a directory to the python path environment, and to the PYTHONPATH
22        environment variable for subprocesses.
23        """
24        path = os.path.abspath(path)
25        if 'PYTHONPATH' in os.environ:
26            PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH']
27        else:
28            PYTHONPATH = path
29        os.environ['PYTHONPATH'] = PYTHONPATH
30        sys.path.insert(0, path)
31
32    def import_package(modname, path):
33        """Import a package into a particular point in the python namespace"""
34        mod = imp.load_source(modname, os.path.abspath(os.path.join(path,'__init__.py')))
35        sys.modules[modname] = mod
36        mod.__path__ = [os.path.abspath(path)]
37        return mod
38
39    root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
40    addpath(os.path.join(root, 'src'))
41    #addpath(os.path.join(root, '../sasmodels/'))
42    import sas
43    from distutils.util import get_platform
44    sas.sasview = import_package('sas.sasview', os.path.join(root,'sasview'))
45    platform = '%s-%s'%(get_platform(),sys.version[:3])
46    build_path = os.path.join(root, 'build','lib.'+platform)
47    sys.path.append(build_path)
48    #######################################################################
49
50class MainSasViewWindow(QtGui.QMainWindow, Ui_MainWindow):
51    # Main window of the application
52    def __init__(self, reactor, parent=None):
53        super(MainSasViewWindow, self).__init__(parent)
54        self.setupUi(self)
55
56        # define workspace for dialogs.
57        self.workspace = QtGui.QWorkspace(self)
58        self.setCentralWidget(self.workspace)
59
60        updatePaths()
61
62        # Create the gui manager
63        from GuiManager import GuiManager
64        self.guiManager = GuiManager(self, reactor, self)
65
66    def closeEvent(self, event):
67        self.guiManager.quitApplication()
68
69
70def SplashScreen():
71    """
72    Displays splash screen as soon as humanely possible.
73    The screen will disappear as soon as the event loop starts.
74    """
75    pixmap = QtGui.QPixmap("images/SVwelcome_mini.png")
76    splashScreen = QtGui.QSplashScreen(pixmap)
77    return splashScreen
78
79
80if __name__ == "__main__":
81    app = QtGui.QApplication([])
82
83    # Main must have reference to the splash screen, so making it explicit
84    splash = SplashScreen()
85    splash.show()
86
87    # DO NOT move the following import to the top!
88    # (unless you know what you're doing)
89    import qt4reactor
90    # Using the Qt4 reactor wrapper from https://github.com/ghtdak/qtreactor
91    qt4reactor.install()
92
93    # DO NOT move the following import to the top!
94    from twisted.internet import reactor
95
96    # Show the main SV window
97    mainwindow = MainSasViewWindow(reactor)
98    #mainwindow.show()
99    mainwindow.showMaximized()
100
101    # no more splash screen
102    splash.finish(mainwindow)
103
104    # No need to .exec_ - the reactor takes care of it.
105    reactor.run()
106
Note: See TracBrowser for help on using the repository browser.