Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0
This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
laydi/system/navigator.py

108 lines
3.7 KiB
Python
Raw Normal View History

import gtk
import gobject
import plots
from system import dataset, logger, plots, project, workflow
class NavigatorView (gtk.TreeView):
2006-04-21 11:23:05 +02:00
def __init__(self, project, app):
self.project = project
self.app = app
if project:
self.data_tree = project.data_tree
else:
self.data_tree = None
2006-04-21 11:23:05 +02:00
gtk.TreeView.__init__(self)
self.set_headers_visible(False)
self.connect('cursor_changed', self.cursor_changed_handler)
self.connect('row_activated', self.row_activated_handler)
#pixrenderer = gtk.CellRendererPixbuf()
textrenderer = gtk.CellRendererText()
self.object_col = gtk.TreeViewColumn('Object')
#self.object_col.pack_start(pixrenderer)
self.object_col.pack_start(textrenderer)
self.object_col.set_attributes(textrenderer, cell_background=3, foreground = 4, text=0)
self.append_column(self.object_col)
2006-05-02 13:09:55 +02:00
# drag'n'drop
self.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,[("GTK_TREE_MODEL_ROW",gtk.TARGET_SAME_APP,7)], gtk.gdk.ACTION_LINK)
self.connect("drag-data-get",self.slot_drag_data)
2006-04-21 12:56:56 +02:00
logger.log('debug', 'Initializing navigator window.')
2006-05-02 13:09:55 +02:00
# sets data for drag event.
def slot_drag_data(self,treeview,context,selection,target_id,etime):
treeselection = treeview.get_selection()
model, iter = treeselection.get_selected()
path = model.get_path(iter)
self.data_tree.drag_data_get(path, selection)
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)
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)
2006-05-02 13:09:55 +02:00
else:
t = type(obj)
logger.log('debug', 'Selected datatype was %s. Don\'t know what to do.' % t)
# TreeView changed. Set correct focus and colours
2006-04-27 16:15:13 +02:00
def row_changed_handler(self, treestore, pos, iter):
obj = treestore.get_value(iter,2)
type_= treestore.get_value(iter,1)
if not (treestore.get_value(iter,2) or treestore.get_value(iter,1)):
2006-04-27 16:15:13 +02:00
return
2006-04-27 16:15:13 +02:00
self.expand_to_path(pos)
if isinstance(obj,dataset.Dataset):
2006-04-27 16:15:13 +02:00
self.set_cursor(pos)
2006-04-27 16:15:13 +02:00
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)
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):
self.display_data_info(obj)
2006-04-21 11:23:05 +02:00
else:
t = type(obj)
logger.log('debug', 'Activated datatype was %s. Don\'t know what to do.' % t)