Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

No selections in scatter marker now updates to no selection instead of last selection

This commit is contained in:
Arnar Flatberg 2007-02-26 12:11:28 +00:00
parent a6fbef9cfa
commit c0bbe24c39
1 changed files with 27 additions and 24 deletions

View File

@ -677,26 +677,30 @@ class ScatterMarkerPlot(Plot):
self.selection_listener(self.current_dim, ids) self.selection_listener(self.current_dim, ids)
def set_current_selection(self, selection): def set_current_selection(self, selection):
index = self.get_index_from_selection(self.dataset_1, selection)
if not len(index)>0:
return
xdata_new = self.xaxis_data.take(index) #take data
ydata_new = self.yaxis_data.take(index)
#remove old selection #remove old selection
if self._selection_line: if self._selection_line:
self.axes.lines.remove(self._selection_line) self.axes.lines.remove(self._selection_line)
index = self.get_index_from_selection(self.dataset_1, selection)
if len(index)==0:
# no selection
self.canvas.draw()
self._selection_line = None
return
xdata_new = self.xaxis_data.take(index) #take data
ydata_new = self.yaxis_data.take(index)
self._selection_line = Line2D(xdata_new, ydata_new self._selection_line = Line2D(xdata_new, ydata_new
,marker='o', markersize=self.ms, ,marker='o', markersize=self.ms,
linewidth=0, markerfacecolor='r', linewidth=0, markerfacecolor='r',
markeredgewidth=1.0) markeredgewidth=1.0)
self.axes.add_line(self._selection_line) self.axes.add_line(self._selection_line)
if self.use_blit: if self.use_blit:
if self._background is None: if self._background is None:
self._background = self.canvas.copy_from_bbox(self.axes.bbox) self._background = self.canvas.copy_from_bbox(self.axes.bbox)
self.canvas.restore_region(self._background) self.canvas.restore_region(self._background)
self.axes.draw_artist(self._selection_line) if self.selection_line:
self.axes.draw_artist(self._selection_line)
self.canvas.blit() self.canvas.blit()
else: else:
self.canvas.draw() self.canvas.draw()
@ -1762,11 +1766,9 @@ class Selector:
return return
self.eventrelease = event self.eventrelease = event
self._show_selector(False)
if self.verts is not None: if self.verts is not None:
self.verts.append((event.xdata, event.ydata)) self.verts.append((event.xdata, event.ydata))
self.line.set_visible(False)
self.polygon.set_visible(False)
self.canvas.blit(self.axes.bbox)
if self.select_type == 'lasso': if self.select_type == 'lasso':
if len(self.verts)>2: if len(self.verts)>2:
self.callback(self.verts, event.key) self.callback(self.verts, event.key)
@ -1774,7 +1776,7 @@ class Selector:
x1, y1 = self.eventpress.xdata, self.eventpress.ydata x1, y1 = self.eventpress.xdata, self.eventpress.ydata
x2, y2 = self.eventrelease.xdata, self.eventrelease.ydata x2, y2 = self.eventrelease.xdata, self.eventrelease.ydata
self.callback(x1, y1, x2, y2, event.key) self.callback(x1, y1, x2, y2, event.key)
self.verts = [] self.verts = []
self.eventpress = None self.eventpress = None
self.eventrelease = None self.eventrelease = None
@ -1813,11 +1815,7 @@ class Selector:
def _onpress(self, event): def _onpress(self, event):
# Is the event to be ignored? # Is the event to be ignored?
if self._ignore(event): return if self._ignore(event): return
if self._background == None: self._show_selector(True)
self._background = self.canvas.copy_from_bbox(self.axes.bbox)
self.polygon.set_visible(True)
self.line.set_visible(True)
self.eventpress = event self.eventpress = event
self.verts = [(event.xdata, event.ydata)] self.verts = [(event.xdata, event.ydata)]
return False return False
@ -1838,18 +1836,23 @@ class Selector:
if ignore: if ignore:
# remove poly + line if they are visible # remove poly + line if they are visible
if self.polygon._visible or self.line._visible: if self.polygon._visible or self.line._visible:
self.polygon.set_visible(False) self._show_selector(False)
self.line.set_visible(False)
self.canvas.restore_region(self._background)
self.canvas.blit()
else: else:
if not self.polygon._visible or not self.line._visible: if not self.polygon._visible or not self.line._visible:
# put poly + line back if we event is ok # put poly + line back if we event is ok
self.polygon.set_visible(True) self._show_selector(True)
self.line.set_visible(True)
return ignore return ignore
def _show_selector(self, bool):
if self.polygon and self.line:
self.polygon.set_visible(bool)
self.line.set_visible(bool)
if self._background == None:
self._background = self.canvas.copy_from_bbox(self.axes.bbox)
self.canvas.restore_region(self._background)
self.canvas.blit()
# Create a view-changed signal that should be emitted every time # Create a view-changed signal that should be emitted every time
# the active view changes. # the active view changes.