From 27d935319c613077b973e35a3b34888084a880b8 Mon Sep 17 00:00:00 2001 From: einarr Date: Fri, 9 Nov 2007 15:02:32 +0000 Subject: [PATCH] Added a delete function to the context menu on navigator elements. --- fluents/navigator.py | 24 ++++++++++++++---------- fluents/project.py | 11 ++++++++++- fluents/view.py | 10 +++++++++- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/fluents/navigator.py b/fluents/navigator.py index 9c980a4..4e44951 100644 --- a/fluents/navigator.py +++ b/fluents/navigator.py @@ -26,7 +26,7 @@ class NavigatorView (gtk.TreeView): # Selection Mode self.get_selection().set_mode(gtk.SELECTION_MULTIPLE) - self.get_selection().set_select_function(self.is_selectable) +# self.get_selection().set_select_function(self.is_selectable) self.get_selection().connect('changed',self.selection_changed_handler) self._previous_selection = [] @@ -71,15 +71,6 @@ class NavigatorView (gtk.TreeView): self.set_model(project.data_tree) self.data_tree.connect('row-changed',self.row_changed_handler) - def is_selectable(self,path): - if self.data_tree: - obj = self.data_tree.get_value(self.data_tree.get_iter(path),2) - if not obj: - return False - if not isinstance(obj, dataset.Dataset): - return False - return True - # selection changed, setting current_data ojbects def selection_changed_handler(self, selection): # update prev selection right away in case of multiple events @@ -199,6 +190,11 @@ class NavigatorMenu(gtk.Menu): self.append(self.save_item) self.save_item.show() + self.delete_item = gtk.MenuItem('Delete') + self.delete_item.connect('activate', self.on_delete, navigator) + self.append(self.delete_item) + self.delete_item.show() + # Build transform sub menu self.trans_menu = gtk.Menu() @@ -308,6 +304,14 @@ class NavigatorMenu(gtk.Menu): print "unknown; ", retval dialog.destroy() + def on_delete(self, item, navigator): + tm, rows = navigator.get_selection().get_selected_rows() + iters = [tm.get_iter(r) for r in rows] + iters.reverse() + for i in iters: + main.project.delete_data(i) + # tm.remove(i) + def on_plot_image(self, item, navigator): plot = plots.ImagePlot(self.dataset, name='Image Plot') icon = fluents.icon_factory.get("line_plot") diff --git a/fluents/project.py b/fluents/project.py index efd4e26..6e2e71a 100644 --- a/fluents/project.py +++ b/fluents/project.py @@ -4,7 +4,7 @@ import gobject import gtk import fluents import logger -import dataset, plots +import dataset, plots, main class Project: def __init__(self,name="Testing"): @@ -55,6 +55,15 @@ class Project: """Returns the current selection object""" return self.sel_obj + def delete_data(self, it): + child = self.data_tree.iter_children(it) + while child != None: + c = self.data_tree.iter_next(child) + self.delete_data(child) + child = c + main.application.main_view.remove_view(self.data_tree.get(it, 2)[0]) + self.data_tree.remove(it) + def add_data(self, parents, data, fun='Function'): """Adds a set of data and plots to the navigator. diff --git a/fluents/view.py b/fluents/view.py index e0cc06d..2b83062 100644 --- a/fluents/view.py +++ b/fluents/view.py @@ -241,7 +241,6 @@ class MainView (gtk.Notebook): self._views = ObjectTable(2, 2, lambda : ViewFrame(self._view_frames)) self._large_view = ViewFrame(list()) self.update_small_views() - self.append_page(self._small_views) self.append_page(self._large_view) @@ -332,6 +331,15 @@ class MainView (gtk.Notebook): vf = self._large_view vf.set_view(view) + def remove_view(self, view): + """Removes the given view if displayed.""" + if view == None: + return + + for vf in self._view_frames: + if vf.get_view() == view: + vf.set_view(None) + def set_all_plots(self, views): """Displays all the views in the list, and hides all other views.