How to set gtk.Clipboard data right?



Hello,

My application wants to provide 2 types of clipboard data;
* Filename uri list,
* Filename list as text.

The clipboard targets are:

clipboard_targets = [
  ('x-special/gnome-copied-files',0,0),
  ("text/uri-list",0,0),
  ("UTF8_STRING",0,0)]

I use the clipboard.set_with_data(..) function to set the targets and a
callback function that hands over the data.

clipboard.set_with_data(clipboard_targets, clipboard_get_data_cb,
clipboard_clear_data_cb, lst)

The problem is in the clipboard_get_data_cb(...) function. the TARGET
list is always null/none. So it does not know what type of data the
receiver can handle.

selectiondata.targets_include_uri() --> Always none
selectiondata.targets_include_image(True) --> Always none
selectiondata.targets_include_text() --> Always none

Why these are None? I just set the clipboard_targets in the above call.

I have tested this by running the enclosed test.py and doing "Paste"
from Gedit, Nautilus, CLI command and The Gimp. These should handle all
the aforementioned target types.

Here is a complete test code:
http://www.futuredesktop.com/tmp/clipboard-test.zip

Some beginning lines of the code:
def clipboard_copy_data(file_lst):
    clipboard = gtk.clipboard_get()

    clipboard_targets = [('x-special/gnome-copied-files',0,0),
               ("text/uri-list",0,0),
               ("UTF8_STRING",0,0)]

    # Probably not necessary, but
    import copy
    lst = copy.deepcopy(file_lst)

    clipboard.set_can_store(clipboard_targets)
    ret = clipboard.set_with_data(clipboard_targets,
clipboard_get_data_cb, clipboard_clear_data_cb, lst)
    return ret

def clipboard_get_data_cb(clipboard, selectiondata, info, userdata):
    print "info=", info

    file_lst = userdata
    print "clipboard_get_data_cb, file_lst=", file_lst

    # Why are these targets always null?
    print "targets=", selectiondata.get_targets()
    print "targets_include_uri=", selectiondata.targets_include_uri()
    print "targets_include_image=",
selectiondata.targets_include_image(True)
    print " targets_include_text=",  selectiondata.targets_include_text()
...
...

It will also provide Pixbuf as clipboard data, but I can use these calls
directly:
 clipboard=gtk.clipboard_get()
 pb = gtk.gdk.pixbuf_new_from_file(filename)
 clipboard.set_image(pb)
---

My development environ is Ubuntu 10.04 and GNOME-desktop.

PS. the final application will be this
http://www.futuredesktop.com/clipart-applet/clipart-applet.ogv ;-)

Kindly
 Osmo Antero (Moma)
 Oslo, Grønland








[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]