On 2/10/2007, at 1:13 PM, Richard Procter wrote:

Hi all,

I'm trying to share application-specific data between my program instances using the gtk.Clipboard and a custom target to distinguish it from normal text.

I found a workaround which appears to work: use gtk.gdk.SELECTION_TYPE_BITMAP for the target type instead of STRING.

def get_f(clipboard, selection, target_handle, userdata):
    selection.set(gtk.gdk.SELECTION_TYPE_BITMAP, 8, "Hello there")

I don't know whether this type guarantees that the data will to be copied verbatim.

regards,
Richard.

The following snippets work on linux but not on win32, where it gives the warning: copy:13: GtkWarning: gdk_property_change: assertion `type != GDK_TARGET_STRING' failed
This appears to come from gdk/win32/gdkproperty-win32.c

Has anyone used custom selection targets under win32 with more success?

regards,
Richard.

The 'copy' process
"""
import pygtk
pygtk.require('2.0')
import gtk

def get_f(clipboard, selection, target_handle, userdata):
    selection.set("STRING", 8, "Hello there")

def clear_f(clipboard, userdata):
    pass

targets = [("Foobar", 0, 0)]
gtk.clipboard_get().set_with_data(targets, get_f, clear_f)
gtk.main()
"""

The 'paste' process
"""
import pygtk
pygtk.require('2.0')
import gtk

def request_f(clipboard, selection, userdata):
    print "Target ", selection.target
    print "Type ", selection.type
    print "Format ", selection.format
    print "Data in selection is ", selection.data

gtk.clipboard_get().request_contents("Foobar", request_f)
gtk.main()
"""

Under linux, the string in the custom target is copied successfully:
"""
Target  Foobar
Type  STRING
Format  8
Data in selection is  Hello there
"""

Under win32, I get
copy:13: GtkWarning: gdk_property_change: assertion `type != GDK_TARGET_STRING' failed

win32 (Windows 2000 SP4):
gtk.pygtk_version == (2, 8, 6) or (2, 10, 6)
gtk.gtk_version == (2, 8, 10)  or (2, 10, 11)
python 2.4

linux:
gtk.pygtk_version == (2, 8, 6)
gtk.gtk_version == (2, 8, 20)
python 2.4


_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to