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

Contents of /trunk/pygtk/integratorreporter.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 849 - (show annotations) (download) (as text)
Mon Sep 18 15:10:48 2006 UTC (14 years, 2 months ago) by johnpye
File MIME type: text/x-python
File size: 2586 byte(s)
Some progress on a rewrite of the Observer funcitonality so that it can be shared with the IntegratorReporter.
1 import ascpy
2 import time
3 import gtk
4 import gtk.glade
5 import time
6 from varentry import *
7 from preferences import *
8
9 import observer
10
11 # When writing this class, we assume that the integrator class has already had
12 # its "analyse" method called, so we know all that stuff like the number of
13 # observed variables, what our time samples are, what the independent variable
14 # is, etc.
15
16 class IntegratorReporterPython(ascpy.IntegratorReporterCxx):
17 def __init__(self,browser,integrator):
18 self.browser=browser
19 ascpy.IntegratorReporterCxx.__init__(self,integrator)
20
21 # GUI elements
22 _xml = gtk.glade.XML(browser.glade_file,"integratorstatusdialog")
23 _xml.signal_autoconnect(self)
24 self.window=_xml.get_widget("integratorstatusdialog")
25 self.window.set_transient_for(self.browser.window)
26 self.label=_xml.get_widget("integratorlabel")
27 self.label.set_text("Solving with "+self.getIntegrator().getEngineName())
28 self.progress=_xml.get_widget("integratorprogress")
29 self.data = None
30
31 def run(self):
32 # run the dialog: start solution, monitor use events
33 _res = self.getIntegrator().solve()
34 self.window.destroy()
35 return _res
36
37 def initOutput(self):
38 # empty out the data table
39 self.data=[]
40 self.nsteps = self.getIntegrator().getNumSteps()
41 self.progress.set_text("Starting...")
42 self.progress.set_fraction(0.0)
43 #update the GUI
44 while gtk.events_pending():
45 gtk.main_iteration()
46 return 1
47
48 def closeOutput(self):
49 # output the results (to the console, for now)
50 for _t,_vals in self.data:
51 print _t,_vals
52
53 self.progress.set_fraction(1.0)
54 self.progress.set_text("Finished.")
55 return 1
56
57 def updateStatus(self):
58 # outdate the GUI
59 try:
60 # TODO: change so it's not updating every step!
61 t = self.getIntegrator().getCurrentTime()
62 _frac = float(self.getIntegrator().getCurrentStep())/self.nsteps
63 self.progress.set_text("t = %f" % (self.getIntegrator().getCurrentTime()))
64 self.progress.set_fraction(_frac)
65 while gtk.events_pending():
66 gtk.main_iteration()
67 return 1
68 except Exception,e:
69 print "\n\nERROR IN UPDATESTATUS!",str(e)
70 return 0
71
72 def recordObservedValues(self):
73 # just add to our in-memory data structure for now...
74 try:
75 i = self.getIntegrator()
76 print str(i.getCurrentObservations())
77 self.data.append((i.getCurrentTime(),i.getCurrentObservations()))
78 except Exception,e:
79 print "\n\nERROR IN RECORDOBSERVEDVALUES!",str(e)
80 return 0
81 return 1
82
83 class IntegratorReporterPyGTK(IntegratorReporterPython):
84 def __init__(self,browser,integrator):
85 IntegratorReporter.__init__(self,browser,integrator)
86
87

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