Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Added "Save dataset" option to navigator context menu.

This commit is contained in:
Einar Ryeng 2007-01-15 13:58:56 +00:00
parent 476c830a5e
commit cacb0a27b7
1 changed files with 64 additions and 31 deletions

View File

@ -35,7 +35,7 @@ class NavigatorView (gtk.TreeView):
# Activate context menu # Activate context menu
self.menu = NavigatorMenu(self) self.menu = NavigatorMenu(self)
self.connect('popup_menu', self.popup_menu) self.connect('popup_menu', self.popup_menu)
self.connect('button_press_event', self.mouse_popup_menu) self.connect('button_press_event', self.on_mouse_event)
self.textrenderer = textrenderer = gtk.CellRendererText() self.textrenderer = textrenderer = gtk.CellRendererText()
pixbufrenderer = gtk.CellRendererPixbuf() pixbufrenderer = gtk.CellRendererPixbuf()
@ -160,7 +160,20 @@ class NavigatorView (gtk.TreeView):
def popup_menu(self, *rest): def popup_menu(self, *rest):
self.menu.popup(None, None, None, 0, 0) self.menu.popup(None, None, None, 0, 0)
def mouse_popup_menu(self, widget, event): def on_mouse_event(self, widget, event):
path = widget.get_path_at_pos(int(event.x), int(event.y))
if path:
iter = self.data_tree.get_iter(path[0])
obj = self.data_tree.get_value(iter, 2)
else:
obj = None
if isinstance(obj, dataset.Dataset):
self.menu.set_dataset(obj)
else:
self.menu.set_dataset(None)
if event.button == 3: if event.button == 3:
self.menu.popup(None, None, None, event.button, event.time) self.menu.popup(None, None, None, event.button, event.time)
@ -169,27 +182,34 @@ class NavigatorMenu(gtk.Menu):
def __init__(self, navigator): def __init__(self, navigator):
gtk.Menu.__init__(self) gtk.Menu.__init__(self)
self.navigaotor = navigator self.navigaotor = navigator
self.dataset = None
# Populate menu # Populate menu
self.load_item = gtk.MenuItem('Load dataset') self.load_item = gtk.MenuItem('Load dataset')
self.load_item.connect('activate', on_load_dataset, navigator) self.load_item.connect('activate', self.on_load_dataset, navigator)
self.append(self.load_item) self.append(self.load_item)
self.load_item.show() self.load_item.show()
self.save_item = gtk.MenuItem('Save dataset') self.save_item = gtk.MenuItem('Save dataset')
self.save_item.connect('activate', on_save_dataset, navigator) self.save_item.connect('activate', self.on_save_dataset, navigator)
self.append(self.save_item) self.append(self.save_item)
self.save_item.show()
def set_dataset(self, ds):
self.dataset = ds
if ds == None:
self.save_item.set_property('sensitive', False)
else:
self.save_item.set_property('sensitive', True)
def on_load_dataset(item, navigator): def on_load_dataset(self, item, navigator):
dialog = gtk.FileChooserDialog('Load dataset') dialog = gtk.FileChooserDialog('Load dataset')
dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK) dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)
retval = dialog.run() retval = dialog.run()
if retval in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]: if retval in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]:
print "Cancelled" pass
elif retval == gtk.RESPONSE_OK: elif retval == gtk.RESPONSE_OK:
print "OK"
print dialog.get_filename()
fd = open(dialog.get_filename()) fd = open(dialog.get_filename())
ds = dataset.read_ftsv(fd) ds = dataset.read_ftsv(fd)
fd.close() fd.close()
@ -208,6 +228,19 @@ def on_load_dataset(item, navigator):
print "unknown; ", retval print "unknown; ", retval
dialog.destroy() dialog.destroy()
def on_save_dataset(item): def on_save_dataset(self, item, navigator):
pass dialog = gtk.FileChooserDialog('Save dataset')
dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, 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(), 'w')
dataset.write_ftsv(fd, self.dataset)
fd.close()
else:
print "unknown; ", retval
dialog.destroy()