Adapt animation_blit_qt4.py to a pure OO implementation (QT4 timerEvent)

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 :frowning:

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

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

Darren

路路路

On Wed, May 27, 2009 at 9:11 AM, Sandro Tosi <morph@鈥10鈥> wrote:

Hi all,

I鈥檇 like to adapt 鈥榓nimation_blit_qt4.py鈥 to a pure OO approach,

removing pylab from the code and move to something near to

鈥榚mbedding_in_qt4.py鈥.

I tried a bit but failed miserably :frowning:

What I鈥檇 like to achieve is use something like in

鈥榚mbedding_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?

Hi Darren,
thanks for replying

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 :frowning:

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 :wink:

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" :slight_smile:

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 :frowning:

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 :slight_smile:

Thanks,

animation_blit_qt4_morph.py (2.25 KB)

embedding_in_qt4_morph.py (849 Bytes)

路路路

On Wed, May 27, 2009 at 21:01, Darren Dale <dsdale24@...287...> wrote:

On Wed, May 27, 2009 at 9:11 AM, Sandro Tosi <morph@...10...> wrote:

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

Hi Sandro,

animation_blit_qt4_morph.py (1.57 KB)

路路路

On Wed, May 27, 2009 at 7:14 PM, Sandro Tosi <morph@鈥10鈥> wrote:

Hi Darren,

thanks for replying

On Wed, May 27, 2009 at 21:01, Darren Dale <dsdale24@鈥287鈥> wrote:

On Wed, May 27, 2009 at 9:11 AM, Sandro Tosi <morph@鈥10鈥> wrote:

Hi all,

I鈥檇 like to adapt 鈥榓nimation_blit_qt4.py鈥 to a pure OO approach,

removing pylab from the code and move to something near to

鈥榚mbedding_in_qt4.py鈥.

I tried a bit but failed miserably :frowning:

What I鈥檇 like to achieve is use something like in

鈥榚mbedding_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鈥檝e worked on was at home :wink:

So, the situation is this:

  • animation_blit_qt4.py has a nice way to update the graph 鈥渙nline鈥,

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 鈥渕ore OO鈥 :slight_smile:

The attached script 鈥渁nimation_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 :frowning:

What I鈥檇 like to achive is something similar to

鈥渆mbedding_in_qt4_morph.py鈥 but where the graph is updated

automatically like in an animation.

Your help will be appreciated a lot :slight_smile:

Try the attached script.

Darren

Hi Darren,

Try the attached script.

Oh it works very great! thanks you very much!

One thing I've done is also remove

import matplotlib
matplotlib.use('Qt4Agg')

since we're already importing the qt4agg backend directly right after.

One only thing it's left a bit obscure (also because doc is a little
missing) is this piece of code:

聽聽聽聽聽聽聽聽# update the data
聽聽聽聽聽聽聽聽self.line.set_ydata(np.sin(self.x+self.cnt/10.0))
聽聽聽聽聽聽聽聽# just draw the animated artist
聽聽聽聽聽聽聽聽self.ax.draw_artist(self.line)
聽聽聽聽聽聽聽聽# just redraw the axes rectangle
聽聽聽聽聽聽聽聽self.blit(self.ax.bbox)

first, I've not clear wat draw_artist and blit does, so if you can
shine some light on me :slight_smile:

Secondly, the "effect" I'd like to achieve is to update the current
line values and "replace" the current line with a new one. In this
code, instead, the line is plotted keeping the previous instances
around. So the effect is to fil the canvas with sin function plots
instead of updating only one instance.

Do you know how to "fix" this?

Thanks a lot for your support! :slight_smile:

路路路

On Thu, May 28, 2009 at 19:16, Darren Dale <dsdale24@...287...> wrote:

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

Not off the top of my head. Maybe someone else on the list can offer a suggestion.

Darren

路路路

On Thu, May 28, 2009 at 6:01 PM, Sandro Tosi <morph@鈥10鈥> wrote:

Hi Darren,

On Thu, May 28, 2009 at 19:16, Darren Dale <dsdale24@鈥287鈥> wrote:

Try the attached script.

Oh it works very great! thanks you very much!

One thing I鈥檝e done is also remove

import matplotlib

matplotlib.use(鈥楺t4Agg鈥)

since we鈥檙e already importing the qt4agg backend directly right after.

One only thing it鈥檚 left a bit obscure (also because doc is a little

missing) is this piece of code:

    # update the data

    self.line.set_ydata(np.sin(self.x+self.cnt/10.0))

    # just draw the animated artist

    self.ax.draw_artist(self.line)

    # just redraw the axes rectangle

    self.blit(self.ax.bbox)

first, I鈥檝e not clear wat draw_artist and blit does, so if you can

shine some light on me :slight_smile:

Secondly, the 鈥渆ffect鈥 I鈥檇 like to achieve is to update the current

line values and 鈥渞eplace鈥 the current line with a new one. In this

code, instead, the line is plotted keeping the previous instances

around. So the effect is to fil the canvas with sin function plots

instead of updating only one instance.

Do you know how to 鈥渇ix鈥 this?

Hi Darren,

animation_blit_qt4_morph_darren2.py (1.78 KB)

路路路

On Fri, May 29, 2009 at 01:50, Darren Dale <dsdale24@...287...> wrote:

On Thu, May 28, 2009 at 6:01 PM, Sandro Tosi <morph@...10...> wrote:

Hi Darren,

On Thu, May 28, 2009 at 19:16, Darren Dale <dsdale24@...287...> wrote:
> Try the attached script.

Oh it works very great! thanks you very much!

One thing I've done is also remove

import matplotlib
matplotlib.use('Qt4Agg')

since we're already importing the qt4agg backend directly right after.

One only thing it's left a bit obscure (also because doc is a little
missing) is this piece of code:

   \# update the data
   self\.line\.set\_ydata\(np\.sin\(self\.x\+self\.cnt/10\.0\)\)
   \# just draw the animated artist
   self\.ax\.draw\_artist\(self\.line\)
   \# just redraw the axes rectangle
   self\.blit\(self\.ax\.bbox\)

first, I've not clear wat draw_artist and blit does, so if you can
shine some light on me :slight_smile:

Secondly, the "effect" I'd like to achieve is to update the current
line values and "replace" the current line with a new one. In this
code, instead, the line is plotted keeping the previous instances
around. So the effect is to fil the canvas with sin function plots
instead of updating only one instance.

Do you know how to "fix" this?

Not off the top of my head. Maybe someone else on the list can offer a
suggestion.

Thanks a lot for your help! Early morning coding did help! :slight_smile:

I'm attaching a script to do what I wanted to. The solution was to
remove the animated=True when calling self.ax.plot and then call an
explicit self.fig.canvas.draw() - and here it is an animate sin and
cos function! :slight_smile:

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