At 17:20 on Sun 12/01/03, [EMAIL PROTECTED] masquerading as 'Pedro Rodriguez' wrote: > Jonathan, > > Finally got it working, I was messing widgets, so you'll find the fixed > script hereafter (it seems also that everything works only with the > window widget). > > While your question was about clipboard, I was sticking to selections, > because there were the sole one for which I could find examples in gtk > distribution and in the tutorial : > http://www.gtk.org/tutorial/ch-managingselections.html > >http://cvs.gnome.org/bonsai/cvsblame.cgi?file=gtk%2B%2Fexamples%2Fselection/setselection.c&rev=&root=/cvs/gnome > > (notice that there seems to be problem when using Invisible widget in > pygtk). > > There is a new way to access clipboard that goes through Clipboard > objects, but I don't know much about them : > - http://developer.gnome.org/doc/API/2.0/gtk/gtk-Clipboards.html
Yes. As is the way of things almost immediately after posting I found:
http://www.moeraki.com/pygtktutorial/pygtk2tutorial/sec-supplyingtheselection.html
I'd been confused that GTK2 supplies the clipboard functionality but
PyGTK doesn't. And that clipboard ~= selection.
Thanks for your help - I'm now up and running :)
Regards,
Jonathan
--
Jonathan Sambrook
Software Developer
Designer Servers
# ----------------------------------------------------------------------
import gtk
# ----------------------------------------------------------------------
# XXX
CURRENT_TIME = 0L
# /XXX
# ----------------------------------------------------------------------
def quit(*args):
gtk.mainquit()
# ----------------------------------------------------------------------
def paste_clicked(*args):
# Asynchonous query
w.selection_convert("PRIMARY", "STRING", CURRENT_TIME)
def clipboard_data_received(wdgt, data, time, *args):
global clip_data
if data is not None:
clip_data = data.data
# print dir(data)
print "clipboard contains '%s'" % clip_data
# ----------------------------------------------------------------------
def copy_clicked(wdgt, *args):
if w.selection_owner_set("PRIMARY", CURRENT_TIME):
print "got the selection ownership"
else:
print "ownership failed"
def get_selection(wdgt, data, *args):
global clip_data
data.set("STRING"
, 8
, "[me %s]" % clip_data
)
print "somebody queried me"
def lost_selection(wdgt, *args):
print "lost the selection"
# ----------------------------------------------------------------------
clip_data = ""
w = gtk.Window()
v = gtk.VBox()
bp = gtk.Button(label="Paste")
bc = gtk.Button(label="Copy")
w.add(v)
v.add(bp)
v.add(bc)
w.connect("delete_event", quit)
w.connect("destroy_event", quit)
w.connect("selection_received", clipboard_data_received)
bp.connect("clicked", paste_clicked)
bc.connect("clicked", copy_clicked)
# ----------------------------------------------------------------------
w.selection_add_target("PRIMARY", "STRING", 1)
w.connect("selection_get", get_selection)
w.connect("selection_clear_event", lost_selection)
# ----------------------------------------------------------------------
w.show_all()
gtk.mainloop()
msg05198/pgp00000.pgp
Description: PGP signature
