[pygtk] empty Treeview drag & drop warning

philopensource at hotmail.com philopensource at hotmail.com
Tue Sep 6 23:46:21 WST 2005


Hi list,

I'm using drag & drop on an empty treeview.
When the data are drop i get this warning and nothing happen in the 
treeview:
GtkWarning: gtk_tree_view_scroll_to_cell: assertion 
`tree_view->priv->tree != NULL' failed


Now when i append an empty row: self.model.append(None, ["","",'','',''])
It works but this empty row is annoying me after.

How can i use DnD on an empty treeview?

Thanks for the answer.
regards,
Philippe Collet

Here is the code i use:

        TARGETS = [
            ('text/plain', 0, 0),
            ('TEXT', 0, 1),
            ('STRING', 0, 2),
            ]

        self.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
                  [('text/plain', 0, 0)],
                  gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_COPY)
        self.connect("drag-data-get", self.drag_data_get_data)
       
        self.enable_model_drag_dest(TARGETS,gtk.gdk.ACTION_DEFAULT)
        self.connect("drag_data_received", self.drag_data_received_cb)

    def drag_data_received_cb(self, treeview, context, x, y, selection,
                                info, etime):
        path = None
        position = None
        iter = None
        model = treeview.get_model()
        name = selection.data
        print name
        drop_info = treeview.get_dest_row_at_pos(x, y)
        if drop_info:
            path, position = drop_info
            iter = model.get_iter(path)
            list= 
self.kernelM.guiM.window.visuPanel.fTreeview.get_data_list_from_name(name)
            if (position == gtk.TREE_VIEW_DROP_BEFORE
                or position == gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                
model.insert_before(None,iter,[name,list[0],list[1],list[2],list[3]])
            elif position == gtk.TREE_VIEW_DROP_AFTER:
                new_iter = model.insert_after(parent=None, sibling=iter, 
row=[name,list[1],list[2],list[3],list[4]])

            if model.iter_next(iter) != None:
                if context.action == gtk.gdk.ACTION_MOVE:
                    context.finish(True, True, etime)
        self.move_to_end()
        return True

    def drag_data_get_data(self, treeview, context, selection, 
target_id,etime):
        #if (GTK_WIDGET_REALIZED(treeview)):
            #treeselection = treeview.get_selection()
            #model, iter = treeselection.get_selected()
        data = self.selItems_list[0].name
        selection.set(selection.target, 8, data)



More information about the pygtk mailing list