Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Added a delete function to the context menu on navigator elements.

This commit is contained in:
Einar Ryeng 2007-11-09 15:02:32 +00:00
parent c26999e688
commit 27d935319c
3 changed files with 33 additions and 12 deletions

View File

@ -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")

View File

@ -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.

View File

@ -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.