Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Added a singleton project in the project module, so that the current project is

easily accessible from anywhere in the code. As there is only one project at
any given time this should not be a problem.

The Gene Ontology browser needed this to be able to set the selection without
passing the current project through several constructors. 

Added a context menu in the GO browser that allows the user to select all GO
terms in the subgraph that starts on the current node.
This commit is contained in:
Einar Ryeng 2007-01-18 15:45:48 +00:00
parent f533344242
commit 7693f336ba
3 changed files with 65 additions and 6 deletions

View File

@ -197,12 +197,13 @@ class FluentApp:
tb = ViewFrameToolButton() tb = ViewFrameToolButton()
self['toolbar'].add(tb) self['toolbar'].add(tb)
def set_project(self, project): def set_project(self, proj):
logger.log('notice', 'Creating a new project') logger.log('notice', 'Creating a new project')
self.project = project self.project = proj
self.workflow.add_project(self.project) project.project = proj
self.navigator_view.add_project(self.project) self.workflow.add_project(proj)
self.dimlistcontroller.set_project(project) self.navigator_view.add_project(proj)
self.dimlistcontroller.set_project(proj)
def set_workflow(self, workflow): def set_workflow(self, workflow):
self.workflow = workflow self.workflow = workflow

View File

@ -135,3 +135,8 @@ class Project:
def set_current_data(self, obj): def set_current_data(self, obj):
self.current_data = obj self.current_data = obj
## Singleton project.
## This is the current and only project in the application.
project = None

View File

@ -1,5 +1,5 @@
import gtk import gtk
from fluents import dataset, logger, plots, workflow, fluents from fluents import dataset, logger, plots, workflow, fluents, project
from fluents.lib import blmfuncs from fluents.lib import blmfuncs
import geneontology import geneontology
#import gostat #import gostat
@ -77,6 +77,11 @@ class GeneOntologyTree (gtk.HPaned):
self._treemodel = treemodel self._treemodel = treemodel
self._tree_view = gtk.TreeView(treemodel) self._tree_view = gtk.TreeView(treemodel)
# Set up context menu
self._context_menu = GoTermContextMenu(treemodel, self._tree_view)
self._tree_view.connect('popup_menu', self._popup_menu)
self._tree_view.connect('button_press_event', self._on_button_press)
renderer = gtk.CellRendererText() renderer = gtk.CellRendererText()
go_column = gtk.TreeViewColumn('GO ID', renderer, text=0) go_column = gtk.TreeViewColumn('GO ID', renderer, text=0)
self._tree_view.insert_column(go_column, 0) self._tree_view.insert_column(go_column, 0)
@ -102,6 +107,54 @@ class GeneOntologyTree (gtk.HPaned):
self._desc_view.set_go_term(term) self._desc_view.set_go_term(term)
##
## GTK Callback functions
##
def _popup_menu(self, *rest):
self.menu.popup(None, None, None, 0, 0)
def _on_button_press(self, widget, event):
path = widget.get_path_at_pos(int(event.x), int(event.y))
iter = None
if path:
iter = self._treemodel.get_iter(path[0])
obj = self._treemodel.get_value(iter, 2)
else:
obj = None
self._context_menu.set_current_term(obj)
if event.button == 3:
self._context_menu.popup(None, None, None, event.button, event.time)
class GoTermContextMenu (gtk.Menu):
"""Context menu for GO terms in the gene ontology browser"""
def __init__(self, treemodel, treeview):
self._treemodel = treemodel
self._treeview = treeview
self._current_term = None
gtk.Menu.__init__(self)
# Popuplate tree
self._select_subtree_item = i = gtk.MenuItem('Select subtree')
i.connect('activate', self._on_select_subtree, treemodel, treeview)
self.append(i)
i.show()
def set_current_term(self, term):
self._current_term = term
def _on_select_subtree(self, item, treemodel, treeview):
logger.log('notice', 'Selecting subtree from GO id: %s (%s)' %
(self._current_term['id'], self._current_term['name']))
ids = [x['id'] for x in networkx.bfs(go, self._current_term)]
project.project.set_selection('go-terms', set(ids))
class GoWorkflow (workflow.Workflow): class GoWorkflow (workflow.Workflow):
name = 'Gene Ontology' name = 'Gene Ontology'