From 06591e301e8a4b46ca950e8cb3fbfce1e2b44371 Mon Sep 17 00:00:00 2001 From: einarr Date: Wed, 17 Jan 2007 14:06:07 +0000 Subject: [PATCH] Added "Plot" submenu in navigator context menu. Can create an ImagePlot of a dataset. --- fluents/navigator.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/fluents/navigator.py b/fluents/navigator.py index a3e092e..98d54c6 100644 --- a/fluents/navigator.py +++ b/fluents/navigator.py @@ -162,6 +162,7 @@ class NavigatorView (gtk.TreeView): def on_mouse_event(self, widget, event): path = widget.get_path_at_pos(int(event.x), int(event.y)) + iter = None if path: iter = self.data_tree.get_iter(path[0]) @@ -170,9 +171,9 @@ class NavigatorView (gtk.TreeView): obj = None if isinstance(obj, dataset.Dataset): - self.menu.set_dataset(obj) + self.menu.set_dataset(obj, iter) else: - self.menu.set_dataset(None) + self.menu.set_dataset(None, iter) if event.button == 3: self.menu.popup(None, None, None, event.button, event.time) @@ -183,7 +184,8 @@ class NavigatorMenu(gtk.Menu): gtk.Menu.__init__(self) self.navigaotor = navigator self.dataset = None - + self.tree_iter = None + # Populate menu self.load_item = gtk.MenuItem('Load dataset') self.load_item.connect('activate', self.on_load_dataset, navigator) @@ -195,13 +197,29 @@ class NavigatorMenu(gtk.Menu): self.append(self.save_item) self.save_item.show() - def set_dataset(self, ds): + # Build plot menu + self.plot_menu = gtk.Menu() + + self.plot_image_item = gtk.MenuItem('Image Plot') + self.plot_image_item.connect('activate', self.on_plot_image, navigator) + self.plot_menu.append(self.plot_image_item) + self.plot_image_item.show() + + self.plot_item = gtk.MenuItem('Plot') + self.append(self.plot_item) + self.plot_item.set_submenu(self.plot_menu) + self.plot_item.show() + + def set_dataset(self, ds, it): self.dataset = ds + self.tree_iter = it + if ds == None: self.save_item.set_property('sensitive', False) + self.plot_item.set_property('sensitive', False) else: self.save_item.set_property('sensitive', True) - + self.plot_item.set_property('sensitive', True) def on_load_dataset(self, item, navigator): dialog = gtk.FileChooserDialog('Load dataset') @@ -248,3 +266,10 @@ class NavigatorMenu(gtk.Menu): print "unknown; ", retval dialog.destroy() + def on_plot_image(self, item, navigator): + project = navigator.project + plot = plots.ImagePlot(self.dataset, name='Image Plot') + icon = fluents.icon_factory.get("line_plot") + project.data_tree_insert(self.tree_iter, 'Image Plot', plot, None, "black", icon) + +