Inter-Process comunication

email9898989 at yahoo.com email9898989 at yahoo.com
Sun Nov 9 11:59:37 EST 2003


Zunbeltz Izaola <zunbeltz at wm.lc.ehu.es.XXX> wrote in message news:<m1vfpwe47a.fsf at lcpxdf.wm.lc.ehu.es>...
> I want to plot the data in a "canvas", but i want to replot each time
> a point is added to data. I don't watn to insert the code to plotting
> inside the Measure (becose this code is GUI dependent). The code for
> plotting is in another function DrawPlOt()
> 
> I want something like to send a signal each time the data is changed
> to execute DrawPlot(). I'm no proffesional programmer and i don't know
> wich technique is the best, signals, theread, anothero one ...
> Any sugestions?

First do you want your data collecting class running as a separate
thread in your wxPython app (simplest way), or as a completely
separate process/application that communicates remotely with your
wxPython app?
To do it using threads, see:
http://wiki.wxpython.org/index.cgi/LongRunningTasks
If it is running as a separate application, then you would need to use
something like sockets/Pyro/Twisted to communicate with your wxPython
app.

Second, if you are just plotting the data, see something like wxPyPlot
or SciPy's wxPython plotting options.
http://scipy.com/
http://www.cyberus.ca/~g_will/wxPython/wxpyplot.html

Next, see the Observer-Observable and Model-View-Controller patterns. 
Bruce Eckel has an example of observer and observable in Python:
http://jamesthornton.com/eckel/TIPython/code/util/

Make your data collecting class (the Model) a subclass of Observable. 
When it gets new data, it calls its own "notifyObservers" method, and
optionally passes the data value (with or without a time stamp too) as
an argument.

Your wxPython canvas (the View) subclasses Observer, and implements a
"notify" method to receive the new data and draw it.  But don't redraw
it immediately if the Model is running in a separate thread, use
something like wxCallAfter(self.RedrawPlot) so that all drawing
happens in the main wxPython application thread (or if you are using
SciPy, see its gui_thread module).

One other problem - if your model is continuously collecting a lot of
data very fast, then your wxPython app will get bogged down if you
redraw every time new data is received.  What I do is have the
"notify" method just append the time stamped data to an array (see the
Numeric module).  Then I use a wxTimer to draw the new data at regular
intervals.




More information about the Python-list mailing list