/[ascend]/branches/adrian/pygtk/canvas/canvas.py
ViewVC logotype

Contents of /branches/adrian/pygtk/canvas/canvas.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2891 - (show annotations) (download) (as text)
Fri Apr 10 19:32:37 2015 UTC (3 years, 10 months ago) by adrian
File MIME type: text/x-python
File size: 2273 byte(s)
Ported all files, probably there are bugs
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 from gi.repository import Gtk
8
9 os.chdir(os.path.abspath(os.path.dirname(sys.argv[0])))
10
11 DEFAULT_LIBRARY = 'brayton_fprops_rachel.a4c'
12
13 #Remove this sometime
14 DEFAULT_CANVAS_MODEL_LIBRARY = os.path.join('..','..','models','test','canvas')
15
16 '''Set the required paths'''
17 try:
18 os.environ['ASCENDLIBRARY']
19 os.environ['LD_LIBRARY_PATH']
20 except KeyError:
21 os.environ['ASCENDLIBRARY'] = os.path.join('..','..','models')
22 os.environ['LD_LIBRARY_PATH'] = os.path.join('..','..')
23 os.environ['ASCENDSOLVERS'] = os.path.join('..','..','solvers','qrslv')
24
25 sys.path.append("..")
26 sys.path.append("../../ascxx")
27
28 if sys.platform.startswith("win"):
29 # Fetchs gtk2 path from registry
30 import _winreg
31 import msvcrt
32 try:
33 k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\GTK\\2.0")
34 except EnvironmentError:
35 # use TkInter to report the error :-)
36 from TkInter import *
37 root = Tk()
38 w = Label(root,"You must install the Gtk+ 2.2 Runtime Environment to run this program")
39 w.pack()
40 root.mainloop()
41 sys.exit(1)
42 else:
43 gtkdir = _winreg.QueryValueEx(k, "Path")
44 import os
45 # we must make sure the gtk2 path is the first thing in the path
46 # otherwise, we can get errors if the system finds other libs with
47 # the same name in the path...
48 os.environ['PATH'] = "%s/lib;%s/bin;" % (gtkdir[0], gtkdir[0]) + os.environ['PATH']
49
50 class Application(object):
51
52 def __init__(self,options):
53 from asclibrary import ascPy
54 from blocklist import mainWindow
55 self.ascwrap = ascPy()
56 self.window = mainWindow(self.ascwrap)
57 if options.library:
58 print options.library
59 self.window.loadlib(lib_name=options.library)
60 else:
61 self.window.loadlib(lib_name=DEFAULT_LIBRARY)
62
63 if options.file:
64 self.window.load_canvas_file(options.file)
65
66 def run(self):
67 Gtk.main()
68
69 if __name__ == '__main__':
70 from optparse import OptionParser
71 parser = OptionParser()
72 parser.add_option('-f','--file',dest='file')
73 parser.add_option('-l','--library',dest='library')
74 (options,args) = parser.parse_args()
75 _Application = Application(options)
76 _Application.run()

Properties

Name Value
svn:executable *

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22