Hi,
I'm trying to write a very simple GUI using matplotlib and have
gotten stuck. Hopefully someone out there has done something similar
and can point me on my way.
First, I should mention that the examples provided with matplotlib
weren't immediately helpful to me, because when I try to run various
demos (like pick_event_demo or object_picker) it fails b/c I'm
relying on (and have to rely on) TkAgg. Sadly, I'm too new to
understand what I would need to do to get those demos working. So I
found someone processing mouseclicks using a Mac online and started
there.
I ended up with something like this:
from pylab import *
class gui :
def __init__(self) :
self.f = figure()
self.data = None # valid mouse click hasn't yet happened
def clicker(event):
self.data = event.xdata
self.f.canvas.mpl_connect("button_press_event",clicker)
def getNextValidClick(self) :
(data, self.data) = (None, None)
while True :
print "Waiting for valid mouse click..."
while self.data == None :
pass # keep polling
if 1 <= self.data <= 3 :
# consider this a valid next mouse click
(data, self.data) = (self.data, None)
break
return data
With which I tried:
g = gui()
x = g.getNextValidClick()
but the latter line caused me to experience the spinning wheel of
dead that we mac users so enjoy.
I have the feeling I need to explicitly yield or some such in the
poll loop, but I don't know how to do that.
Advice greatly appreciated, both on the code I've provided, and on if
there is a better way altogether to provide an app with data obtained
via a matplotlib mouse click callback.
Thanks,
--b
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users