Added icon, title and preview for clipboard objects. Also allow for opening docs and rtfs from the web.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import logging
|
||||
|
||||
from sugar.graphics.menuicon import MenuIcon
|
||||
from view.clipboardmenu import ClipboardMenu
|
||||
from sugar.activity import ActivityFactory
|
||||
@@ -6,31 +8,54 @@ from sugar.clipboard import clipboardservice
|
||||
class ClipboardIcon(MenuIcon):
|
||||
|
||||
def __init__(self, menu_shell, object_id, name):
|
||||
MenuIcon.__init__(self, menu_shell, icon_name='activity-xbook')
|
||||
MenuIcon.__init__(self, menu_shell)
|
||||
self._object_id = object_id
|
||||
self._name = name
|
||||
self._percent = 0
|
||||
self._preview = None
|
||||
self.connect('activated', self._icon_activated_cb)
|
||||
self._menu = None
|
||||
|
||||
def create_menu(self):
|
||||
self._menu = ClipboardMenu(self._name, self._percent)
|
||||
self._menu = ClipboardMenu(self._name, self._percent, self._preview)
|
||||
self._menu.connect('action', self._popup_action_cb)
|
||||
return self._menu
|
||||
|
||||
def set_percent(self, percent):
|
||||
def set_state(self, name, percent, icon_name, preview):
|
||||
self._name = name
|
||||
self._percent = percent
|
||||
self._preview = preview
|
||||
self.set_icon_name(icon_name)
|
||||
if self._menu:
|
||||
self._menu.set_percent(percent)
|
||||
self._menu.set_state(name, percent, preview)
|
||||
|
||||
def _get_activity_for_mime_type(self, mime_type):
|
||||
# FIXME: We should use some kind of registry that could be extended by
|
||||
# newly installed activities.
|
||||
if mime_type == "application/pdf":
|
||||
return "org.laptop.sugar.Xbook"
|
||||
elif mime_type in ["application/msword", "text/rtf", "application/rtf"]:
|
||||
return "org.laptop.AbiWordActivity"
|
||||
else:
|
||||
return None
|
||||
|
||||
def _icon_activated_cb(self, icon):
|
||||
if self._percent == 100:
|
||||
cb_service = clipboardservice.get_instance()
|
||||
format_types = cb_service.get_object_format_types(self._object_id)
|
||||
if len(format_types) > 0 and format_types[0] == "application/pdf":
|
||||
activity = ActivityFactory.create("org.laptop.sugar.Xbook")
|
||||
activity.execute("open_document", [self._object_id])
|
||||
|
||||
(name, percent, icon, preview, format_types) = \
|
||||
cb_service.get_object(self._object_id)
|
||||
|
||||
if format_types:
|
||||
logging.debug("_icon_activated_cb: " + self._object_id)
|
||||
|
||||
activity_id = self._get_activity_for_mime_type(format_types[0])
|
||||
|
||||
if activity_id:
|
||||
activity = ActivityFactory.create(activity_id)
|
||||
activity.start()
|
||||
activity.execute("open_document", [self._object_id])
|
||||
|
||||
def _popup_action_cb(self, popup, action):
|
||||
self.popdown()
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class ClipboardMenu(Menu):
|
||||
ACTION_SHARE = 1
|
||||
ACTION_STOP_DOWNLOAD = 2
|
||||
|
||||
def __init__(self, name, percent):
|
||||
def __init__(self, name, percent, preview):
|
||||
Menu.__init__(self, name)
|
||||
|
||||
if percent < 100:
|
||||
@@ -31,6 +31,8 @@ class ClipboardMenu(Menu):
|
||||
self._remove_icon = None
|
||||
self._stop_icon = None
|
||||
|
||||
self.add_item(preview)
|
||||
|
||||
self._update_icons(percent)
|
||||
|
||||
def _update_icons(self, percent):
|
||||
@@ -51,7 +53,8 @@ class ClipboardMenu(Menu):
|
||||
self.remove_action(self._remove_icon)
|
||||
self._remove_icon = None
|
||||
|
||||
def set_percent(self, percent):
|
||||
def set_state(self, name, percent, preview):
|
||||
self.set_title(name)
|
||||
if self._progress_bar:
|
||||
self._progress_bar.set_property('percent', percent)
|
||||
self._update_icons(percent)
|
||||
|
||||
@@ -88,9 +88,10 @@ class ClipboardBox(hippo.CanvasBox):
|
||||
del self._icons[object_id]
|
||||
logging.debug('ClipboardBox: ' + object_id + ' was deleted.')
|
||||
|
||||
def _object_state_changed_cb(self, cb_service, object_id, percent):
|
||||
def _object_state_changed_cb(self, cb_service, object_id, name, percent,
|
||||
icon_name, preview):
|
||||
icon = self._icons[object_id]
|
||||
icon.set_percent(percent)
|
||||
icon.set_state(name, percent, icon_name, preview)
|
||||
logging.debug('ClipboardBox: ' + object_id + ' state was changed.')
|
||||
|
||||
def drag_motion_cb(self, widget, context, x, y, time):
|
||||
@@ -104,13 +105,13 @@ class ClipboardBox(hippo.CanvasBox):
|
||||
self._context_map.add_context(context, object_id, len(context.targets))
|
||||
|
||||
cb_service = clipboardservice.get_instance()
|
||||
cb_service.add_object(object_id, "name")
|
||||
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)
|
||||
|
||||
cb_service.set_object_state(object_id, percent = 100)
|
||||
cb_service.set_object_percent(object_id, percent = 100)
|
||||
|
||||
return True
|
||||
|
||||
@@ -186,9 +187,11 @@ class ClipboardBox(hippo.CanvasBox):
|
||||
|
||||
def _get_targets_for_dnd(self, object_id):
|
||||
cb_service = clipboardservice.get_instance()
|
||||
format_types = cb_service.get_object_format_types(object_id)
|
||||
targets = []
|
||||
|
||||
(name, percent, icon, preview, format_types) = \
|
||||
cb_service.get_object(object_id)
|
||||
|
||||
targets = []
|
||||
for format_type in format_types:
|
||||
targets.append((format_type, 0, 0))
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class ClipboardPanelWindow(PanelWindow):
|
||||
|
||||
cb_service = clipboardservice.get_instance()
|
||||
cb_service.add_object(key, "name")
|
||||
cb_service.set_object_state(key, percent = 100)
|
||||
cb_service.set_object_percent(key, percent = 100)
|
||||
|
||||
targets = clipboard.wait_for_targets()
|
||||
for target in targets:
|
||||
|
||||
Reference in New Issue
Block a user