def __init__(self, tree, size_method, color_method, string_method=str, iter_method=iter, margin=0.0): """create a tree map from tree, using itermethod(node) to walk tree, size_method(node) to get object size and color_method(node) to get its color. Optionally provide a string method called on a node to show which node has been clicked (default str) and a margin (proportion in [0,0.5)""" self.size_method = size_method self.iter_method = iter_method self.color_method = color_method self.string_method = string_method self.areas = {} self.margin = margin self.ax = pylab.subplot(111) pylab.subplots_adjust(left=0, right=1, top=1, bottom=0) self.addnode(tree) pylab.disconnect(pylab.get_current_fig_manager().toolbar._idDrag) pylab.connect('motion_notify_event', self.show_node_label) pylab.connect('button_press_event', self.zoom_selected)
def __call__(self, n=1, timeout=30, debug=False): """ Blocking call to retrieve n coordinate pairs through mouse clicks. """ # just for printing the coordinates self.debug = debug # make sure the user isn't messing with us assert isinstance(n, int), "Requires an integer argument" # connect the click events to the on_click function call self.cid = _pylab.connect('button_press_event', self.on_click) # initialize the list of click coordinates self.clicks = [] # wait for n clicks counter = 0 while len(self.clicks) < n: # key step: yield the processor to other threads _wx.Yield(); # rest for a moment _time.sleep(0.1) # check for a timeout counter += 1 if counter > timeout/0.1: print "ginput timeout"; break; # All done! Disconnect the event and return what we have _pylab.disconnect(self.cid) self.cid = None return self.clicks
def my_call(self, event): self.event = event if event.button == 1: ## Button #1 is the left click ## self.xdatalist.append(event.xdata) self.ydatalist.append(event.ydata) sys.stdout.flush() print 'x = %s and y = %s' % (event.xdata,event.ydata) sys.stdout.flush() ax = pylab.gca() ax.hold(True) ax.plot([event.xdata],[event.ydata],'r+',markersize=9) pylab.draw() if event.button == 3: ## Button #3 is the right click ## self.length.append(len(self.xdatalist)) pylab.disconnect(self.cid) self.ask_for_another() if event.button == 2: ## Button #3 is the right click ## self.ymax.append(event.ydata) sys.stdout.flush() ax = pylab.gca() ax.hold(True) ax.plot([event.xdata],[event.ydata],'go') pylab.draw()
def my_call(self, event): self.event = event if event.button == 1: ## Button #1 is the left click ## self.xdatalist.append(event.xdata) self.ydatalist.append(event.ydata) sys.stdout.flush() print "x = %s and y = %s" % (event.xdata, event.ydata) sys.stdout.flush() ax = pylab.gca() ax.hold(True) ax.plot([event.xdata], [event.ydata], "r+", markersize=9) pylab.draw() if event.button == 3: ## Button #3 is the right click ## self.length.append(len(self.xdatalist)) pylab.disconnect(self.cid) self.ask_for_another() if event.button == 2: ## Button #3 is the right click ## self.ymax.append(event.ydata) sys.stdout.flush() ax = pylab.gca() ax.hold(True) ax.plot([event.xdata], [event.ydata], "go") pylab.draw()
def spectrum_cursor_off(self): """ Turn off cursor binding and reset the field curs_val to an empty list. """ if self.cid is not None: pylab.disconnect(self.cid) self.curs_val = [] self.cid = None
def GetPosition(self, event): """ Callback function for data point collection. """ try: line2d = matplotlib.lines.Line2D line2d = matplotlib.patches.Line2D except: pass #If we are zooming, do not register click if event.button == 1 and event.inaxes and self.ToolBar.mode == "": self.Event = event self.DataPointsX.append(event.xdata) self.DataPointsY.append(event.ydata) print "(x,y) = (%f, %f)" % (self.DataPointsX[-1], self.DataPointsY[-1]) #Draw crossed circled at mouse click position if self.DrawIndicators: dx = 10 dy = 10 r = sqrt(dx**2 + dy**2) circ = matplotlib.patches.Circle((event.xdata, event.ydata), radius=r, fill=False, edgecolor="red", linewidth=2) lin1 = line2d(xdata=[event.xdata-dx,event.xdata+dx], ydata=[event.ydata-dy, event.ydata+dy], color="red", linewidth=1) lin2 = line2d(xdata=[event.xdata+dx,event.xdata-dx], ydata=[event.ydata-dy, event.ydata+dy], color="red", linewidth=1) ax = gca() ax.add_artist(circ) ax.add_artist(lin1) ax.add_artist(lin2) draw() #Right button click stops data point collection elif event.button == 3: disconnect(self.EventId) print "Finished collecting data points" print "Now run Analyse() to get point coordinates"
conn.send(mes) print('message sent') clicked = True cid = pylab.connect('button_press_event', onClick) print '\n\n\n\n' print '********************' print('waiting for click') print '********************' while not clicked: pylab.pause(0.1) #pylab.waitforbuttonpress() print('exit') pylab.disconnect(cid) elif re.search('DRAW', line): params = line.split(' ') #print params if len(params) == 3: d, x, y = params x = int(x) y = int(y) minX = min(minX, x) maxX = max(maxX, x) minY = min(minY, y) maxY = max(maxY, y) xs.append(x) ys.append(y) #print 'draw %d %d' % (x, y)