Added extended toolbar with selection freeze
This commit is contained in:
parent
97e652edce
commit
ae7a6a5a0e
|
@ -1,4 +1,4 @@
|
||||||
|
import os,sys
|
||||||
import pygtk
|
import pygtk
|
||||||
import gobject
|
import gobject
|
||||||
import gtk
|
import gtk
|
||||||
|
@ -238,6 +238,16 @@ class Plot (gtk.Frame):
|
||||||
self.fig = Figure(figsize=(5,4), dpi=72)
|
self.fig = Figure(figsize=(5,4), dpi=72)
|
||||||
self.canvas = FigureCanvas(self.fig)
|
self.canvas = FigureCanvas(self.fig)
|
||||||
self.fig.set_facecolor('white')
|
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):
|
def get_title(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
@ -298,7 +308,6 @@ class NavToolbar(NavigationToolbar2):
|
||||||
self._idPress = self.canvas.mpl_connect('button_press_event', self.press_select)
|
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._idRelease = self.canvas.mpl_connect('button_release_event', self.release_select)
|
||||||
self.mode = 'Select rectangle mode'
|
self.mode = 'Select rectangle mode'
|
||||||
|
|
||||||
self.set_message(self.mode)
|
self.set_message(self.mode)
|
||||||
|
|
||||||
def set_message(self, s):
|
def set_message(self, s):
|
||||||
|
@ -366,6 +375,23 @@ class NavToolbar(NavigationToolbar2):
|
||||||
self._select_callback = listener
|
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):
|
class SinePlot(Plot):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Plot.__init__(self, 'Sine plot')
|
Plot.__init__(self, 'Sine plot')
|
||||||
|
@ -420,10 +446,15 @@ class LineViewPlot(Plot):
|
||||||
self.canvas.show()
|
self.canvas.show()
|
||||||
|
|
||||||
# We use a regular toolbar as we don't need selections
|
# 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.set_property('show-arrow', False)
|
||||||
|
self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
|
||||||
self.canvas.mpl_connect('resize_event',self.clear_background)
|
self.canvas.mpl_connect('resize_event',self.clear_background)
|
||||||
|
|
||||||
|
|
||||||
def get_toolbar(self):
|
def get_toolbar(self):
|
||||||
return self._toolbar
|
return self._toolbar
|
||||||
|
|
||||||
|
@ -431,6 +462,8 @@ class LineViewPlot(Plot):
|
||||||
self._background = None
|
self._background = None
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def selection_changed(self, selection):
|
||||||
|
if not self._sel_sensitive:
|
||||||
|
return
|
||||||
ids = selection[self.current_dim] # current identifiers
|
ids = selection[self.current_dim] # current identifiers
|
||||||
index = self.dataset.get_indices(self.current_dim, ids)
|
index = self.dataset.get_indices(self.current_dim, ids)
|
||||||
if self.use_blit:
|
if self.use_blit:
|
||||||
|
@ -464,32 +497,34 @@ class LineViewPlot(Plot):
|
||||||
class ScatterMarkerPlot(Plot):
|
class ScatterMarkerPlot(Plot):
|
||||||
"""The ScatterMarkerPlot is faster than regular scatterplot, but
|
"""The ScatterMarkerPlot is faster than regular scatterplot, but
|
||||||
has no color and size options."""
|
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)
|
Plot.__init__(self, name)
|
||||||
self.ax = ax = self.fig.add_subplot(111)
|
self.ax = ax = self.fig.add_subplot(111)
|
||||||
#self.ax.set_position([0.01,0.01,.99,.99])
|
#self.ax.set_position([0.01,0.01,.99,.99])
|
||||||
self.ax.set_xticks([])
|
#self.ax.set_xticks([])
|
||||||
self.ax.set_yticks([])
|
#self.ax.set_yticks([])
|
||||||
self.ax.axhline(0,color='k',lw=1.5,zorder=0)
|
self.ax.axhline(0,color='k',lw=1.5,zorder=0)
|
||||||
self.ax.axvline(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.current_dim = id_dim
|
||||||
self.dataset_1 = dataset_1
|
self.dataset_1 = dataset_1
|
||||||
|
self.ms = s
|
||||||
self._selection_line = None
|
self._selection_line = None
|
||||||
x_index = dataset_1[sel_dim][id_1]
|
x_index = dataset_1[sel_dim][id_1]
|
||||||
y_index = dataset_2[sel_dim][id_2]
|
y_index = dataset_2[sel_dim][id_2]
|
||||||
|
|
||||||
self.xaxis_data = dataset_1._array[:,x_index]
|
self.xaxis_data = dataset_1._array[:,x_index]
|
||||||
self.yaxis_data = dataset_2._array[:,y_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_title(self.get_title())
|
||||||
ax.set_xlabel("%s - %s" % (sel_dim, id_1))
|
#ax.set_xlabel("%s - %s" % (sel_dim, id_1))
|
||||||
ax.set_ylabel("%s - %s" % (sel_dim, id_2))
|
#ax.set_ylabel("%s - %s" % (sel_dim, id_2))
|
||||||
|
|
||||||
###
|
###
|
||||||
self.add(self.canvas)
|
self.add(self.canvas)
|
||||||
self.canvas.show()
|
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_property('show-arrow', False)
|
||||||
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
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)
|
self.selection_listener(self.current_dim, ids)
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def selection_changed(self, selection):
|
||||||
|
if not self._sel_sensitive:
|
||||||
|
return
|
||||||
ids = selection[self.current_dim] # current identifiers
|
ids = selection[self.current_dim] # current identifiers
|
||||||
index = self.dataset_1.get_indices(self.current_dim, ids)
|
index = self.dataset_1.get_indices(self.current_dim, ids)
|
||||||
xdata_new = scipy.take(self.xaxis_data, index) #take data
|
xdata_new = scipy.take(self.xaxis_data, index) #take data
|
||||||
|
@ -521,7 +558,7 @@ has no color and size options."""
|
||||||
#remove old selection
|
#remove old selection
|
||||||
if self._selection_line:
|
if self._selection_line:
|
||||||
self.ax.lines.remove(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._toolbar.forward() #update data lims before draw
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
|
||||||
|
@ -552,8 +589,8 @@ has no color and size options."""
|
||||||
self.add(self.canvas)
|
self.add(self.canvas)
|
||||||
self.canvas.show()
|
self.canvas.show()
|
||||||
|
|
||||||
self._toolbar = NavToolbar(self.canvas, None)
|
self._toolbar = PlotToolbar(self.canvas, None)
|
||||||
self._toolbar.set_property('show-arrow', False)
|
self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
|
||||||
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
||||||
|
|
||||||
def get_toolbar(self):
|
def get_toolbar(self):
|
||||||
|
@ -577,6 +614,8 @@ has no color and size options."""
|
||||||
self.selection_listener(self.current_dim, ids)
|
self.selection_listener(self.current_dim, ids)
|
||||||
|
|
||||||
def selection_changed(self, selection):
|
def selection_changed(self, selection):
|
||||||
|
if not self._sel_sensitive:
|
||||||
|
return
|
||||||
ids = selection[self.current_dim] # current identifiers
|
ids = selection[self.current_dim] # current identifiers
|
||||||
index = self.dataset_1.get_indices(self.current_dim, ids)
|
index = self.dataset_1.get_indices(self.current_dim, ids)
|
||||||
lw = scipy.zeros(self.xaxis_data.shape,'f')
|
lw = scipy.zeros(self.xaxis_data.shape,'f')
|
||||||
|
@ -642,8 +681,8 @@ class NetworkPlot(Plot):
|
||||||
networkx.draw_networkx(self.graph, ax=self.ax, **kw)
|
networkx.draw_networkx(self.graph, ax=self.ax, **kw)
|
||||||
|
|
||||||
# Setup toolbar
|
# Setup toolbar
|
||||||
self._toolbar = NavToolbar(self.canvas, None)
|
self._toolbar = PlotToolbar(self.canvas, None)
|
||||||
self._toolbar.set_property('show-arrow', False)
|
self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
|
||||||
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
self._toolbar.set_select_callback(self.rectangle_select_callback)
|
||||||
|
|
||||||
def get_toolbar(self):
|
def get_toolbar(self):
|
||||||
|
|
Reference in New Issue