From: <jd...@us...> - 2008-05-26 17:03:01
|
Revision: 5271 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5271&view=rev Author: jdh2358 Date: 2008-05-26 10:02:46 -0700 (Mon, 26 May 2008) Log Message: ----------- added a line vertex selector widget Modified Paths: -------------- branches/v0_91_maint/CODING_GUIDE branches/v0_91_maint/lib/matplotlib/lines.py Modified: branches/v0_91_maint/CODING_GUIDE =================================================================== --- branches/v0_91_maint/CODING_GUIDE 2008-05-25 21:31:43 UTC (rev 5270) +++ branches/v0_91_maint/CODING_GUIDE 2008-05-26 17:02:46 UTC (rev 5271) @@ -9,12 +9,6 @@ svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk matplotlib --username=youruser --password=yourpass -# checking out the main src -svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/matplotlib matplotlib --username=youruser --password=yourpass - -# branch checkouts, eg the transforms branch -svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/transforms transbranch - == Committing changes == When committing changes to matplotlib, there are a few things to bear Modified: branches/v0_91_maint/lib/matplotlib/lines.py =================================================================== --- branches/v0_91_maint/lib/matplotlib/lines.py 2008-05-25 21:31:43 UTC (rev 5270) +++ branches/v0_91_maint/lib/matplotlib/lines.py 2008-05-26 17:02:46 UTC (rev 5271) @@ -569,6 +569,10 @@ def get_markersize(self): return self._markersize + def get_data(self, orig=True): + 'return the xdata, ydata; if orig is True, return the original data' + return self.get_xdata(orig=orig), self.get_ydata(orig=orig) + def get_xdata(self, orig=True): """ return the xdata; if orig is true return the original data, @@ -1460,7 +1464,58 @@ 'return True if line is dashstyle' return self._linestyle in ('--', '-.', ':') +class VertexSelector: + """ + manage the callbacks to maintain a list of selected vertices for + matplotlib.lines.Lin2D. Derived classes should override + process_selected to do something with the picks + """ + def __init__(self, line): + """ + Initialize the class with a matplotlib.lines.Line2D instance. + The line should already be added to some matplotlib.axes.Axes + instance and should have the picker property set. + """ + if not hasattr(line, 'axes'): + raise RuntimeError('You must first add the line to the Axes') + if line.get_picker() is None: + raise RuntimeError('You must first set the picker property of the line') + + self.axes = line.axes + self.line = line + self.canvas = self.axes.figure.canvas + self.cid = self.canvas.mpl_connect('pick_event', self.onpick) + + self.ind = set() + + + def process_selected(self, ind, xs, ys): + """ + Default do nothing implementation of the process_selected method. + + ind are the indices of the selected vertices. xs and ys are + the coordinates of the selected vertices. + """ + pass + + def onpick(self, event): + 'when the line is picked, update the set of selected indicies' + if event.artist is not self.line: return + + for i in event.ind: + if i in self.ind: + self.ind.remove(i) + else: + self.ind.add(i) + + + ind = list(self.ind) + ind.sort() + ind = npy.array(ind) + xdata, ydata = self.line.get_data() + self.process_selected(ind, xdata[ind], ydata[ind]) + lineStyles = Line2D._lineStyles lineMarkers = Line2D._markers This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |