2006-08-08 10:48:55 +02:00
|
|
|
|
|
|
|
from system import logger, dataset
|
|
|
|
|
|
|
|
import pygtk
|
|
|
|
import gtk
|
|
|
|
import gtk.gdk
|
|
|
|
import gtk.glade
|
|
|
|
import gnome
|
|
|
|
import gnome.ui
|
|
|
|
import gobject
|
|
|
|
|
2006-08-30 01:57:21 +02:00
|
|
|
class SimpleMenu(gtk.Menu):
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Menu.__init__(self)
|
|
|
|
|
|
|
|
def add_simple_item(self, title, function):
|
|
|
|
item = gtk.MenuItem(title)
|
|
|
|
item.connect('activate', function)
|
|
|
|
self.append(item)
|
|
|
|
item.show()
|
|
|
|
|
2006-08-08 10:48:55 +02:00
|
|
|
class SelectionTree(gtk.TreeView):
|
|
|
|
|
|
|
|
def __init__(self):
|
2006-08-30 01:57:21 +02:00
|
|
|
self.store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
|
2006-08-08 10:48:55 +02:00
|
|
|
gtk.TreeView.__init__(self, self.store)
|
|
|
|
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
sel_column = gtk.TreeViewColumn('Selection', renderer, text=0)
|
|
|
|
self.insert_column(sel_column, 0)
|
|
|
|
|
2006-08-30 01:57:21 +02:00
|
|
|
self.connect('row-activated', self._on_row_activated)
|
2006-08-30 13:36:30 +02:00
|
|
|
self.connect('cursor-changed', self._on_cursor_changed)
|
2006-08-08 10:48:55 +02:00
|
|
|
|
|
|
|
self._identifier_list = None
|
|
|
|
self._dim_list = {}
|
|
|
|
|
|
|
|
# A mapping of selection names to selection lines.
|
2006-08-30 01:57:21 +02:00
|
|
|
self._selections = []
|
2006-08-08 10:48:55 +02:00
|
|
|
|
|
|
|
self.set_headers_visible(True)
|
2006-08-09 16:35:42 +02:00
|
|
|
self._current_dim = None
|
2006-08-30 01:57:21 +02:00
|
|
|
self._current_selection = None
|
|
|
|
|
|
|
|
# Set up context menu
|
|
|
|
self._menu = SimpleMenu()
|
|
|
|
self._menu.add_simple_item('Select', self._on_set_selection)
|
|
|
|
|
|
|
|
self.connect('popup_menu', self._on_popup_menu)
|
|
|
|
self.connect('button_press_event', self._on_button_press_event)
|
2006-08-08 10:48:55 +02:00
|
|
|
|
|
|
|
def set_identifier_list(self, identifier_list):
|
2006-08-30 01:57:21 +02:00
|
|
|
"""Dependency injection. Sets the widget that should be used to
|
|
|
|
display the selected identifiers."""
|
2006-08-08 10:48:55 +02:00
|
|
|
self._identifier_list = identifier_list
|
|
|
|
|
|
|
|
def set_project(self, project):
|
2006-08-30 01:57:21 +02:00
|
|
|
"""Dependency injection. Set the current project."""
|
2006-08-08 10:48:55 +02:00
|
|
|
self.project = project
|
|
|
|
project.add_selection_observer(self)
|
|
|
|
project.add_dataset_observer(self)
|
|
|
|
self.update_dims(project.dim_names)
|
2006-08-30 01:57:21 +02:00
|
|
|
self.add_selection(project.get_selection())
|
2006-08-08 10:48:55 +02:00
|
|
|
|
|
|
|
def selection_changed(self, selection):
|
2006-08-30 01:57:21 +02:00
|
|
|
"""Callback on selection update"""
|
2006-08-08 10:48:55 +02:00
|
|
|
self.update_dims(selection.keys())
|
2006-08-30 01:57:21 +02:00
|
|
|
self.add_selection(selection)
|
2006-08-09 16:35:42 +02:00
|
|
|
self._update_current_dim()
|
2006-08-08 10:48:55 +02:00
|
|
|
|
2006-08-30 01:57:21 +02:00
|
|
|
def get_selection_iter(self, dimname, selection):
|
|
|
|
i = self._dim_list[dimname]
|
|
|
|
if not i:
|
|
|
|
return None
|
|
|
|
|
|
|
|
children = self.store.iter_children(i)
|
|
|
|
if not children:
|
|
|
|
return None
|
|
|
|
|
|
|
|
while children:
|
|
|
|
if self.store.get(children, 1)[0] == selection:
|
|
|
|
return self.store.get(children, 1)[0]
|
|
|
|
children = self.store.iter_next(children)
|
|
|
|
return None
|
|
|
|
|
2006-08-08 10:48:55 +02:00
|
|
|
def dataset_changed(self):
|
2006-08-30 01:57:21 +02:00
|
|
|
"""Callback when new datasets are created"""
|
|
|
|
self.selection_changed(self.project.get_selection())
|
|
|
|
for sel in self.project.selections:
|
|
|
|
if not sel in self._selections:
|
|
|
|
self._selections.append(sel)
|
|
|
|
self.add_selection(sel)
|
2006-08-08 10:48:55 +02:00
|
|
|
|
|
|
|
def update_dims(self, dim_list):
|
2006-08-30 01:57:21 +02:00
|
|
|
"""Update the list of dimensions shown"""
|
2006-08-08 10:48:55 +02:00
|
|
|
for dim in dim_list:
|
|
|
|
if not self._dim_list.has_key(dim):
|
2006-08-30 01:57:21 +02:00
|
|
|
d = self.store.insert_after(None, None, (dim, None))
|
2006-08-08 10:48:55 +02:00
|
|
|
self._dim_list[dim] = d
|
|
|
|
|
2006-08-30 01:57:21 +02:00
|
|
|
def add_selection(self, selection):
|
|
|
|
for dim in selection.dims():
|
|
|
|
if not self.get_selection_iter(dim, selection):
|
|
|
|
d = self._dim_list[dim]
|
|
|
|
i = self.store.insert_after(d, None, (selection.title, selection))
|
|
|
|
|
|
|
|
def _update_current_dim(self):
|
2006-08-30 15:56:54 +02:00
|
|
|
id_list = []
|
|
|
|
if self._current_dim and self._current_selection:
|
|
|
|
id_list = self._current_selection[self._current_dim]
|
2006-08-30 01:57:21 +02:00
|
|
|
self._identifier_list.set_identifiers(id_list)
|
|
|
|
|
|
|
|
# Callbacks
|
|
|
|
def _on_row_activated(self, treeview, path, column):
|
2006-08-30 13:36:30 +02:00
|
|
|
self.project.set_selection(self._current_dim,
|
|
|
|
self._current_selection[self._current_dim])
|
|
|
|
|
|
|
|
def _on_cursor_changed(self, treeview):
|
|
|
|
cursor = self.get_cursor()[0]
|
|
|
|
i = self.store.get_iter(cursor)
|
2006-08-08 10:48:55 +02:00
|
|
|
p = self.store.iter_parent(i)
|
2006-08-30 01:57:21 +02:00
|
|
|
if p == None:
|
2006-08-30 15:56:54 +02:00
|
|
|
self._current_dim = None
|
2006-08-30 01:57:21 +02:00
|
|
|
else:
|
|
|
|
self._current_dim = self.store.get_value(p, 0)
|
|
|
|
self._current_selection = self.store.get_value(i, 1)
|
2006-08-09 16:35:42 +02:00
|
|
|
self._update_current_dim()
|
2006-08-30 13:36:30 +02:00
|
|
|
|
2006-08-30 01:57:21 +02:00
|
|
|
def _on_set_selection(self, *rest):
|
|
|
|
if not self._current_selection:
|
2006-08-09 16:35:42 +02:00
|
|
|
return
|
2006-08-30 01:57:21 +02:00
|
|
|
self.project.set_selection(self._current_dim,
|
|
|
|
self._current_selection[self._current_dim])
|
|
|
|
|
|
|
|
def _on_button_press_event(self, widget, event):
|
|
|
|
if event.button == 3:
|
|
|
|
self._menu.popup(None, None, None, event.button, event.time)
|
|
|
|
|
|
|
|
def _on_popup_menu(self):
|
|
|
|
pass
|
2006-08-08 10:48:55 +02:00
|
|
|
|
|
|
|
class IdentifierList(gtk.TreeView):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.store = gtk.ListStore(gobject.TYPE_STRING)
|
|
|
|
gtk.TreeView.__init__(self, self.store)
|
2006-08-30 01:57:21 +02:00
|
|
|
self.set_headers_visible(True)
|
2006-08-08 10:48:55 +02:00
|
|
|
|
2006-08-30 01:57:21 +02:00
|
|
|
# Set up identifier column to show active identifiers
|
2006-08-08 10:48:55 +02:00
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
ids_column = gtk.TreeViewColumn('Identifiers', renderer, text=0)
|
|
|
|
self.insert_column(ids_column, 0)
|
|
|
|
|
|
|
|
def set_identifiers(self, identifiers):
|
2006-08-30 01:57:21 +02:00
|
|
|
"Show the list of identifier strings."
|
2006-08-08 10:48:55 +02:00
|
|
|
self.store.clear()
|
2006-08-30 15:56:54 +02:00
|
|
|
id_list = list(identifiers)
|
|
|
|
id_list.sort()
|
|
|
|
for e in id_list:
|
2006-08-08 10:48:55 +02:00
|
|
|
self.store.append((e,))
|
2006-08-30 01:57:21 +02:00
|
|
|
|