2006-04-16 20:25:54 +02:00
|
|
|
|
|
|
|
import pygtk
|
|
|
|
import gtk
|
|
|
|
import matplotlib
|
2006-04-19 20:25:44 +02:00
|
|
|
import scipy
|
2006-04-16 20:25:54 +02:00
|
|
|
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
|
|
|
|
from matplotlib.axes import Subplot
|
|
|
|
from matplotlib.figure import Figure
|
|
|
|
from matplotlib.numerix import arange, sin, pi
|
2006-04-18 11:19:59 +02:00
|
|
|
from matplotlib.widgets import RectangleSelector
|
2006-04-25 11:53:35 +02:00
|
|
|
from system import logger
|
2006-04-18 11:19:59 +02:00
|
|
|
|
2006-04-16 20:25:54 +02:00
|
|
|
|
2006-04-18 00:30:53 +02:00
|
|
|
class MainView (gtk.Notebook):
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Notebook.__init__(self)
|
|
|
|
self.set_show_tabs(False)
|
|
|
|
self.set_show_border(False)
|
|
|
|
|
|
|
|
# Add a multiple pane view and a single pane view.
|
|
|
|
self.small_view = SmallView()
|
|
|
|
self.small_view.show()
|
|
|
|
self.large_view = LargeView()
|
|
|
|
self.large_view.show()
|
|
|
|
|
|
|
|
self.append_page(self.small_view)
|
|
|
|
self.append_page(self.large_view)
|
|
|
|
self.set_current_page(0)
|
|
|
|
|
|
|
|
def goto_small(self):
|
|
|
|
if self.get_current_page() == 0:
|
|
|
|
return None
|
|
|
|
self.set_current_page(0)
|
|
|
|
view = self.large_view.remove_child()
|
|
|
|
self.small_view.return_current(view)
|
|
|
|
|
|
|
|
def goto_large(self):
|
|
|
|
if self.get_current_page() == 1:
|
|
|
|
return None
|
|
|
|
self.set_current_page(1)
|
|
|
|
view = self.small_view.borrow_current()
|
|
|
|
self.large_view.set_child(view)
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
gtk.Notebook.show(self)
|
|
|
|
|
|
|
|
def insert_view(self, view):
|
|
|
|
self.small_view.insert_view(view)
|
|
|
|
|
2006-04-17 22:27:39 +02:00
|
|
|
class SmallView (gtk.Table):
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Table.__init__(self, 2, 2, True)
|
|
|
|
|
|
|
|
self.child_views = [[EmptyView(), EmptyView()],
|
|
|
|
[EmptyView(), EmptyView()]]
|
|
|
|
self.cols = 2
|
|
|
|
self.rows = 2
|
|
|
|
|
|
|
|
self.active_x = 0
|
|
|
|
self.active_y = 0
|
2006-04-18 00:30:53 +02:00
|
|
|
|
|
|
|
self.set_row_spacings(3)
|
|
|
|
self.set_col_spacings(3)
|
2006-04-17 22:27:39 +02:00
|
|
|
|
|
|
|
for x in range(self.cols):
|
|
|
|
for y in range(self.rows):
|
|
|
|
child = self.child_views[x][y]
|
|
|
|
child.parent_signalling = child.connect('button_press_event', self.__view_button_event__)
|
|
|
|
self.attach(child, x, x+1, y, y+1)
|
|
|
|
|
|
|
|
def set_child(self, child, col, row):
|
|
|
|
cur_widget = self.child_views[col][row]
|
|
|
|
cur_widget.disconnect(cur_widget.parent_signalling)
|
|
|
|
self.remove(cur_widget)
|
|
|
|
self.attach(child, col, col+1, row, row+1)
|
|
|
|
child.parent_signalling = child.connect('button_press_event', self.__view_button_event__)
|
|
|
|
self.child_views[col][row] = child
|
2006-04-20 12:34:50 +02:00
|
|
|
if cur_widget.active:
|
|
|
|
child.mark_active(True)
|
|
|
|
cur_widget.mark_active(False)
|
2006-04-17 22:27:39 +02:00
|
|
|
child.show()
|
|
|
|
|
2006-04-18 00:30:53 +02:00
|
|
|
def borrow_current(self):
|
|
|
|
self.borrowed = self.child_views[self.active_x][self.active_y]
|
|
|
|
self.remove_child(self.active_x, self.active_y)
|
|
|
|
return self.borrowed
|
|
|
|
|
|
|
|
def return_current(self, view):
|
|
|
|
self.set_child(view, self.active_x, self.active_y)
|
|
|
|
|
2006-04-17 22:27:39 +02:00
|
|
|
def remove_child(self, col, row):
|
2006-04-18 00:30:53 +02:00
|
|
|
self.remove(self.child_views[col][row])
|
|
|
|
self.attach(EmptyView(), col, col+1, row, row+1)
|
2006-04-17 22:27:39 +02:00
|
|
|
|
2006-04-18 00:30:53 +02:00
|
|
|
def insert_view(self, child):
|
|
|
|
if not self.find_child(child):
|
|
|
|
self.set_child(child, self.active_x, self.active_y)
|
|
|
|
|
2006-04-17 22:27:39 +02:00
|
|
|
def show(self):
|
|
|
|
for x in self.child_views:
|
|
|
|
for y in x:
|
|
|
|
y.show()
|
|
|
|
gtk.Table.show(self)
|
|
|
|
|
|
|
|
def hide(self):
|
|
|
|
for x in self.child_views:
|
|
|
|
for y in x:
|
|
|
|
y.hide()
|
|
|
|
gtk.Table.hide(self)
|
|
|
|
|
|
|
|
def set_active(self, x, y):
|
|
|
|
old_focus = self.child_views[self.active_x][self.active_y]
|
|
|
|
new_focus = self.child_views[x][y]
|
|
|
|
old_focus.mark_active(False)
|
|
|
|
new_focus.mark_active(True)
|
|
|
|
self.active_x = x
|
|
|
|
self.active_y = y
|
|
|
|
|
|
|
|
def find_child(self, child):
|
|
|
|
for i, row in enumerate(self.child_views):
|
|
|
|
for j, v in enumerate(row):
|
|
|
|
if v == child:
|
|
|
|
return (i, j)
|
|
|
|
return None
|
|
|
|
|
|
|
|
def __view_button_event__(self, view, *rest):
|
|
|
|
loc = self.find_child(view)
|
|
|
|
if loc:
|
|
|
|
self.set_active(loc[0], loc[1])
|
|
|
|
|
2006-04-18 00:30:53 +02:00
|
|
|
def get_view(self, x, y):
|
|
|
|
return self.child_views[x][y]
|
|
|
|
|
2006-04-17 22:27:39 +02:00
|
|
|
class LargeView (gtk.Frame):
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Frame.__init__(self)
|
|
|
|
self.child_view = EmptyView()
|
|
|
|
self.add(self.child_view)
|
|
|
|
|
|
|
|
def set_child(self, child):
|
2006-04-18 00:30:53 +02:00
|
|
|
self.remove(self.child_view)
|
|
|
|
self.child_view.hide()
|
|
|
|
self.add(child)
|
|
|
|
self.child_view = child
|
|
|
|
child.show()
|
2006-04-17 22:27:39 +02:00
|
|
|
|
|
|
|
def hide(self):
|
|
|
|
self.child_view.hide()
|
|
|
|
gtk.Frame.hide(self)
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
self.child_view.show()
|
|
|
|
gtk.Frame.show(self)
|
|
|
|
|
2006-04-18 00:30:53 +02:00
|
|
|
def remove_child(self):
|
|
|
|
child = self.child_view
|
|
|
|
child.hide()
|
|
|
|
self.remove(child)
|
|
|
|
return child
|
|
|
|
|
2006-04-16 20:25:54 +02:00
|
|
|
class Plot (gtk.Frame):
|
|
|
|
|
2006-04-24 16:52:21 +02:00
|
|
|
def __init__(self, title):
|
2006-04-16 20:25:54 +02:00
|
|
|
gtk.Frame.__init__(self)
|
|
|
|
self.mark_active(False)
|
|
|
|
self.connect('button_press_event', self.on_button_press)
|
2006-04-18 16:25:46 +02:00
|
|
|
self.sel_obj = None
|
2006-04-20 12:34:50 +02:00
|
|
|
self.active = False
|
2006-04-24 16:52:21 +02:00
|
|
|
self.title = title
|
|
|
|
|
|
|
|
def get_title(self):
|
|
|
|
return self.title
|
|
|
|
|
2006-04-16 20:25:54 +02:00
|
|
|
def on_button_press(self, *rest):
|
2006-04-22 23:46:44 +02:00
|
|
|
# logger.log('debug', 'button pressed in plot')
|
2006-04-16 20:25:54 +02:00
|
|
|
self.mark_active(True)
|
|
|
|
|
|
|
|
def mark_active(self, active):
|
|
|
|
if active:
|
|
|
|
self.set_shadow_type(gtk.SHADOW_IN)
|
|
|
|
else:
|
2006-04-18 00:30:53 +02:00
|
|
|
self.set_shadow_type(gtk.SHADOW_OUT)
|
2006-04-20 12:34:50 +02:00
|
|
|
self.active = active
|
2006-04-18 16:25:46 +02:00
|
|
|
|
2006-04-24 16:42:45 +02:00
|
|
|
def update(self, key):
|
2006-04-19 20:25:44 +02:00
|
|
|
pass
|
2006-04-24 16:42:45 +02:00
|
|
|
|
|
|
|
def set_project(self, project):
|
|
|
|
self.project = project
|
2006-04-25 12:08:12 +02:00
|
|
|
|
2006-04-18 16:25:46 +02:00
|
|
|
|
2006-04-17 22:27:39 +02:00
|
|
|
class EmptyView (Plot):
|
2006-04-16 20:25:54 +02:00
|
|
|
def __init__(self):
|
2006-04-24 16:52:21 +02:00
|
|
|
Plot.__init__(self, 'Empty view')
|
2006-04-17 22:27:39 +02:00
|
|
|
|
|
|
|
label = gtk.Label('No view')
|
|
|
|
ebox = gtk.EventBox()
|
|
|
|
ebox.add(label)
|
|
|
|
self.add(ebox)
|
|
|
|
label.connect('button_press_event', self.on_button_press)
|
2006-04-16 20:25:54 +02:00
|
|
|
|
2006-04-17 22:27:39 +02:00
|
|
|
self.label = label
|
|
|
|
self.ebox = ebox
|
|
|
|
self.show()
|
2006-04-16 20:25:54 +02:00
|
|
|
|
2006-04-17 22:27:39 +02:00
|
|
|
def show(self):
|
|
|
|
self.ebox.show()
|
|
|
|
self.label.show()
|
|
|
|
Plot.show(self)
|
|
|
|
|
|
|
|
def hide(self):
|
|
|
|
self.label.hide()
|
|
|
|
self.ebox.hide()
|
|
|
|
Plot.hide(self)
|
|
|
|
|
2006-04-21 16:45:01 +02:00
|
|
|
|
2006-04-20 12:27:58 +02:00
|
|
|
class SinePlot(Plot):
|
2006-04-24 16:42:45 +02:00
|
|
|
def __init__(self):
|
2006-04-24 16:52:21 +02:00
|
|
|
Plot.__init__(self, 'Sine plot')
|
|
|
|
|
2006-04-16 20:25:54 +02:00
|
|
|
fig = Figure(figsize=(5,4), dpi=72)
|
|
|
|
ax = fig.add_subplot(111)
|
|
|
|
t = arange(0.0,3.0,0.01)
|
|
|
|
s = sin(2*pi*t)
|
|
|
|
ax.plot(t,s)
|
2006-04-24 16:52:21 +02:00
|
|
|
|
2006-04-16 20:25:54 +02:00
|
|
|
self.canvas = FigureCanvas(fig)
|
|
|
|
self.add(self.canvas)
|
|
|
|
self.canvas.show()
|
|
|
|
|
2006-04-17 22:27:39 +02:00
|
|
|
|
2006-04-20 12:27:58 +02:00
|
|
|
class ScatterPlot(Plot):
|
2006-04-24 16:52:21 +02:00
|
|
|
def __init__(self, dataset,id_dim, sel_dim,id_1,id_2):
|
|
|
|
Plot.__init__(self, 'Scatter plot')
|
2006-04-16 20:25:54 +02:00
|
|
|
fig = Figure(figsize=(5,4), dpi=72)
|
2006-04-18 11:19:59 +02:00
|
|
|
self.ax = ax = fig.add_subplot(111)
|
2006-04-24 11:53:07 +02:00
|
|
|
self.current_dim = id_dim
|
2006-04-19 20:25:44 +02:00
|
|
|
# testing testing
|
2006-04-24 11:53:07 +02:00
|
|
|
self.dataset = dataset
|
|
|
|
x_index = dataset[sel_dim][id_1]
|
|
|
|
y_index = dataset[sel_dim][id_2]
|
|
|
|
|
|
|
|
self.xaxis_data = dataset._array[:,x_index]
|
|
|
|
self.yaxis_data = dataset._array[:,y_index]
|
|
|
|
ax.plot(self.xaxis_data,self.yaxis_data,'og')
|
2006-04-19 20:25:44 +02:00
|
|
|
###
|
|
|
|
|
2006-04-16 20:25:54 +02:00
|
|
|
self.canvas = FigureCanvas(fig)
|
|
|
|
self.add(self.canvas)
|
2006-04-19 20:25:44 +02:00
|
|
|
rectprops = dict(facecolor='gray', edgecolor = 'black',
|
|
|
|
alpha=0.2, fill=True) #cool
|
2006-04-24 11:53:07 +02:00
|
|
|
self.sel = RectangleSelector(ax, self.rectangle_select_callback,
|
2006-04-18 16:25:46 +02:00
|
|
|
drawtype='box',useblit=True,rectprops=rectprops)
|
2006-04-18 11:19:59 +02:00
|
|
|
|
2006-04-16 20:25:54 +02:00
|
|
|
self.canvas.show()
|
|
|
|
|
2006-04-19 20:25:44 +02:00
|
|
|
def rectangle_select_callback(self,event1, event2):
|
2006-04-18 11:19:59 +02:00
|
|
|
'event1 and event2 are the press and release events'
|
|
|
|
x1, y1 = event1.xdata, event1.ydata
|
|
|
|
x2, y2 = event2.xdata, event2.ydata
|
2006-04-19 12:37:44 +02:00
|
|
|
ydata = self.yaxis_data
|
|
|
|
xdata = self.xaxis_data
|
2006-04-25 12:08:12 +02:00
|
|
|
|
|
|
|
# find indices of selected area
|
2006-04-19 12:37:44 +02:00
|
|
|
if x1>x2:
|
|
|
|
if y1<y2:
|
|
|
|
index =scipy.nonzero((xdata<x1) & (xdata>x2) & (ydata>y1) & (ydata<y2))
|
|
|
|
else:
|
|
|
|
index =scipy.nonzero((xdata<x1) & (xdata>x2) & (ydata<y1) & (ydata>y2))
|
|
|
|
else:
|
2006-04-24 11:53:07 +02:00
|
|
|
#logger.log('debug','Selection x_start less than x_end')
|
2006-04-19 12:37:44 +02:00
|
|
|
if y1<y2:
|
2006-04-24 11:53:07 +02:00
|
|
|
#logger.log('debug','Selection y_start less than y_end')
|
2006-04-19 20:25:44 +02:00
|
|
|
index =scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata>y1) & (ydata<y2))
|
2006-04-19 12:37:44 +02:00
|
|
|
else:
|
2006-04-24 11:53:07 +02:00
|
|
|
#logger.log('debug','Selection y_start bigger than y_end')
|
2006-04-19 20:25:44 +02:00
|
|
|
index =scipy.nonzero((xdata>x1) & (xdata<x2) & (ydata<y1) & (ydata>y2))
|
|
|
|
|
2006-04-25 12:08:12 +02:00
|
|
|
# generate ids for selected indices
|
|
|
|
reverse = {}
|
|
|
|
for key, value in self.dataset[self.current_dim].items():
|
|
|
|
reverse[value] = key
|
|
|
|
ids = []
|
|
|
|
for ind in index:
|
|
|
|
ids.append(reverse[ind])
|
|
|
|
|
2006-04-24 16:28:30 +02:00
|
|
|
self.project.set_selection(self.current_dim,ids)
|
2006-04-19 20:25:44 +02:00
|
|
|
|
2006-04-24 16:42:45 +02:00
|
|
|
def update(self, key):
|
|
|
|
curr_sel = self.project.get_selection() # get selection object
|
2006-04-19 20:50:10 +02:00
|
|
|
ids = curr_sel[self.current_dim] # current identifiers
|
2006-04-24 11:53:07 +02:00
|
|
|
|
|
|
|
index = [ind for id,ind in self.dataset[self.current_dim].items() if id in ids] #conversion to index
|
2006-04-19 20:50:10 +02:00
|
|
|
xdata_new = scipy.take(self.xaxis_data,index) #take data
|
2006-04-19 20:25:44 +02:00
|
|
|
ydata_new = scipy.take(self.yaxis_data,index)
|
2006-04-24 16:25:24 +02:00
|
|
|
self.ax.clear()
|
2006-04-24 11:53:07 +02:00
|
|
|
self.ax.plot(self.xaxis_data,self.yaxis_data,'og')
|
2006-04-19 20:25:44 +02:00
|
|
|
self.ax.plot(xdata_new,ydata_new,'or')
|
|
|
|
self.canvas.draw()
|