Added context menu to NavigatorView that allows reading FTSV datasets directly, i.e. without
adding a function in the workflow for this.
This commit is contained in:
parent
58886726d8
commit
ee447b688c
|
@ -3,6 +3,7 @@ import gtk
|
||||||
import gobject
|
import gobject
|
||||||
import plots
|
import plots
|
||||||
import time
|
import time
|
||||||
|
import fluents
|
||||||
import dataset, logger, plots, project, workflow
|
import dataset, logger, plots, project, workflow
|
||||||
|
|
||||||
class NavigatorView (gtk.TreeView):
|
class NavigatorView (gtk.TreeView):
|
||||||
|
@ -31,6 +32,11 @@ class NavigatorView (gtk.TreeView):
|
||||||
# self.connect('cursor_changed', self.cursor_changed_handler)
|
# self.connect('cursor_changed', self.cursor_changed_handler)
|
||||||
self.connect('row_activated', self.row_activated_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()
|
self.textrenderer = textrenderer = gtk.CellRendererText()
|
||||||
pixbufrenderer = gtk.CellRendererPixbuf()
|
pixbufrenderer = gtk.CellRendererPixbuf()
|
||||||
self.object_col = gtk.TreeViewColumn('Object')
|
self.object_col = gtk.TreeViewColumn('Object')
|
||||||
|
@ -151,3 +157,57 @@ class NavigatorView (gtk.TreeView):
|
||||||
t = type(obj)
|
t = type(obj)
|
||||||
logger.log('debug', 'Activated datatype was %s. Don\'t know what to do.' % t)
|
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
|
||||||
|
|
||||||
|
|
Reference in New Issue