[sugar] clipboard questions

Tomeu Vizoso tomeu
Sun Jul 22 12:51:15 EDT 2007

On Sat, 2007-07-21 at 18:00 -0400, Erik Blankinship wrote:
> I would like to put images taken with the camera onto the clipboard.
> I am able to put images taken with the camera onto the clipboard this
> way:
> self.clipBoard = gtk.Clipboard(display=gtk.gdk.display_get_default(),
> selection="CLIPBOARD")
> ...
> #todo: should probably listen for a CTRL+C callback, but how?
> self.clipBoard.set_image ( pixbuf )
> My questions are:
>      1. How do I listen for Control+C events to call
>         self.clipBoard.set_image( pixbuf )?

Don't know if it's the best way, but you can just connect to you
window's key-press-event signal:

    self.connect('key-press-event', self._key_press_event_cb)


def _key_press_event_cb(self, widget, event):
    keyname = gtk.gdk.keyval_name(event.keyval)
    if keyname == 'c' and event.state == gtk.gdk.CONTROL_MASK:
        self.clipboard = gtk.Clipboard()
        pixbuf = self._get_selected_pixbuf()

>      1. Is there anything else to it?  Images I put on the clipboard
>         now do not have either a name or an "Open" menuitem.  Is there
>         a spec somewhere for what metadata we should associate with
>         clipboard data?

Sugar now recognizes 'image/png', 'image/gif' and 'image/jpeg' as
images. You can check in the shell's log which targets is receiving the

>      1. Is there an example of using drag and drop in sugar to the
>         clipboard?

The sugar frame where you can drop objects behaves exactly the same as
any other X app that receives drops.

As you are using pygtk, just follow the instructions in the drag and
drop section in the pygtk tutorial:


As for examples in sugar, you can read what the journal is doing for
offering drags of entries, but this example is more complicated that
what you want as we are dragging from a hippo canvas (instead of
dragging a widget, that already has builtin support for it):


Please consider setting the dragged pixbuf as the pointer during
dragging, as in your case will be quite easy and will improve
considerably the user experience:


Hope this helps,


More information about the Sugar-devel mailing list