Cleanup clipboard D-Bus API

- The clipboard now determines each objects unique id and
    returns it from add_object()
- The ID is opaque to the client and should not be used/accessed
    other than with the clipboard service
- Add object type hints for dbus-python
- Sugar clipboard bindings for get_object() now return a dict rather
    than a tuple
- ClipboardIcon now retrieves the real file path and uses that
    to open the file
- Adapt sugar bits to clipboard changes
This commit is contained in:
Dan Williams
2007-03-14 00:50:06 -04:00
parent bfe04c2073
commit 8b4ccf3eb1
6 changed files with 86 additions and 74 deletions
+11 -1
View File
@@ -16,6 +16,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import logging
import os
from sugar.graphics.canvasicon import CanvasIcon
from view.clipboardmenu import ClipboardMenu
@@ -71,7 +72,16 @@ class ClipboardIcon(CanvasIcon):
logging.debug("_icon_activated_cb: " + self._object_id)
activityfactory.create_with_uri(self._activity, self._object_id)
# Get the file path
cb_service = clipboardservice.get_instance()
obj = cb_service.get_object(self._object_id)
formats = obj['FORMATS']
if len(formats) > 0:
path = cb_service.get_object_data(self._object_id, formats[0])
if os.path.exists(path):
activityfactory.create_with_uri(self._activity, path)
else:
logging.debug("Clipboard item file path %s didn't exist" % path)
def _icon_activated_cb(self, icon):
self._open_file()
+15 -15
View File
@@ -64,14 +64,16 @@ class ClipboardBox(hippo.CanvasBox):
return None
def _add_selection(self, object_id, selection):
if selection.data:
logging.debug('ClipboardBox: adding type ' + selection.type + '.')
cb_service = clipboardservice.get_instance()
cb_service.add_object_format(object_id,
selection.type,
selection.data,
on_disk = False)
if not selection.data:
return
logging.debug('ClipboardBox: adding type ' + selection.type + '.')
cb_service = clipboardservice.get_instance()
cb_service.add_object_format(object_id,
selection.type,
selection.data,
on_disk = False)
def _object_added_cb(self, cb_service, object_id, name):
icon = ClipboardIcon(self._popup_context, object_id, name)
@@ -90,7 +92,6 @@ class ClipboardBox(hippo.CanvasBox):
icon_name, preview, activity):
icon = self._icons[object_id]
icon.set_state(name, percent, icon_name, preview, activity)
logging.debug('ClipboardBox: ' + object_id + ' state was changed.')
def drag_motion_cb(self, widget, context, x, y, time):
logging.debug('ClipboardBox._drag_motion_cb')
@@ -99,12 +100,11 @@ class ClipboardBox(hippo.CanvasBox):
def drag_drop_cb(self, widget, context, x, y, time):
logging.debug('ClipboardBox._drag_drop_cb')
object_id = util.unique_id()
cb_service = clipboardservice.get_instance()
object_id = cb_service.add_object(name="")
self._context_map.add_context(context, object_id, len(context.targets))
cb_service = clipboardservice.get_instance()
cb_service.add_object(object_id, name="")
for target in context.targets:
if str(target) not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE'):
widget.drag_get_data(context, target, time)
@@ -186,8 +186,8 @@ class ClipboardBox(hippo.CanvasBox):
def _get_targets_for_dnd(self, object_id):
cb_service = clipboardservice.get_instance()
(name, percent, icon, preview, activity, format_types) = \
cb_service.get_object(object_id)
attrs = cb_service.get_object(object_id)
format_types = attrs[clipboardservice.FORMATS_KEY]
targets = []
for format_type in format_types:
+1 -3
View File
@@ -43,10 +43,8 @@ class ClipboardPanelWindow(PanelWindow):
def _owner_change_cb(self, clipboard, event):
logging.debug("owner_change_cb")
key = util.unique_id()
cb_service = clipboardservice.get_instance()
cb_service.add_object(key, name="")
key = cb_service.add_object(name="")
cb_service.set_object_percent(key, percent = 100)
targets = clipboard.wait_for_targets()