Confused/frustrated w/ waitforbuttonpress

Hi,
Looking for a way to analyze a set of images I found waitforbuttonpress, which
basically does what I need: allows me to display a few plots/scatter/etc for as
long as I need; then when pressing a key move to the next image and redo all
plots/scatter/etc.
Now my problem is that waitforbuttonpress (or the (mis)use I gave it) forces me
to close the ipython session frequently and start over again. This is at least
inconvenient, and a few times forced me to recalculate things that took some
time (and that I had forgot to save).
I know this might be backend-related. I use GTKAgg, on ubuntu 10.04, mpl-1.0.0
(locally built). Below you'll find a script I created where I see this behavior,
the ipython console's output, and the steps I followed.

Steps followed and description:
1- Run script, click mouse a few times (plot is closed and redrawn), finally
press a key. The plot is closed, and the console returns to be active. This
corresponds to "In [1]" in the ipython console's output
2- Trying to run anything at the ipython console results in a looong delay and a
message like in "In [2]" at the console. The console works fine after this,
though, at least with non matplotlib-related stuff
3- Running the script again results in the output shown in "In [3]". The script
seems to runs fine, i.e. clicks cause the redrawing of the plot, though pressing
any key (which should break the loop and end the script) will end the script but
won't close the plot windows. The console works mostly ok, the only way to close
the plot window and ipython is by killing the ipython process.
4- In some other cases, I ended up with an unresponsive console that required
killing the ipython process as well.
This test case is not comprehensive of the things I've experienced, but it might
show a possible cause of this behavior.

Regards,

Jorge

···

------------------------
Ipython console's output:

In [1]: run doct/intrinsic-images/test_waitforbuttonpress.py
/home/jscandal/lib/python2.6/site-packages/matplotlib/backend_bases.py:2051:
DeprecationWarning: Using default event loop until function specific to this GUI
is implemented
  warnings.warn(str,DeprecationWarning)

In [2]: run doct/intrinsic-images/test_waitforbuttonpress.py
Warning: Timeout for mainloop thread exceeded
switching to nonthreaded mode (until mainloop wakes up again)

In [3]: run doct/intrinsic-images/test_waitforbuttonpress.py
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)

/usr/lib/pymodules/python2.6/IPython/Shell.pyc in on_timer(self)
    847
    848 update_tk(self.tk)
--> 849 self.IP.runcode()
    850 time.sleep(0.01)
    851 return True

/usr/lib/pymodules/python2.6/IPython/Shell.pyc in runcode(self)
    455 # code modifies it, we restore our own handling.

    456 try:
--> 457 signal(SIGINT,sigint_handler)
    458 except SystemError:
    459 # This happens under Windows, which seems to have all sorts

ValueError: signal only works in main thread
-------------------------

script used in the test:
------------------------
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

data = np.random.rand(10,2)

while True:
    fig, ax = plt.subplots(1,1)
    ax.scatter(data.T[0], data.T[1])
    plt.show()
    if fig.waitforbuttonpress(timeout=-1):
  plt.close('all')
  break
    plt.close('all')

Hi,
Looking for a way to analyze a set of images I found waitforbuttonpress, which
basically does what I need: allows me to display a few plots/scatter/etc for as
long as I need; then when pressing a key move to the next image and redo all
plots/scatter/etc.
Now my problem is that waitforbuttonpress (or the (mis)use I gave it) forces me
to close the ipython session frequently and start over again. This is at least
inconvenient, and a few times forced me to recalculate things that took some
time (and that I had forgot to save).
I know this might be backend-related. I use GTKAgg, on ubuntu 10.04, mpl-1.0.0
(locally built). Below you'll find a script I created where I see this behavior,
the ipython console's output, and the steps I followed.

Steps followed and description:
1- Run script, click mouse a few times (plot is closed and redrawn), finally
press a key. The plot is closed, and the console returns to be active. This
corresponds to "In [1]" in the ipython console's output
2- Trying to run anything at the ipython console results in a looong delay and a
message like in "In [2]" at the console. The console works fine after this,
though, at least with non matplotlib-related stuff
3- Running the script again results in the output shown in "In [3]". The script
seems to runs fine, i.e. clicks cause the redrawing of the plot, though pressing
any key (which should break the loop and end the script) will end the script but
won't close the plot windows. The console works mostly ok, the only way to close
the plot window and ipython is by killing the ipython process.
4- In some other cases, I ended up with an unresponsive console that required
killing the ipython process as well.
This test case is not comprehensive of the things I've experienced, but it might
show a possible cause of this behavior.

Jorge,

Running mpl from svn, with gtkagg backend, on ubuntu, but with ipython 0.11alpha1, I can't reproduce the problem; your example works for me. I suspect the difference is that ipython 0.11 uses a non-threaded interactive mode, while 0.10 uses the threaded mode. Is updating your ipython an option for you?

Eric

···

On 08/05/2010 10:54 PM, Jorge Scandaliaris wrote:

Regards,

Jorge

------------------------
Ipython console's output:

In [1]: run doct/intrinsic-images/test_waitforbuttonpress.py
/home/jscandal/lib/python2.6/site-packages/matplotlib/backend_bases.py:2051:
DeprecationWarning: Using default event loop until function specific to this GUI
is implemented
   warnings.warn(str,DeprecationWarning)

In [2]: run doct/intrinsic-images/test_waitforbuttonpress.py
Warning: Timeout for mainloop thread exceeded
switching to nonthreaded mode (until mainloop wakes up again)

In [3]: run doct/intrinsic-images/test_waitforbuttonpress.py
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)

/usr/lib/pymodules/python2.6/IPython/Shell.pyc in on_timer(self)
     847
     848 update_tk(self.tk)
--> 849 self.IP.runcode()
     850 time.sleep(0.01)
     851 return True

/usr/lib/pymodules/python2.6/IPython/Shell.pyc in runcode(self)
     455 # code modifies it, we restore our own handling.

     456 try:
--> 457 signal(SIGINT,sigint_handler)
     458 except SystemError:
     459 # This happens under Windows, which seems to have all sorts

ValueError: signal only works in main thread
-------------------------

script used in the test:
------------------------
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

data = np.random.rand(10,2)

while True:
     fig, ax = plt.subplots(1,1)
     ax.scatter(data.T[0], data.T[1])
     plt.show()
     if fig.waitforbuttonpress(timeout=-1):
  plt.close('all')
  break
     plt.close('all')

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options