1 |
#!/usr/bin/env python |
2 |
''' This is the main application for the Canvas modeller, it handles the ASCEND solver and the GUI''' |
3 |
|
4 |
from __future__ import with_statement |
5 |
import os |
6 |
import sys |
7 |
import platform |
8 |
|
9 |
import gi |
10 |
gi.require_version('Gtk', '3.0') |
11 |
from gi.repository import Gtk |
12 |
|
13 |
|
14 |
os.chdir(os.path.abspath(os.path.dirname(sys.argv[0]))) |
15 |
|
16 |
DEFAULT_LIBRARY = 'brayton_fprops_rachel.a4c' |
17 |
|
18 |
#Remove this sometime |
19 |
DEFAULT_CANVAS_MODEL_LIBRARY = os.path.join('..','..','models','test','canvas') |
20 |
|
21 |
'''Set the required paths''' |
22 |
try: |
23 |
os.environ['ASCENDLIBRARY'] |
24 |
os.environ['LD_LIBRARY_PATH'] |
25 |
except KeyError: |
26 |
os.environ['ASCENDLIBRARY'] = os.path.join('..','..','models') |
27 |
os.environ['LD_LIBRARY_PATH'] = os.path.join('..','..') |
28 |
os.environ['ASCENDSOLVERS'] = os.path.join('..','..','solvers','qrslv') |
29 |
|
30 |
sys.path.append("..") |
31 |
sys.path.append("../../ascxx") |
32 |
|
33 |
if platform.system() == "Windows": |
34 |
import _winreg as wreg |
35 |
|
36 |
k = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\ASCEND") |
37 |
INSTALL_LIB,t = wreg.QueryValueEx(k,"INSTALL_LIB") |
38 |
INSTALL_SOLVERS,t = wreg.QueryValueEx(k,"INSTALL_SOLVERS") |
39 |
INSTALL_MODELS,t = wreg.QueryValueEx(k,"INSTALL_MODELS") |
40 |
os.environ['PATH'] = os.environ['PATH'] + INSTALL_LIB |
41 |
os.environ['ASCENDLIBRARY'] = INSTALL_MODELS |
42 |
os.environ['ASCENDSOLVERS'] = INSTALL_SOLVERS |
43 |
DEFAULT_CANVAS_MODEL_LIBRARY = os.path.join(INSTALL_MODELS,'test','canvas') |
44 |
|
45 |
class Application(): |
46 |
|
47 |
def __init__(self,options): |
48 |
from asclibrary import ascPy |
49 |
from blocklist import mainWindow |
50 |
self.ascwrap = ascPy() |
51 |
self.window = mainWindow(self.ascwrap) |
52 |
if options.library: |
53 |
print options.library |
54 |
self.window.loadlib(lib_name=options.library) |
55 |
else: |
56 |
self.window.loadlib(lib_name=DEFAULT_LIBRARY) |
57 |
|
58 |
if options.file: |
59 |
self.window.load_canvas_file(options.file) |
60 |
|
61 |
def run(self): |
62 |
Gtk.main() |
63 |
|
64 |
if __name__ == '__main__': |
65 |
from optparse import OptionParser |
66 |
parser = OptionParser() |
67 |
parser.add_option('-f','--file',dest='file') |
68 |
parser.add_option('-l','--library',dest='library') |
69 |
(options,args) = parser.parse_args() |
70 |
_Application = Application(options) |
71 |
_Application.run() |