Re: [PyGObject] Drag & Drop in a TreeView
- From: <c buhtz posteo jp>
- To: gtk-app-devel-list gnome org
- Subject: Re: [PyGObject] Drag & Drop in a TreeView
- Date: Sun, 22 Jul 2018 22:39:44 +0200
I see attachments are removed
This is the code
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="TreeView Drag and Drop")
self.connect("delete-event", Gtk.main_quit)
self.set_default_size(400, 300)
# "model" with dummy data
self.store = Gtk.TreeStore(str, str)
for i in range(5):
self.store.append(None, ['Item {}'.format(i),
'{}'.format(i*100)]) # treeview
self.view = Gtk.TreeView(model=self.store)
self.add(self.view)
# build columsn
colA = Gtk.TreeViewColumn('Col A', Gtk.CellRendererText(),
text=0) self.view.append_column(colA)
colB = Gtk.TreeViewColumn('Col B', Gtk.CellRendererText(),
text=1) self.view.append_column(colB)
# DnD events
self.view.connect("drag-begin", self.drag_begin)
self.view.connect("drag-data-get", self.drag_data_get)
self.view.connect("drag-drop", self.drag_drop)
self.view.connect("drag-data-delete", self.drag_data_delete)
self.view.connect("drag-data-received", self.drag_data_received)
self.view.connect("drag-end", self.drag_end)
target_entry = Gtk.TargetEntry.new('text/uri-list', 2, 0)
self.view.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK,
[target_entry], Gdk.DragAction.DEFAULT|Gdk.DragAction.MOVE)
self.view.enable_model_drag_dest([target_entry],
Gdk.DragAction.DEFAULT|Gdk.DragAction.MOVE)
def drag_begin(self, treeview, context):
print('== Drag started')
def drag_data_get(self, treeview, context, data, info, time):
print('== Drag data requested by destination')
def drag_drop(self, treeview, context, selection, info, time):
print('== Drag data droped')
def drag_data_received(self, treeview, context, x, y, selection,
info, time): print('== Drag data received')
def drag_end(self, treeview, context):
print('== Drag data end')
def drag_data_delete(self, treeview, context):
print('== Drag data delete')
win = MainWindow()
win.show_all()
Gtk.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]