[Matplotlib-users] Adapt animation_blit_qt4.py to a pure OO implementation (QT4 timerEvent)

2009-05-27 Thread Sandro Tosi
Hi all,
I'd like to adapt 'animation_blit_qt4.py' to a pure OO approach,
removing pylab from the code and move to something near to
'embedding_in_qt4.py'.

I tried a bit but failed miserably :(

What I'd like to achieve is use something like in
'embedding_in_qt4.py' but that can be updated using the timerEvent /
startTime paradigm (something similar to gobject.add_idle(func) but
this time for Qt4).

Can someone please give me a help on this?

Thanks a lot in advance,
-- 
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

--
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers  brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing,  
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA,  Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Adapt animation_blit_qt4.py to a pure OO implementation (QT4 timerEvent)

2009-05-27 Thread Darren Dale
On Wed, May 27, 2009 at 9:11 AM, Sandro Tosi mo...@debian.org wrote:

 Hi all,
 I'd like to adapt 'animation_blit_qt4.py' to a pure OO approach,
 removing pylab from the code and move to something near to
 'embedding_in_qt4.py'.

 I tried a bit but failed miserably :(

 What I'd like to achieve is use something like in
 'embedding_in_qt4.py' but that can be updated using the timerEvent /
 startTime paradigm (something similar to gobject.add_idle(func) but
 this time for Qt4).

 Can someone please give me a help on this?


Can you be more specific? Maybe post what you have along with a description
of how it is failing?

Darren
--
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers  brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing,  
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA,  Big Spaceship. http://p.sf.net/sfu/creativitycat-com ___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Adapt animation_blit_qt4.py to a pure OO implementation (QT4 timerEvent)

2009-05-27 Thread Sandro Tosi
Hi Darren,
thanks for replying

On Wed, May 27, 2009 at 21:01, Darren Dale dsdal...@gmail.com wrote:
 On Wed, May 27, 2009 at 9:11 AM, Sandro Tosi mo...@debian.org wrote:

 Hi all,
 I'd like to adapt 'animation_blit_qt4.py' to a pure OO approach,
 removing pylab from the code and move to something near to
 'embedding_in_qt4.py'.

 I tried a bit but failed miserably :(

 What I'd like to achieve is use something like in
 'embedding_in_qt4.py' but that can be updated using the timerEvent /
 startTime paradigm (something similar to gobject.add_idle(func) but
 this time for Qt4).

 Can someone please give me a help on this?

 Can you be more specific? Maybe post what you have along with a description
 of how it is failing?

Eheh, sorry for being so generic: I wrote that email from work, while
the code I've worked on was at home ;)

So, the situation is this:

- animation_blit_qt4.py has a nice way to update the graph online,
using the timerEvent/startTimer
- animation_blit_qt4.py contains pylab staff (I want to avoid using)
- animation_blit_qt4.py uses the backend Qt4Agg not the backend object
- embedding_in_qt4.py uses an OO approach at embedding mpl in a qt4
widget/application.

The ultimate result I want to achieve is to embed mpl in a qt4
application but update the graph in realtime.

So I started modifying animation_blit_qt4.py to make it more OO :)

The attached script animation_blit_qt4_morph.py only replaced the
pylab parts with a mix of OO style and pyplot, and the timerEvent just
print the receive event without updating the graph.

As you can see, not much of what I need :(

What I'd like to achive is something similar to
embedding_in_qt4_morph.py but where the graph is updated
automatically like in an animation.

Your help will be appreciated a lot :)

Thanks,
-- 
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi
# For detailed comments on animation and the techniqes used here, see
# the wiki entry http://www.scipy.org/Cookbook/Matplotlib/Animations

import os, sys
import matplotlib
matplotlib.use('Qt4Agg') # qt4 example
# matplotlib Figure object
from matplotlib.figure import Figure
import matplotlib.backends.backend_qt4agg as backend

from PyQt4 import QtCore, QtGui

ITERS = 1000

#import pylab as p
import matplotlib.pyplot as plt
import numpy as npy
import time

class BlitQT(QtCore.QObject):#, backend.FigureCanvas):
def __init__(self):
self.fig = Figure()
self.ax = self.fig.add_subplot(111)
self.canvas = self.ax.figure.canvas
self.ax.grid()

# By making this a child of the canvas we make sure that it is
# destroyed first and avoids a possible exception when the user clicks
# on the window's close box.
QtCore.QObject.__init__(self, self.canvas)

self.cnt = 0

# create the initial line
self.x = npy.arange(0,2*npy.pi,0.01)
self.line, = self.ax.plot(self.x, npy.sin(self.x), animated=True, lw=2)

#self.background = None
#self.old_size = 0, 0
plt.draw()
#backend.show()


def timerEvent(self, evt):
# See if the size has changed since last time round.
#current_size = self.ax.bbox.width, self.ax.bbox.height
print evt

#if self.old_size != current_size:
#self.old_size = current_size
#self.background = self.canvas.copy_from_bbox(self.ax.bbox)

# restore the clean slate background
#self.canvas.restore_region(self.background)
# update the data
self.line.set_ydata(npy.sin(self.x+self.cnt/10.0))
plt.draw()
# just draw the animated artist
#self.ax.draw_artist(self.line)
# just redraw the axes rectangle
#self.canvas.blit(self.ax.bbox)

if self.cnt==ITERS:
# print the timing info and quit
print 'FPS:' , ITERS/(time.time()-self.tstart)
sys.exit()

else:
self.cnt += 1

#p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
#p.grid() # to ensure proper background restore

app = BlitQT()
# for profiling
app.tstart = time.time()
app.startTimer(100)
backend.show()
#!/usr/bin/env python

# for command-line arguments
import sys
# Python Qt4 bindings
from PyQt4 import QtGui

# standard Matplotlib imports
import numpy as np
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure


class Qt4MplCanvas(FigureCanvas):
Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).
def __init__(self):
self.fig = Figure()
self.axes = self.fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False)

self.x = np.arange(0.0, 3.0, 0.01)
self.y = np.cos(2*np.pi*self.x)
self.axes.plot(self.x, self.y)

FigureCanvas.__init__(self, self.fig)