172 lines
4.8 KiB
Python
172 lines
4.8 KiB
Python
|
|
import pygtk
|
|
import gtk
|
|
import matplotlib
|
|
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
|
|
from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar
|
|
import scipy
|
|
import logger
|
|
|
|
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
|
|
|
|
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
|
|
child.show()
|
|
|
|
def remove_child(self, col, row):
|
|
self.remove(selv.child_views[col, row])
|
|
self.attach(col, row, EmptyView())
|
|
|
|
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])
|
|
|
|
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):
|
|
pass
|
|
|
|
def hide(self):
|
|
self.child_view.hide()
|
|
gtk.Frame.hide(self)
|
|
|
|
def show(self):
|
|
self.child_view.show()
|
|
gtk.Frame.show(self)
|
|
|
|
class Plot (gtk.Frame):
|
|
|
|
def __init__(self):
|
|
gtk.Frame.__init__(self)
|
|
self.mark_active(False)
|
|
self.connect('button_press_event', self.on_button_press)
|
|
|
|
def on_button_press(self, *rest):
|
|
logger.log('debug', 'button pressed in plot')
|
|
self.mark_active(True)
|
|
|
|
def get_toolbar(self, window):
|
|
return None
|
|
|
|
def mark_active(self, active):
|
|
if active:
|
|
self.set_shadow_type(gtk.SHADOW_IN)
|
|
else:
|
|
self.set_shadow_type(gtk.SHADOW_ETCHED_IN)
|
|
|
|
class EmptyView (Plot):
|
|
def __init__(self):
|
|
Plot.__init__(self)
|
|
|
|
label = gtk.Label('No view')
|
|
ebox = gtk.EventBox()
|
|
ebox.add(label)
|
|
self.add(ebox)
|
|
label.connect('button_press_event', self.on_button_press)
|
|
|
|
self.label = label
|
|
self.ebox = ebox
|
|
self.show()
|
|
|
|
def show(self):
|
|
self.ebox.show()
|
|
self.label.show()
|
|
Plot.show(self)
|
|
|
|
def hide(self):
|
|
self.label.hide()
|
|
self.ebox.hide()
|
|
Plot.hide(self)
|
|
|
|
class SinePlot (Plot):
|
|
|
|
def __init__(self):
|
|
Plot.__init__(self)
|
|
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)
|
|
self.canvas = FigureCanvas(fig)
|
|
self.add(self.canvas)
|
|
self.canvas.show()
|
|
|
|
def get_toolbar(self, window):
|
|
self.toolbar = NavigationToolbar(self.canvas, window)
|
|
self.toolbar.set_property('show-arrow', False)
|
|
return self.toolbar
|
|
|
|
class ScatterPlot (Plot):
|
|
def __init__(self):
|
|
Plot.__init__(self)
|
|
fig = Figure(figsize=(5,4), dpi=72)
|
|
ax = fig.add_subplot(111)
|
|
t = arange(0.0, 3.0, 0.01)
|
|
a = scipy.randn(200, 300)
|
|
fig.plot(a)
|
|
self.canvas = FigureCanvas(fig)
|
|
self.add(self.canvas)
|
|
self.canvas.show()
|
|
|
|
def get_toolbar(self, window):
|
|
self.toolbar = NavigationToolbar(self.canvas, window)
|
|
self.toolbar.set_property('show-arrow', False)
|
|
return self.toolbar
|
|
|