diff --git a/system/navigator.py b/system/navigator.py index 60f4e3b..9d241ce 100644 --- a/system/navigator.py +++ b/system/navigator.py @@ -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) diff --git a/system/plots.py b/system/plots.py index 31f42c2..30eb489 100644 --- a/system/plots.py +++ b/system/plots.py @@ -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