Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

cleaning up

This commit is contained in:
Arnar Flatberg 2006-08-30 13:39:32 +00:00
parent fc2891bad8
commit a670fc6b61
1 changed files with 18 additions and 27 deletions

View File

@ -225,8 +225,8 @@ class MainView (gtk.Notebook):
if focused: if focused:
self.emit('view-changed', vf) self.emit('view-changed', vf)
class Plot (gtk.Frame):
class Plot (gtk.Frame):
def __init__(self, title): def __init__(self, title):
gtk.Frame.__init__(self) gtk.Frame.__init__(self)
self.sel_obj = None self.sel_obj = None
@ -286,7 +286,6 @@ class EmptyView (Plot):
class NavToolbar(NavigationToolbar2): class NavToolbar(NavigationToolbar2):
toolitems = (('Select', 'Select within rectangle', 'zoom_to_rect.png', toolitems = (('Select', 'Select within rectangle', 'zoom_to_rect.png',
'select'),) + NavigationToolbar2.toolitems 'select'),) + NavigationToolbar2.toolitems
def __init__(self, *args): def __init__(self, *args):
NavigationToolbar2.__init__(self, *args) NavigationToolbar2.__init__(self, *args)
self._select_callback = None self._select_callback = None
@ -383,12 +382,11 @@ class PlotToolbar(NavToolbar):
""" """
def __init__(self, *args): def __init__(self, *args):
NavToolbar.__init__(self, *args) NavToolbar.__init__(self, *args)
iconSize = gtk.ICON_SIZE_SMALL_TOOLBAR
self.tb_freeze = gtk.ToolItem() self.tb_freeze = gtk.ToolItem()
self.chk = gtk.CheckButton () self.chk = gtk.CheckButton ()
self.chk.set_label ('Freeze') self.chk.set_label ('Freeze')
self.tb_freeze.add (self.chk) self.tb_freeze.add (self.chk)
self.tb_freeze.set_tooltip(self.tooltips, 'Freeze current selcetion updating') self.tb_freeze.set_tooltip(self.tooltips, 'Freeze current selection')
self.insert(self.tb_freeze,-1) self.insert(self.tb_freeze,-1)
toolitem = gtk.SeparatorToolItem() toolitem = gtk.SeparatorToolItem()
self.insert(toolitem, -1) self.insert(toolitem, -1)
@ -415,6 +413,7 @@ class LineViewPlot(Plot):
self.current_dim = self.dataset.get_dim_name(major_axis) self.current_dim = self.dataset.get_dim_name(major_axis)
if len(self._data.shape)==2 and not minor_axis: if len(self._data.shape)==2 and not minor_axis:
minor_axis = major_axis-1 minor_axis = major_axis-1
#initial draw #initial draw
self.line_collection = {} self.line_collection = {}
x_axis = scipy.arrayrange(self._data.shape[minor_axis]) x_axis = scipy.arrayrange(self._data.shape[minor_axis])
@ -428,11 +427,8 @@ class LineViewPlot(Plot):
self.add(self.canvas) self.add(self.canvas)
self.canvas.show() self.canvas.show()
# We use a regular toolbar as we don't need selections
#self._toolbar = NavigationToolbar2(self.canvas, None)
#self._toolbar.set_property('show-arrow', False)
#FIXME: Lineview plot cannot do selections -> disable in toolbar
self._toolbar = PlotToolbar(self.canvas, None) 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._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
@ -452,8 +448,8 @@ class LineViewPlot(Plot):
if self._background is None: if self._background is None:
self._last_index = None self._last_index = None
self._background = self.canvas.copy_from_bbox(self.ax.bbox) self._background = self.canvas.copy_from_bbox(self.ax.bbox)
self.canvas.restore_region(self._background) self.canvas.restore_region(self._background)
if index: if index:
if self._last_index: if self._last_index:
for i in self._last_index: for i in self._last_index:
@ -468,9 +464,9 @@ class LineViewPlot(Plot):
self.ax.lines[i].set_zorder(3) self.ax.lines[i].set_zorder(3)
if self.use_blit: if self.use_blit:
self.ax.draw_artist(self.ax.lines[i]) self.ax.draw_artist(self.ax.lines[i])
#else:
# self.ax.add_line(self.line_collection[i])
self._last_index = index self._last_index = index
if self.use_blit: if self.use_blit:
self.canvas.blit() self.canvas.blit()
else: else:
@ -481,10 +477,7 @@ class ScatterMarkerPlot(Plot):
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,s=6, 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 = 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.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
@ -493,18 +486,14 @@ has no color and size options."""
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,markersize=s) self.ax.plot(self.xaxis_data,self.yaxis_data,'o',markeredgewidth=0,markersize=s)
ax.set_title(self.get_title()) self.ax.set_title(self.get_title())
#ax.set_xlabel("%s - %s" % (sel_dim, id_1))
#ax.set_ylabel("%s - %s" % (sel_dim, id_2))
###
self.add(self.canvas) self.add(self.canvas)
self.canvas.show() self.canvas.show()
# add toolbar
self._toolbar = PlotToolbar(self.canvas, None) self._toolbar = PlotToolbar(self.canvas, None)
self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive) self._toolbar.chk.connect ('toggled' ,self.set_selection_sensitive)
self._toolbar.set_property('show-arrow', False) self._toolbar.set_property('show-arrow', False)
@ -526,7 +515,6 @@ has no color and size options."""
assert y1<=y2 assert y1<=y2
index = scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2)) index = scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2))
ids = self.dataset_1.get_identifiers(self.current_dim, index) ids = self.dataset_1.get_identifiers(self.current_dim, index)
self.selection_listener(self.current_dim, ids) self.selection_listener(self.current_dim, ids)
@ -538,16 +526,19 @@ 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,marker='o',markersize=self.ms,linestyle=None,markerfacecolor='r') self._selection_line, = self.ax.plot(xdata_new,ydata_new,marker='o',markersize=self.ms,linestyle=None,markerfacecolor='r')
self._toolbar.forward() #update data lims before draw self._toolbar.forward() #update data lims before draw
self.canvas.draw() self.canvas.draw()
class ScatterPlot(Plot): class ScatterPlot(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,c='b',s=30, name="Scatter plot"): def __init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2,c='b',s=30, name="Scatter plot"):
Plot.__init__(self, name) Plot.__init__(self, name)
self.ax = ax = self.fig.add_subplot(111) self.ax = self.fig.add_subplot(111)
self.current_dim = id_dim self.current_dim = id_dim
self.dataset_1 = dataset_1 self.dataset_1 = dataset_1
x_index = dataset_1[sel_dim][id_1] x_index = dataset_1[sel_dim][id_1]
@ -555,8 +546,8 @@ has no color and size options."""
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]
lw = scipy.zeros(self.xaxis_data.shape,'f') lw = scipy.zeros(self.xaxis_data.shape,'f')
ax.scatter(self.xaxis_data,self.yaxis_data,s=s,c=c,linewidth=lw,edgecolor='k',alpha=.6,cmap = cm.Set1) self.ax.scatter(self.xaxis_data,self.yaxis_data,s=s,c=c,linewidth=lw,edgecolor='k',alpha=.6,cmap = cm.Set1)
ax.set_title(self.get_title()) self.ax.set_title(self.get_title())
# collection # collection
self.coll = ax.collections[0] self.coll = ax.collections[0]
@ -599,6 +590,7 @@ has no color and size options."""
self.coll.set_zorder(zo) self.coll.set_zorder(zo)
self._toolbar.forward() #update data lims before draw self._toolbar.forward() #update data lims before draw
self.canvas.draw() self.canvas.draw()
class NetworkPlot(Plot): class NetworkPlot(Plot):
def __init__(self, dataset, **kw): def __init__(self, dataset, **kw):
@ -607,7 +599,6 @@ class NetworkPlot(Plot):
self.dataset = dataset self.dataset = dataset
self.keywords = kw self.keywords = kw
self.dim_name = self.dataset.get_dim_name(0) self.dim_name = self.dataset.get_dim_name(0)
if not kw.has_key('name'): if not kw.has_key('name'):
kw['name'] = self.dataset.get_name() kw['name'] = self.dataset.get_name()
if not kw.has_key('prog'): if not kw.has_key('prog'):