1 | # UNLESS EXEPTIONALLY REQUIRED TRY TO AVOID IMPORTING ANY MODULES HERE |
---|
2 | # ESPECIALLY ANYTHING IN SAS, SASMODELS NAMESPACE |
---|
3 | from PyQt4 import QtGui |
---|
4 | |
---|
5 | # Local UI |
---|
6 | from UI.MainWindowUI import Ui_MainWindow |
---|
7 | |
---|
8 | # Initialize logging |
---|
9 | import SasviewLogger |
---|
10 | |
---|
11 | def 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 | |
---|
50 | class 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 | if self.guiManager.quitApplication(): |
---|
68 | event.accept() |
---|
69 | else: |
---|
70 | event.ignore() |
---|
71 | |
---|
72 | |
---|
73 | def SplashScreen(): |
---|
74 | """ |
---|
75 | Displays splash screen as soon as humanely possible. |
---|
76 | The screen will disappear as soon as the event loop starts. |
---|
77 | """ |
---|
78 | pixmap = QtGui.QPixmap("images/SVwelcome_mini.png") |
---|
79 | splashScreen = QtGui.QSplashScreen(pixmap) |
---|
80 | return splashScreen |
---|
81 | |
---|
82 | |
---|
83 | if __name__ == "__main__": |
---|
84 | app = QtGui.QApplication([]) |
---|
85 | |
---|
86 | # Main must have reference to the splash screen, so making it explicit |
---|
87 | splash = SplashScreen() |
---|
88 | splash.show() |
---|
89 | |
---|
90 | # DO NOT move the following import to the top! |
---|
91 | # (unless you know what you're doing) |
---|
92 | import qt4reactor |
---|
93 | # Using the Qt4 reactor wrapper from https://github.com/ghtdak/qtreactor |
---|
94 | qt4reactor.install() |
---|
95 | |
---|
96 | # DO NOT move the following import to the top! |
---|
97 | from twisted.internet import reactor |
---|
98 | |
---|
99 | # Show the main SV window |
---|
100 | mainwindow = MainSasViewWindow(reactor) |
---|
101 | #mainwindow.show() |
---|
102 | mainwindow.showMaximized() |
---|
103 | |
---|
104 | # no more splash screen |
---|
105 | splash.finish(mainwindow) |
---|
106 | |
---|
107 | # No need to .exec_ - the reactor takes care of it. |
---|
108 | reactor.run() |
---|
109 | |
---|