2006-04-16 20:25:54 +02:00
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
import plots
|
2006-04-25 11:53:35 +02:00
|
|
|
from system import dataset, logger, plots, project
|
2006-04-16 20:25:54 +02:00
|
|
|
|
|
|
|
class NavigatorView (gtk.TreeView):
|
2006-04-21 11:23:05 +02:00
|
|
|
def __init__(self, project, app):
|
|
|
|
self.project = project
|
2006-04-16 20:25:54 +02:00
|
|
|
self.app = app
|
2006-04-22 23:46:44 +02:00
|
|
|
if project:
|
|
|
|
self.data_tree = project.data_tree
|
|
|
|
else:
|
|
|
|
self.data_tree = None
|
2006-04-21 11:23:05 +02:00
|
|
|
|
2006-04-22 23:46:44 +02:00
|
|
|
gtk.TreeView.__init__(self) #, self.data_tree)
|
2006-04-16 20:25:54 +02:00
|
|
|
|
|
|
|
self.set_headers_visible(False)
|
2006-04-21 16:29:08 +02:00
|
|
|
self.connect('cursor_changed', self.cursor_changed_handler)
|
2006-04-21 16:59:25 +02:00
|
|
|
self.connect('row_activated', self.row_activated_handler)
|
2006-04-16 20:25:54 +02:00
|
|
|
|
2006-04-27 16:15:13 +02:00
|
|
|
# self.connect('row_inserted', self.row_changed_handler)
|
|
|
|
|
2006-04-16 20:25:54 +02:00
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
self.object_col = gtk.TreeViewColumn('Object', renderer, text=0)
|
|
|
|
self.append_column(self.object_col)
|
|
|
|
|
2006-04-21 12:56:56 +02:00
|
|
|
logger.log('debug', 'Initializing navigator window.')
|
2006-04-16 20:25:54 +02:00
|
|
|
|
2006-04-22 23:46:44 +02:00
|
|
|
def add_project(self, project):
|
|
|
|
self.project = project
|
|
|
|
self.data_tree = project.data_tree
|
|
|
|
self.set_model(project.data_tree)
|
2006-04-27 16:15:13 +02:00
|
|
|
self.data_tree.connect('row-changed',self.row_changed_handler)
|
2006-04-22 23:46:44 +02:00
|
|
|
|
2006-04-21 16:29:08 +02:00
|
|
|
def cursor_changed_handler(self, widget):
|
|
|
|
selection = widget.get_selection()
|
|
|
|
model, tree_iter = selection.get_selected()
|
|
|
|
obj = self.data_tree.get_value(tree_iter, 2)
|
|
|
|
|
2006-04-21 16:59:25 +02:00
|
|
|
if isinstance(obj, dataset.Dataset):
|
|
|
|
logger.log('debug', 'Selecting dataset')
|
|
|
|
self.project.set_current_data(obj)
|
|
|
|
elif not isinstance(obj, plots.Plot):
|
|
|
|
t = type(obj)
|
|
|
|
logger.log('debug', 'Selected datatype was %s. Don\'t know what to do.' % t)
|
|
|
|
|
2006-04-27 16:15:13 +02:00
|
|
|
# TreeView changed. Expand new items!
|
|
|
|
def row_changed_handler(self, treestore, pos, iter):
|
|
|
|
obj = treestore.get_value(iter,2)
|
|
|
|
if not treestore.get_value(iter,2):
|
|
|
|
return
|
|
|
|
self.expand_to_path(pos)
|
|
|
|
|
|
|
|
if isinstance(treestore.get_value(iter,2),dataset.Dataset):
|
|
|
|
self.set_cursor(pos)
|
|
|
|
|
2006-04-21 17:02:13 +02:00
|
|
|
def display_data_info(self, data):
|
2006-04-24 13:39:11 +02:00
|
|
|
dims = zip(data.get_dim_names(), data.shape)
|
2006-04-21 17:02:13 +02:00
|
|
|
|
|
|
|
dim_text = ", ".join(["%s (%d)" % dim for dim in dims])
|
|
|
|
|
|
|
|
text = """<span weight="bold">Data:</span> %s
|
|
|
|
|
|
|
|
<span weight="bold">Dimensions:</span> %s""" % (data.get_name(), dim_text)
|
|
|
|
|
|
|
|
d = gtk.MessageDialog(flags=(gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT),
|
|
|
|
buttons=gtk.BUTTONS_OK)
|
|
|
|
d.set_markup(text)
|
|
|
|
d.set_default_response(gtk.BUTTONS_OK)
|
|
|
|
d.run()
|
|
|
|
d.destroy()
|
|
|
|
|
2006-04-21 16:59:25 +02:00
|
|
|
def row_activated_handler(self, widget, path, column):
|
|
|
|
tree_iter = self.data_tree.get_iter(path)
|
|
|
|
obj = self.data_tree.get_value(tree_iter, 2)
|
|
|
|
|
2006-04-21 11:23:05 +02:00
|
|
|
if isinstance(obj, plots.Plot):
|
|
|
|
logger.log('debug', 'Activating plot')
|
|
|
|
self.app.change_plot(obj)
|
|
|
|
elif isinstance(obj, dataset.Dataset):
|
2006-04-21 17:02:13 +02:00
|
|
|
self.display_data_info(obj)
|
2006-04-21 11:23:05 +02:00
|
|
|
else:
|
|
|
|
t = type(obj)
|
2006-04-21 16:59:25 +02:00
|
|
|
logger.log('debug', 'Activated datatype was %s. Don\'t know what to do.' % t)
|