Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar
This commit is contained in:
+22
-27
@@ -2,6 +2,7 @@ import logging
|
||||
|
||||
from sugar.graphics.menuicon import MenuIcon
|
||||
from view.clipboardmenu import ClipboardMenu
|
||||
from sugar.graphics.iconcolor import IconColor
|
||||
from sugar.activity import ActivityFactory
|
||||
from sugar.clipboard import clipboardservice
|
||||
from sugar import util
|
||||
@@ -14,32 +15,30 @@ class ClipboardIcon(MenuIcon):
|
||||
self._name = name
|
||||
self._percent = 0
|
||||
self._preview = None
|
||||
self._activity = None
|
||||
self.connect('activated', self._icon_activated_cb)
|
||||
self._menu = None
|
||||
|
||||
def create_menu(self):
|
||||
self._menu = ClipboardMenu(self._name, self._percent, self._preview)
|
||||
self._menu = ClipboardMenu(self._name, self._percent, self._preview,
|
||||
self._activity)
|
||||
self._menu.connect('action', self._popup_action_cb)
|
||||
return self._menu
|
||||
|
||||
def set_state(self, name, percent, icon_name, preview):
|
||||
def set_state(self, name, percent, icon_name, preview, activity):
|
||||
self._name = name
|
||||
self._percent = percent
|
||||
self._preview = preview
|
||||
self.set_icon_name(icon_name)
|
||||
self._activity = activity
|
||||
self.set_property("icon_name", icon_name)
|
||||
if self._menu:
|
||||
self._menu.set_state(name, percent, preview)
|
||||
self._menu.set_state(name, percent, preview, activity)
|
||||
|
||||
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"
|
||||
if activity and percent < 100:
|
||||
self.set_property('color', IconColor("#000000,#424242"))
|
||||
else:
|
||||
return None
|
||||
|
||||
self.set_property('color', IconColor("#000000,#FFFFFF"))
|
||||
|
||||
def _activity_create_success_cb(self, handler, activity):
|
||||
activity.start(util.unique_id())
|
||||
activity.execute("open_document", [self._object_id])
|
||||
@@ -47,26 +46,20 @@ class ClipboardIcon(MenuIcon):
|
||||
def _activity_create_error_cb(self, handler, err):
|
||||
pass
|
||||
|
||||
def _icon_activated_cb(self, icon):
|
||||
if self._percent < 100:
|
||||
return
|
||||
|
||||
cb_service = clipboardservice.get_instance()
|
||||
(name, percent, icon, preview, format_types) = \
|
||||
cb_service.get_object(self._object_id)
|
||||
if not format_types:
|
||||
def _open_file(self):
|
||||
if self._percent < 100 or not self._activity:
|
||||
return
|
||||
|
||||
logging.debug("_icon_activated_cb: " + self._object_id)
|
||||
activity_type = self._get_activity_for_mime_type(format_types[0])
|
||||
if not activity_type:
|
||||
return
|
||||
|
||||
# Launch the activity to handle this item
|
||||
handler = ActivityFactory.create(activity_type)
|
||||
handler = ActivityFactory.create(self._activity)
|
||||
handler.connect('success', self._activity_create_success_cb)
|
||||
handler.connect('error', self._activity_create_error_cb)
|
||||
|
||||
|
||||
def _icon_activated_cb(self, icon):
|
||||
self._open_file()
|
||||
|
||||
def _popup_action_cb(self, popup, action):
|
||||
self.popdown()
|
||||
|
||||
@@ -75,6 +68,8 @@ class ClipboardIcon(MenuIcon):
|
||||
elif action == ClipboardMenu.ACTION_DELETE:
|
||||
cb_service = clipboardservice.get_instance()
|
||||
cb_service.delete_object(self._object_id)
|
||||
|
||||
elif action == ClipboardMenu.ACTION_OPEN:
|
||||
self._open_file()
|
||||
|
||||
def get_object_id(self):
|
||||
return self._object_id
|
||||
|
||||
+45
-10
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import gtk
|
||||
import gobject
|
||||
import hippo
|
||||
@@ -10,16 +11,28 @@ from sugar.graphics import style
|
||||
class ClipboardMenuItem(ClipboardBubble):
|
||||
|
||||
def __init__(self, percent = 0, stylesheet="clipboard.Bubble"):
|
||||
ClipboardBubble.__init__(self, percent = percent)
|
||||
self._text_item = None
|
||||
ClipboardBubble.__init__(self, percent=percent)
|
||||
style.apply_stylesheet(self, stylesheet)
|
||||
|
||||
self._text_item = hippo.CanvasText(text=str(percent) + ' %')
|
||||
style.apply_stylesheet(self._text_item, 'clipboard.MenuItem.Title')
|
||||
self.append(self._text_item)
|
||||
|
||||
def do_set_property(self, pspec, value):
|
||||
if pspec.name == 'percent':
|
||||
if self._text_item:
|
||||
self._text_item.set_property('text', str(value) + ' %')
|
||||
|
||||
ClipboardBubble.do_set_property(self, pspec, value)
|
||||
|
||||
class ClipboardMenu(Menu):
|
||||
|
||||
ACTION_DELETE = 0
|
||||
ACTION_SHARE = 1
|
||||
ACTION_OPEN = 1
|
||||
ACTION_STOP_DOWNLOAD = 2
|
||||
|
||||
def __init__(self, name, percent, preview):
|
||||
def __init__(self, name, percent, preview, activity):
|
||||
Menu.__init__(self, name)
|
||||
|
||||
if percent < 100:
|
||||
@@ -29,21 +42,39 @@ class ClipboardMenu(Menu):
|
||||
self._progress_bar = None
|
||||
|
||||
self._remove_icon = None
|
||||
self._open_icon = None
|
||||
self._stop_icon = None
|
||||
|
||||
self.add_item(preview, wrap=True)
|
||||
|
||||
self._update_icons(percent)
|
||||
self._update_icons(percent, activity)
|
||||
|
||||
def _update_icons(self, percent):
|
||||
if percent == 100:
|
||||
def _update_icons(self, percent, activity):
|
||||
|
||||
if percent == 100 and activity:
|
||||
if not self._remove_icon:
|
||||
self._remove_icon = CanvasIcon(icon_name='stock-remove')
|
||||
self.add_action(self._remove_icon, ClipboardMenu.ACTION_DELETE)
|
||||
|
||||
|
||||
if not self._open_icon:
|
||||
self._open_icon = CanvasIcon(icon_name='stock-keep')
|
||||
self.add_action(self._open_icon, ClipboardMenu.ACTION_OPEN)
|
||||
|
||||
if self._stop_icon:
|
||||
self.remove_action(self._stop_icon)
|
||||
self._stop_icon = None
|
||||
elif percent == 100 and not activity:
|
||||
if not self._remove_icon:
|
||||
self._remove_icon = CanvasIcon(icon_name='stock-remove')
|
||||
self.add_action(self._remove_icon, ClipboardMenu.ACTION_DELETE)
|
||||
|
||||
if self._open_icon:
|
||||
self.remove_action(self._open_icon)
|
||||
self._open_icon = None
|
||||
|
||||
if self._stop_icon:
|
||||
self.remove_action(self._stop_icon)
|
||||
self._stop_icon = None
|
||||
else:
|
||||
if not self._stop_icon:
|
||||
self._stop_icon = CanvasIcon(icon_name='stock-close')
|
||||
@@ -52,9 +83,13 @@ class ClipboardMenu(Menu):
|
||||
if self._remove_icon:
|
||||
self.remove_action(self._remove_icon)
|
||||
self._remove_icon = None
|
||||
|
||||
def set_state(self, name, percent, preview):
|
||||
|
||||
if self._open_icon:
|
||||
self.remove_action(self._open_icon)
|
||||
self._open_icon = None
|
||||
|
||||
def set_state(self, name, percent, preview, activity):
|
||||
self.set_title(name)
|
||||
if self._progress_bar:
|
||||
self._progress_bar.set_property('percent', percent)
|
||||
self._update_icons(percent)
|
||||
self._update_icons(percent, activity)
|
||||
|
||||
@@ -53,18 +53,18 @@ class EventFrame(gobject.GObject):
|
||||
self._hover = EventFrame.HOVER_NONE
|
||||
self._active = False
|
||||
|
||||
invisible = self._create_invisible(0, 0, gtk.gdk.screen_width(), 1)
|
||||
invisible = self._create_invisible(0, 0, gtk.gdk.screen_width(), 6)
|
||||
self._windows.append(invisible)
|
||||
|
||||
invisible = self._create_invisible(0, 0, 1, gtk.gdk.screen_height())
|
||||
invisible = self._create_invisible(0, 0, 6, gtk.gdk.screen_height())
|
||||
self._windows.append(invisible)
|
||||
|
||||
invisible = self._create_invisible(gtk.gdk.screen_width() - 1, 0,
|
||||
invisible = self._create_invisible(gtk.gdk.screen_width() - 6, 0,
|
||||
gtk.gdk.screen_width(),
|
||||
gtk.gdk.screen_height())
|
||||
self._windows.append(invisible)
|
||||
|
||||
invisible = self._create_invisible(0, gtk.gdk.screen_height() - 1,
|
||||
invisible = self._create_invisible(0, gtk.gdk.screen_height() - 6,
|
||||
gtk.gdk.screen_width(),
|
||||
gtk.gdk.screen_height())
|
||||
self._windows.append(invisible)
|
||||
|
||||
@@ -89,9 +89,9 @@ class ClipboardBox(hippo.CanvasBox):
|
||||
logging.debug('ClipboardBox: ' + object_id + ' was deleted.')
|
||||
|
||||
def _object_state_changed_cb(self, cb_service, object_id, name, percent,
|
||||
icon_name, preview):
|
||||
icon_name, preview, activity):
|
||||
icon = self._icons[object_id]
|
||||
icon.set_state(name, percent, icon_name, preview)
|
||||
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):
|
||||
@@ -188,7 +188,7 @@ class ClipboardBox(hippo.CanvasBox):
|
||||
def _get_targets_for_dnd(self, object_id):
|
||||
cb_service = clipboardservice.get_instance()
|
||||
|
||||
(name, percent, icon, preview, format_types) = \
|
||||
(name, percent, icon, preview, activity, format_types) = \
|
||||
cb_service.get_object(object_id)
|
||||
|
||||
targets = []
|
||||
|
||||
@@ -70,7 +70,7 @@ clipboard_bubble = {
|
||||
}
|
||||
|
||||
clipboard_menu_item_title = {
|
||||
'xalign': hippo.ALIGNMENT_START,
|
||||
'xalign': hippo.ALIGNMENT_CENTER,
|
||||
'padding-left': 5,
|
||||
'color' : 0xFFFFFFFF,
|
||||
'font' : style.get_font_description('Bold', 1.2)
|
||||
|
||||
Reference in New Issue
Block a user