From ee447b688c98b4bd7ed53c2594e5a5aee7d3dbb8 Mon Sep 17 00:00:00 2001 From: einarr Date: Fri, 12 Jan 2007 14:37:44 +0000 Subject: [PATCH] Added context menu to NavigatorView that allows reading FTSV datasets directly, i.e. without adding a function in the workflow for this. --- fluents/navigator.py | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/fluents/navigator.py b/fluents/navigator.py index 4f61835..697d53a 100644 --- a/fluents/navigator.py +++ b/fluents/navigator.py @@ -3,6 +3,7 @@ import gtk import gobject import plots import time +import fluents import dataset, logger, plots, project, workflow class NavigatorView (gtk.TreeView): @@ -31,6 +32,11 @@ class NavigatorView (gtk.TreeView): # self.connect('cursor_changed', self.cursor_changed_handler) self.connect('row_activated', self.row_activated_handler) + # Activate context menu + self.menu = NavigatorMenu(self) + self.connect('popup_menu', self.popup_menu) + self.connect('button_press_event', self.mouse_popup_menu) + self.textrenderer = textrenderer = gtk.CellRendererText() pixbufrenderer = gtk.CellRendererPixbuf() self.object_col = gtk.TreeViewColumn('Object') @@ -151,3 +157,57 @@ class NavigatorView (gtk.TreeView): t = type(obj) logger.log('debug', 'Activated datatype was %s. Don\'t know what to do.' % t) + def popup_menu(self, *rest): + self.menu.popup(None, None, None, 0, 0) + + def mouse_popup_menu(self, widget, event): + if event.button == 3: + self.menu.popup(None, None, None, event.button, event.time) + + +class NavigatorMenu(gtk.Menu): + def __init__(self, navigator): + gtk.Menu.__init__(self) + self.navigaotor = navigator + + # Populate menu + self.load_item = gtk.MenuItem('Load dataset') + self.load_item.connect('activate', on_load_dataset, navigator) + self.append(self.load_item) + self.load_item.show() + + self.save_item = gtk.MenuItem('Save dataset') + self.save_item.connect('activate', on_save_dataset, navigator) + self.append(self.save_item) + + +def on_load_dataset(item, navigator): + dialog = gtk.FileChooserDialog('Load dataset') + dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK) + retval = dialog.run() + if retval in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]: + print "Cancelled" + elif retval == gtk.RESPONSE_OK: + print "OK" + print dialog.get_filename() + fd = open(dialog.get_filename()) + ds = dataset.read_ftsv(fd) + fd.close() + + if isinstance(ds, dataset.GraphDataset): + icon = fluents.icon_factory.get("graph_dataset") + elif isinstance(ds, dataset.CategoryDataset): + icon = fluents.icon_factory.get("category_dataset") + else: + icon = fluents.icon_factory.get("dataset") + + project = navigator.project + project.add_dataset(ds) + project.data_tree_insert(None, ds.get_name(), ds, None, "black", icon) + else: + print "unknown; ", retval + dialog.destroy() + +def on_save_dataset(item): + pass +