Drag'n'drop for plots

This commit is contained in:
Reidar Strand Hagen 2006-05-02 11:09:55 +00:00
parent a2d3a9d5cc
commit 4e4150236f
2 changed files with 40 additions and 3 deletions

View File

@ -19,7 +19,6 @@ class NavigatorView (gtk.TreeView):
self.connect('cursor_changed', self.cursor_changed_handler)
self.connect('row_activated', self.row_activated_handler)
#pixrenderer = gtk.CellRendererPixbuf()
textrenderer = gtk.CellRendererText()
@ -28,11 +27,24 @@ class NavigatorView (gtk.TreeView):
self.object_col.pack_start(textrenderer)
self.object_col.set_attributes(textrenderer, cell_background=3, foreground = 4, text=0)
self.append_column(self.object_col)
# drag'n'drop
self.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,[("GTK_TREE_MODEL_ROW",gtk.TARGET_SAME_APP,7)], gtk.gdk.ACTION_LINK)
self.connect("drag-data-get",self.slot_drag_data)
logger.log('debug', 'Initializing navigator window.')
# sets data for drag event.
def slot_drag_data(self,treeview,context,selection,target_id,etime):
treeselection = treeview.get_selection()
model, iter = treeselection.get_selected()
path = model.get_path(iter)
self.data_tree.drag_data_get(path, selection)
def add_project(self, project):
self.project = project
self.data_tree = project.data_tree
@ -47,7 +59,7 @@ class NavigatorView (gtk.TreeView):
if isinstance(obj, dataset.Dataset):
logger.log('debug', 'Selecting dataset')
self.project.set_current_data(obj)
elif not isinstance(obj, plots.Plot):
else:
t = type(obj)
logger.log('debug', 'Selected datatype was %s. Don\'t know what to do.' % t)

View File

@ -62,6 +62,11 @@ class Plot (gtk.Frame):
self.title = title
self.selection_listener = None
def get_title(self):
return self.title
@ -115,6 +120,26 @@ class SmallView (gtk.Table):
child.parent_signalling = child.connect('button_press_event', self.__view_button_event__)
self.attach(child, x, x+1, y, y+1)
# drag'n'drop
for views in self.child_views:
for view in views:
view.drag_dest_set(gtk.DEST_DEFAULT_ALL, [("GTK_TREE_MODEL_ROW",gtk.TARGET_SAME_APP,7)],gtk.gdk.ACTION_LINK)
view.connect("drag-data-received",self.drag_received_by_view,view)
def drag_received_by_view(self, widget, drag_context, x, y, selection, info, timestamp, view):
treestore, path = selection.tree_get_row_drag_data()
iter = treestore.get_iter(path)
obj = treestore.get_value(iter,2)
loc = self.find_child(view)
if loc and isinstance(obj, Plot) and (not self.find_child(obj)):
self.set_child(obj,loc[0],loc[1])
def set_view_listener(self, listener):
self._listener = listener