/[ascend]/trunk/pygtk/librarytest.py
ViewVC logotype

Contents of /trunk/pygtk/librarytest.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download) (as text)
Mon Apr 24 02:23:08 2006 UTC (18 years, 1 month ago) by johnpye
File MIME type: text/x-python
File size: 3644 byte(s)
Removed 'interface' directory in trunk/pygtk/interface (moved everything up a level)
Made corresponding changes to SCons* and spec files.
1 #!/usr/bin/python
2 import sys
3
4 import dl
5 sys.setdlopenflags(dl.RTLD_GLOBAL|dl.RTLD_NOW)
6
7 import ascpy
8
9 import gtkbrowser
10
11 print "python: creating new library object\n";
12
13 #----errror callback function-----
14 def error_reporter(sev,filename,line,msg):
15 if(sev==1):
16 leftstr = ""
17 rightstr = "\n"
18 typestr = "Note: "
19 elif(sev==2):
20 leftstr = chr(27)+"[33;2m"
21 rightstr = chr(27)+"[0m\n"
22 typestr = "Warning: "
23 elif(sev==3):
24 leftstr = chr(27)+"[31;1m"
25 rightstr = chr(27)+"[0m\n"
26 typestr = "Error: "
27 elif(sev==4):
28 # this is the default case, so keep it quiet:
29 leftstr = chr(27)+"[33;2m"
30 rightstr = chr(27)+"[0m"
31 typestr = ""
32 elif(sev==5):
33 leftstr = chr(27)+"[33;2m"
34 rightstr = chr(27)+"[0m\n"
35 typestr = "PROGRAM WARNING: "
36 elif(sev==6):
37 leftstr = chr(27)+"[31;1m"
38 rightstr = chr(27)+"[0m\n"
39 typestr = "PROGRAM ERROR: "
40 else:
41 typestr = "";
42 leftstr = rightstr = ""
43
44 if(filename):
45 outputstr = "%s%s:%d: %s%s\n" % (leftstr,filename,line,msg.strip(),rightstr)
46 else:
47 outputstr = "%s%s%s%s" % (leftstr,typestr,msg,rightstr)
48
49 sys.stderr.write(outputstr)
50 return len(outputstr)
51
52 #---------output model hierarchy---------------
53 def show(i,level=0):
54 sys.stderr.write((" "*level)+i.getName().toString()+" IS_A "+i.getType().getName().toString())
55
56 if i.isCompound():
57 if i.isChildless():
58 sys.stderr.write(": no children)\n")
59 else:
60 sys.stderr.write(":\n");
61 for c in i.getChildren():
62 show(c,level+1)
63 elif i.isRelation() or i.isWhen():
64 sys.stderr.write("\n")
65 elif i.isSet():
66 if i.isSetInt():
67 set = i.getSetIntValue()
68 elif i.isSetString():
69 set = i.getSetStringValue()
70 #sys.stderr.write("[%d]:" % set.length())
71 sys.stderr.write(" = %s\n" % set);
72
73 elif ( i.isAtom() or i.isFund() ) and not i.isDefined():
74 sys.stderr.write(" (undefined)\n")
75 elif i.isBool():
76 sys.stderr.write(" = "); sys.stderr.write("%s" % i.getBoolValue()); sys.stderr.write("\n")
77 elif i.isInt():
78 sys.stderr.write(" = "); sys.stderr.write("%d" % i.getIntValue()); sys.stderr.write("\n")
79 else:
80 if i.getType().isRefinedSolverVar():
81 if i.isFixed():
82 sys.stderr.write(" = "+chr(27)+"[1;43;37m"); sys.stderr.write("%f" % i.getRealValue()); sys.stderr.write(chr(27)+"[0m\n")
83 else:
84 sys.stderr.write(" = "+chr(27)+"[1m"); sys.stderr.write("%f" % i.getRealValue()); sys.stderr.write(chr(27)+"[0m\n")
85 else:
86 sys.stderr.write(" = "); sys.stderr.write("%f" % i.getRealValue()); sys.stderr.write("\n")
87 #-------------------------------
88
89 reporter = ascpy.getReporter()
90 reporter.setPythonErrorCallback(error_reporter)
91
92 #reporter.reportError("STUFF")
93
94 l = ascpy.Library()
95
96 l.listModules()
97
98 #t = l.findType("boolean")
99
100 l.load("simple_fs.a4c")
101
102 mv = l.getModules()
103 m = mv[0]
104 tv = l.getModuleTypes(m)
105
106 #for m in mv:
107 # print "Module ", m.getName()
108 # for t in l.getModuleTypes(m):
109 # print " - Type ", t.getName()
110
111 #l.listModules();
112
113 #t = l.findType("boolean_var")
114 #t = l.findType("boolean")
115
116 t = l.findType("test_flowsheet")
117 # t = l.findType("my_water3")
118 sim = t.getSimulation("i")
119
120 sim.check()
121
122 print "Simulation instance kind:", sim.getKindStr()
123
124 pv = t.getMethods()
125 p_specify = 0
126 print "Listing methods of",t.getName,":"
127 for p in pv:
128 print " *", p.getName()
129 if p.getName()=="specify":
130 p_specify = p
131
132 print "Running '"+p_specify.getName()+"'"
133 print p_specify
134 sim.run(p_specify)
135
136 sim.build()
137
138 sim.check()
139
140 print sim.getFixableVariables()
141
142 sim.solve()
143
144 ch = sim.getModel().getChildren()
145
146 print "Children of",sim.getName(),":"
147 print ch
148
149 print "Children of",ch[1].getName(),":"
150 print ch[1].getChildren()
151
152
153 show(sim.getModel())
154
155 b = gtkbrowser.Browser(sim)
156 gtkbrowser.gtk.main()
157
158 print "COMPLETED"
159
160 del l

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