On Tue, Nov 29, 2011 at 4:16 AM, Fabien Lafont <lafont.fab...@gmail.com> wrote:
> Hello everyone,
>
> I don't understand how works TimerBase.
>
>
>
> >From matplotlib import backend_bases
>
> def write(x):
>     print x
>
> backend_bases.TimerBase._timer_start
> backend_bases.TimerBase(1000,write(2))

TimerBase is a do-nothing skeleton class that provides the common
infrastructure for other backends to implement a timer that works with
them (just like the rest of backend_bases). For example, the gtk
backend uses this as a starting point for its own timer class. You
really shouldn't be instantiating TimerBase yourself as it won't do
anything.

> It returns only "2" one time. Why it doesn't return 2 every second?

The only reason you actually see anything at all is because you call
write yourself when you do:

write(2)

The timer never actually does anything. The proper call is to separate
the function and its arguments, since as the docs say, it takes a
"list of (func, args) tuples that will be
called upon timer events":

TimerBase(1000, [(write, 2)])

However, the proper way to create a timer, which will intergrate
properly with the figure event loop, is shown in the example:

http://matplotlib.sourceforge.net/examples/event_handling/timers.html

In your case:

timer = fig.canvas.new_timer(interval=1000)
timer.add_callback(write, 2)
timer.start()

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to