73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
|
|
import gtk
|
|
import gobject
|
|
import plots
|
|
from system import dataset, logger, plots, project
|
|
|
|
class NavigatorView (gtk.TreeView):
|
|
def __init__(self, project, app):
|
|
self.project = project
|
|
self.app = app
|
|
if project:
|
|
self.data_tree = project.data_tree
|
|
else:
|
|
self.data_tree = None
|
|
|
|
gtk.TreeView.__init__(self) #, self.data_tree)
|
|
|
|
self.set_headers_visible(False)
|
|
self.connect('cursor_changed', self.cursor_changed_handler)
|
|
self.connect('row_activated', self.row_activated_handler)
|
|
|
|
renderer = gtk.CellRendererText()
|
|
self.object_col = gtk.TreeViewColumn('Object', renderer, text=0)
|
|
self.append_column(self.object_col)
|
|
|
|
logger.log('debug', 'Initializing navigator window.')
|
|
|
|
def add_project(self, project):
|
|
self.project = project
|
|
self.data_tree = project.data_tree
|
|
self.set_model(project.data_tree)
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
def display_data_info(self, data):
|
|
dims = zip(data.get_dim_names(), data.shape)
|
|
|
|
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()
|
|
|
|
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)
|
|
|
|
if isinstance(obj, plots.Plot):
|
|
logger.log('debug', 'Activating plot')
|
|
self.app.change_plot(obj)
|
|
elif isinstance(obj, dataset.Dataset):
|
|
self.display_data_info(obj)
|
|
else:
|
|
t = type(obj)
|
|
logger.log('debug', 'Activated datatype was %s. Don\'t know what to do.' % t)
|