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

Contents of /trunk/pygtk/integratorreporter.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 855 - (show annotations) (download) (as text)
Wed Sep 20 14:00:41 2006 UTC (13 years, 9 months ago) by johnpye
File MIME type: text/x-python
File size: 3428 byte(s)
Removed some verbage in Integrator output
1 import ascpy
2 import time
3 import sys
4 import gtk
5 import gtk.glade
6 import time
7 from varentry import *
8 from preferences import *
9
10 from observer import *
11
12 # When writing this class, we assume that the integrator class has already had
13 # its "analyse" method called, so we know all that stuff like the number of
14 # observed variables, what our time samples are, what the independent variable
15 # is, etc.
16
17 INTEGRATOR_NUM = 0
18
19 class IntegratorReporterPython(ascpy.IntegratorReporterCxx):
20 def __init__(self,browser,integrator):
21 self.browser=browser
22 ascpy.IntegratorReporterCxx.__init__(self,integrator)
23
24 # GUI elements
25 _xml = gtk.glade.XML(browser.glade_file,"integratorstatusdialog")
26 _xml.signal_autoconnect(self)
27 self.window=_xml.get_widget("integratorstatusdialog")
28 self.window.set_transient_for(self.browser.window)
29 self.label=_xml.get_widget("integratorlabel")
30 self.label.set_text("Solving with "+self.getIntegrator().getEngineName())
31 self.progress=_xml.get_widget("integratorprogress")
32 self.data = None
33
34 def run(self):
35 # run the dialog: start solution, monitor use events
36 _res = self.getIntegrator().solve()
37 self.window.destroy()
38 return _res
39
40 def initOutput(self):
41 # empty out the data table
42 self.data=[]
43 self.nsteps = self.getIntegrator().getNumSteps()
44 self.progress.set_text("Starting...")
45 self.progress.set_fraction(0.0)
46 #update the GUI
47 while gtk.events_pending():
48 gtk.main_iteration()
49 return 1
50
51 def closeOutput(self):
52 global INTEGRATOR_NUM
53 integrator = self.getIntegrator()
54 # create an empty observer
55 try:
56 _xml = gtk.glade.XML(self.browser.glade_file,"observervbox")
57 _label = gtk.Label();
58 INTEGRATOR_NUM = INTEGRATOR_NUM + 1
59 _name = "Integrator %d" % INTEGRATOR_NUM
60 _tab = self.browser.maintabs.append_page(_xml.get_widget("observervbox"),_label)
61 _obs = ObserverTab(xml=_xml, name=_name, browser=self.browser, tab=_tab, alive=False)
62 _label.set_text(_obs.name)
63 self.browser.observers.append(_obs)
64
65 # add the columns
66 _obs.add_instance(integrator.getIndependentVariable().getInstance())
67 for _v in [integrator.getObservedVariable(_i) for _i in range(0,integrator.getNumObservedVars())]:
68 _obs.add_instance(_v.getInstance())
69
70 for _time,_vals in self.data:
71 _obs.do_add_row([_time]+[_v for _v in _vals])
72 except Exception,e:
73 sys.stderr.write("\n\n\nCAUGHT EXCEPTION: %s\n\n\n" % str(e))
74 return 0
75
76 def closeOutput1(self):
77 # output the results (to the console, for now)
78 for _t,_vals in self.data:
79 print _t,_vals
80
81 self.progress.set_fraction(1.0)
82 self.progress.set_text("Finished.")
83 return 1
84
85 def updateStatus(self):
86 # outdate the GUI
87 try:
88 # TODO: change so it's not updating every step!
89 t = self.getIntegrator().getCurrentTime()
90 _frac = float(self.getIntegrator().getCurrentStep())/self.nsteps
91 self.progress.set_text("t = %f" % (self.getIntegrator().getCurrentTime()))
92 self.progress.set_fraction(_frac)
93 while gtk.events_pending():
94 gtk.main_iteration()
95 return 1
96 except Exception,e:
97 print "\n\nERROR IN UPDATESTATUS!",str(e)
98 return 0
99
100 def recordObservedValues(self):
101 # just add to our in-memory data structure for now...
102 try:
103 i = self.getIntegrator()
104 #print str(i.getCurrentObservations())
105 self.data.append((i.getCurrentTime(),i.getCurrentObservations()))
106 except Exception,e:
107 print "\n\nERROR IN RECORDOBSERVEDVALUES!",str(e)
108 return 0
109 return 1
110
111
112

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