Added extended toolbar with selection freeze

This commit is contained in:
Arnar Flatberg 2006-08-29 09:03:28 +00:00
parent 97e652edce
commit ae7a6a5a0e

View File

@ -1,4 +1,4 @@
import os,sys
import pygtk
import gobject
import gtk
@ -238,6 +238,16 @@ class Plot (gtk.Frame):
self.fig = Figure(figsize=(5,4), dpi=72)
self.canvas = FigureCanvas(self.fig)
self.fig.set_facecolor('white')
self._sel_sensitive = True
def set_selection_sensitive(self,event):
if event:
if event.get_active():
logger.log('debug','Selection freezed')
self._sel_sensitive = False
else:
logger.log('debug','Selections active')
self._sel_sensitive = True
def get_title(self):
return self.title
@ -273,7 +283,7 @@ class EmptyView (Plot):
class NavToolbar(NavigationToolbar2):
toolitems = (('Select', 'Select within rectangle', 'zoom_to_rect.png',
'select'),) + NavigationToolbar2.toolitems
def __init__(self, *args):
NavigationToolbar2.__init__(self, *args)
self._select_callback = None
@ -298,7 +308,6 @@ class NavToolbar(NavigationToolbar2):
self._idPress = self.canvas.mpl_connect('button_press_event', self.press_select)
self._idRelease = self.canvas.mpl_connect('button_release_event', self.release_select)
self.mode = 'Select rectangle mode'
self.set_message(self.mode)
def set_message(self, s):
@ -364,8 +373,25 @@ class NavToolbar(NavigationToolbar2):
widget coordinates.
"""
self._select_callback = listener
class PlotToolbar(NavToolbar):
"""Extensions to existing toolbar
"""
def __init__(self, *args):
NavToolbar.__init__(self, *args)
iconSize = gtk.ICON_SIZE_SMALL_TOOLBAR
self.tb_freeze = gtk.ToolItem()
self.chk = gtk.CheckButton ()
self.chk.set_label ('Freeze')
self.tb_freeze.add (self.chk)
self.tb_freeze.set_tooltip(self.tooltips, 'Freeze current selcetion updating')
self.insert(self.tb_freeze,-1)
toolitem = gtk.SeparatorToolItem()
self.insert(toolitem, -1)
self.show_all()
self.message.hide()
class SinePlot(Plot):
def __init__(self):
Plot.__init__(self, 'Sine plot')
@ -420,10 +446,15 @@ class LineViewPlot(Plot):
self.canvas.show()
# We use a regular toolbar as we don't need selections
self._toolbar = NavigationToolbar2(self.canvas, None)
#self._toolbar = NavigationToolbar2(self.canvas, None)
#self._toolbar.set_property('show-arrow', False)
self._toolbar = PlotToolbar(self.canvas, None)
self._toolbar.set_property('show-arrow', False)
self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
self.canvas.mpl_connect('resize_event',self.clear_background)
def get_toolbar(self):
return self._toolbar
@ -431,6 +462,8 @@ class LineViewPlot(Plot):
self._background = None
def selection_changed(self, selection):
if not self._sel_sensitive:
return
ids = selection[self.current_dim] # current identifiers
index = self.dataset.get_indices(self.current_dim, ids)
if self.use_blit:
@ -464,32 +497,34 @@ class LineViewPlot(Plot):
class ScatterMarkerPlot(Plot):
"""The ScatterMarkerPlot is faster than regular scatterplot, but
has no color and size options."""
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2, name="Scatter plot"):
def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2,s=6, name="Scatter plot"):
Plot.__init__(self, name)
self.ax = ax = self.fig.add_subplot(111)
#self.ax.set_position([0.01,0.01,.99,.99])
self.ax.set_xticks([])
self.ax.set_yticks([])
#self.ax.set_xticks([])
#self.ax.set_yticks([])
self.ax.axhline(0,color='k',lw=1.5,zorder=0)
self.ax.axvline(0,color='k',lw=1.5,zorder=0)
self.current_dim = id_dim
self.dataset_1 = dataset_1
self.ms = s
self._selection_line = None
x_index = dataset_1[sel_dim][id_1]
y_index = dataset_2[sel_dim][id_2]
self.xaxis_data = dataset_1._array[:,x_index]
self.yaxis_data = dataset_2._array[:,y_index]
ax.plot(self.xaxis_data,self.yaxis_data,'o',markeredgewidth=0)
ax.plot(self.xaxis_data,self.yaxis_data,'o',markeredgewidth=0,markersize=s)
ax.set_title(self.get_title())
ax.set_xlabel("%s - %s" % (sel_dim, id_1))
ax.set_ylabel("%s - %s" % (sel_dim, id_2))
#ax.set_xlabel("%s - %s" % (sel_dim, id_1))
#ax.set_ylabel("%s - %s" % (sel_dim, id_2))
###
self.add(self.canvas)
self.canvas.show()
self._toolbar = NavToolbar(self.canvas, None)
self._toolbar = PlotToolbar(self.canvas, None)
self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
self._toolbar.set_property('show-arrow', False)
self._toolbar.set_select_callback(self.rectangle_select_callback)
@ -514,6 +549,8 @@ has no color and size options."""
self.selection_listener(self.current_dim, ids)
def selection_changed(self, selection):
if not self._sel_sensitive:
return
ids = selection[self.current_dim] # current identifiers
index = self.dataset_1.get_indices(self.current_dim, ids)
xdata_new = scipy.take(self.xaxis_data, index) #take data
@ -521,7 +558,7 @@ has no color and size options."""
#remove old selection
if self._selection_line:
self.ax.lines.remove(self._selection_line)
self._selection_line, = self.ax.plot(xdata_new,ydata_new,'or')
self._selection_line, = self.ax.plot(xdata_new,ydata_new,marker='o',markersize=self.ms,linestyle=None)
self._toolbar.forward() #update data lims before draw
self.canvas.draw()
@ -552,8 +589,8 @@ has no color and size options."""
self.add(self.canvas)
self.canvas.show()
self._toolbar = NavToolbar(self.canvas, None)
self._toolbar.set_property('show-arrow', False)
self._toolbar = PlotToolbar(self.canvas, None)
self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
self._toolbar.set_select_callback(self.rectangle_select_callback)
def get_toolbar(self):
@ -577,6 +614,8 @@ has no color and size options."""
self.selection_listener(self.current_dim, ids)
def selection_changed(self, selection):
if not self._sel_sensitive:
return
ids = selection[self.current_dim] # current identifiers
index = self.dataset_1.get_indices(self.current_dim, ids)
lw = scipy.zeros(self.xaxis_data.shape,'f')
@ -642,8 +681,8 @@ class NetworkPlot(Plot):
networkx.draw_networkx(self.graph, ax=self.ax, **kw)
# Setup toolbar
self._toolbar = NavToolbar(self.canvas, None)
self._toolbar.set_property('show-arrow', False)
self._toolbar = PlotToolbar(self.canvas, None)
self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
self._toolbar.set_select_callback(self.rectangle_select_callback)
def get_toolbar(self):