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

Annotation of /trunk/pygtk/librarytest.py

Parent Directory Parent Directory | Revision Log Revision Log


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

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