2006-12-13 22:36:05 +01:00
|
|
|
import logging
|
|
|
|
import gtk
|
|
|
|
import hippo
|
|
|
|
|
2007-05-01 18:26:26 +02:00
|
|
|
from view.frame.framewindow import FrameWindow
|
2006-12-13 22:36:05 +01:00
|
|
|
from view.frame.clipboardbox import ClipboardBox
|
|
|
|
from sugar.clipboard import clipboardservice
|
|
|
|
from sugar import util
|
|
|
|
|
2007-05-01 18:26:26 +02:00
|
|
|
class ClipboardPanelWindow(FrameWindow):
|
2007-02-20 16:35:07 +01:00
|
|
|
def __init__(self, frame, orientation):
|
2007-05-01 18:26:26 +02:00
|
|
|
FrameWindow.__init__(self, orientation)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
2006-12-16 23:55:22 +01:00
|
|
|
self._frame = frame
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
# Listening for new clipboard objects
|
2007-03-14 13:32:05 +01:00
|
|
|
# NOTE: we need to keep a reference to gtk.Clipboard in order to keep
|
|
|
|
# listening to it.
|
|
|
|
self._clipboard = gtk.Clipboard()
|
|
|
|
self._clipboard.connect("owner-change", self._owner_change_cb)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
|
|
|
root = self.get_root()
|
|
|
|
|
2007-03-14 13:32:05 +01:00
|
|
|
self._clipboard_box = ClipboardBox(frame.get_popup_context())
|
|
|
|
root.append(self._clipboard_box)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
|
|
|
# Receiving dnd drops
|
|
|
|
self.drag_dest_set(0, [], 0)
|
2007-03-14 13:32:05 +01:00
|
|
|
self.connect("drag_motion", self._clipboard_box.drag_motion_cb)
|
|
|
|
self.connect("drag_drop", self._clipboard_box.drag_drop_cb)
|
|
|
|
self.connect("drag_data_received",
|
|
|
|
self._clipboard_box.drag_data_received_cb)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
|
|
|
# Offering dnd drags
|
|
|
|
self.drag_source_set(0, [], 0)
|
|
|
|
self.add_events(gtk.gdk.BUTTON_PRESS_MASK |
|
2006-12-14 13:50:42 +01:00
|
|
|
gtk.gdk.POINTER_MOTION_HINT_MASK)
|
2007-03-14 13:32:05 +01:00
|
|
|
self.connect("motion_notify_event",
|
|
|
|
self._clipboard_box.motion_notify_event_cb)
|
2007-02-27 13:41:51 +01:00
|
|
|
|
|
|
|
# FIXME I'm not sure we should expose the canvas in the Window API
|
2007-03-14 13:32:05 +01:00
|
|
|
self._canvas.connect("button_press_event",
|
|
|
|
self._clipboard_box.button_press_event_cb)
|
2007-02-27 13:41:51 +01:00
|
|
|
|
2007-03-14 13:32:05 +01:00
|
|
|
self.connect("drag_end", self._clipboard_box.drag_end_cb)
|
|
|
|
self.connect("drag_data_get", self._clipboard_box.drag_data_get_cb)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
|
|
|
def _owner_change_cb(self, clipboard, event):
|
2007-03-14 13:32:05 +01:00
|
|
|
if self._clipboard_box.owns_clipboard():
|
|
|
|
return
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
logging.debug("owner_change_cb")
|
2007-03-14 13:32:05 +01:00
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
cb_service = clipboardservice.get_instance()
|
2007-03-14 05:50:06 +01:00
|
|
|
key = cb_service.add_object(name="")
|
2007-01-05 21:13:46 +01:00
|
|
|
cb_service.set_object_percent(key, percent = 100)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
|
|
|
targets = clipboard.wait_for_targets()
|
|
|
|
for target in targets:
|
|
|
|
if target not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE'):
|
|
|
|
selection = clipboard.wait_for_contents(target)
|
|
|
|
if selection:
|
|
|
|
self._add_selection(key, selection)
|
2007-03-14 13:32:05 +01:00
|
|
|
|
|
|
|
cb_service.set_object_percent(key, percent=100)
|
|
|
|
|
|
|
|
# TODO: Notify somehow the object added.
|
|
|
|
#self._frame.show_and_hide(0)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
|
|
|
def _add_selection(self, key, selection):
|
|
|
|
if selection.data:
|
|
|
|
logging.debug('adding type ' + selection.type + '.')
|
|
|
|
|
|
|
|
cb_service = clipboardservice.get_instance()
|
|
|
|
cb_service.add_object_format(key,
|
|
|
|
selection.type,
|
|
|
|
selection.data,
|
|
|
|
on_disk = False)
|