Portál AbcLinuxu, 9. května 2025 19:45
Zdravím, nejde mi rozchodit v Python 2.7.* a GTK+ (gi.repository) DnD mezi dvěma iconview, netuší někdo, kde by mohl být problém?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gi.repository import Gtk, Gdk
from gi.repository.GdkPixbuf import Pixbuf
(TARGET_ENTRY_TEXT, TARGET_ENTRY_PIXBUF) = range(2)
(COLUMN_TEXT, COLUMN_PIXBUF) = range(2)
DRAG_ACTION = Gdk.DragAction.COPY
icons = ["gtk-cut", "gtk-paste", "gtk-copy"]
win = Gtk.Window()
content = Gtk.VBox()
#source view
liststore = Gtk.ListStore(Pixbuf, str)
sourceview = Gtk.IconView.new()
sourceview.set_model(liststore)
sourceview.set_pixbuf_column(0)
sourceview.set_text_column(1)
sourceview.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, [],
DRAG_ACTION)
def on_drag_data_get( widget, drag_context, data, info, time):
selected_path = self.get_selected_items()[0]
selected_iter = self.get_model().get_iter(selected_path)
print widget.get_model().get_iter(selected_iter, 1)
sourceview.connect("drag-data-get", on_drag_data_get)
for icon in icons:
pixbuf = Gtk.IconTheme.get_default().load_icon(icon, 64, 0)
liststore.append([pixbuf, "Label"])
content.add(sourceview)
#target view
targetstore = Gtk.ListStore(Pixbuf, str)
targetstore.append([Gtk.IconTheme.get_default().load_icon("gtk-save", 64,0), "X"])
targetview = Gtk.IconView.new()
targetview.set_model(targetstore)
targetview.set_pixbuf_column(0)
targetview.set_text_column(1)
targetview.drag_dest_set(Gtk.DestDefaults.ALL, [], DRAG_ACTION)
def on_drag_data_received(self, widget, drag_context, x,y, data,info, time):
text = data.get_text()
print("Received text: %s" % text)
targetview.connect("drag-data-received", on_drag_data_received)
content.add(targetview)
win.add(content)
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
#!/usr/bin/env python # -*- coding: utf-8 -*- from gi.repository import Gtk, Gdk from gi.repository.GdkPixbuf import Pixbuf (TARGET_ENTRY_TEXT, TARGET_ENTRY_PIXBUF) = range(2) (COLUMN_TEXT, COLUMN_PIXBUF) = range(2) DRAG_ACTION = Gdk.DragAction.COPY icons = ["gtk-cut", "gtk-paste", "gtk-copy"] win = Gtk.Window() content = Gtk.VBox() #source view liststore = Gtk.ListStore(Pixbuf, str) sourceview = Gtk.IconView.new() sourceview.set_model(liststore) sourceview.set_pixbuf_column(0) sourceview.set_text_column(1) sourceview.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, [], DRAG_ACTION) def on_drag_data_get( widget, drag_context, data, info, time): selected_path = self.get_selected_items()[0] selected_iter = self.get_model().get_iter(selected_path) print widget.get_model().get_iter(selected_iter, 1) sourceview.connect("drag-data-get", on_drag_data_get) for icon in icons: pixbuf = Gtk.IconTheme.get_default().load_icon(icon, 64, 0) liststore.append([pixbuf, "Label"]) content.add(sourceview) #target view targetstore = Gtk.ListStore(Pixbuf, str) targetstore.append([Gtk.IconTheme.get_default().load_icon("gtk-save", 64,0), "X"]) targetview = Gtk.IconView.new() targetview.set_model(targetstore) targetview.set_pixbuf_column(0) targetview.set_text_column(1) targetview.drag_dest_set(Gtk.DestDefaults.ALL, [], DRAG_ACTION) def on_drag_data_received(self, widget, drag_context, x,y, data,info, time): text = data.get_text() print("Received text: %s" % text) targetview.connect("drag-data-received", on_drag_data_received) content.add(targetview) win.add(content) win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main()
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.