Drag and drop support for GtkTreeView, where the model is filtered and sorted

As the name implies, I have gtk.TreeView , whose model is sorted and filtered. According to the documentation : "Reordering row reordering only works with unsorted repositories." The only other information relates to the use of external sources, which in this case I do not need.

I tried to implement it anyway by providing handlers for the received drag and drop signals, but still get the following error:

Gtk Warning. When using models that do not support the GtkTreeDragDest interface, you can override the default "drag_data_received" handler in GtkTreeView and enable drag and drop. The easiest way to do this is to connect to drag_data_received and call g_signal_stop_emission_by_name () in the signal handler to prevent the default handler from starting. Look at the source code of the default handler in gtktreeview.c to see what your handler should do. (gtktreeview.c is in the GTK source code.) If you use GTK from a language other than C, it might be a more natural way to override the default handlers, for example. through derivation.

Despite this, although I have not yet implemented it, it looks like I could make it work, since it does not crash. However, this is a warning that I would rather not do.

So, is there a python equivalent for g_signal_stop_emission_by_name , or am I wrong about that?

+4
source share
3 answers

I was a little embarrassed as I already had a drag and drop handler, but was sorted as soon as I did the following:

 def __init__(self): self.treeview.connect("drag_data_received", self.on_drag_data_received) def on_drag_data_received(self, widget, drag_context, x, y, selection_data, info, timestamp): widget.stop_emission('drag_data_received') 

Just add, according to pygtk docs , * emit_stop_by_name * and * stop_emission * are identical.

+4
source

This is gobject.GObject.emit_stop_by_name() . I do not know if what you are doing will succeed, but there is no โ€œstandardโ€ way that I can think of.

Instead of realizing yourself, you can try using Py-gtktree : see an example called drag_between_tree_and_list.py . You can sort the tree on the right and still be able to drag it using the elements that are automatically dragged to the โ€œrightโ€ position. It does not allow dragging anywhere in the tree, but for a different reason: the example explicitly requests this.

+1
source

I got rid of the warning using treeview.stop_emission ('drag-drop-received') in my own drag and drop handler. Perhaps the doublep method will also work, although I have not tried it.

0
source

Source: https://habr.com/ru/post/1313311/


All Articles