2007-01-05 21:13:46 +01:00
|
|
|
import logging
|
|
|
|
|
2007-02-21 21:12:27 +01:00
|
|
|
from sugar.graphics.canvasicon import CanvasIcon
|
2006-12-13 22:36:05 +01:00
|
|
|
from view.clipboardmenu import ClipboardMenu
|
2007-02-23 13:09:33 +01:00
|
|
|
from sugar.graphics.xocolor import XoColor
|
2007-02-22 22:51:24 +01:00
|
|
|
from sugar.graphics import units
|
2007-02-24 14:35:31 +01:00
|
|
|
from sugar.graphics import color
|
2007-02-21 20:20:36 +01:00
|
|
|
from sugar.activity import activityfactory
|
2006-12-13 22:36:05 +01:00
|
|
|
from sugar.clipboard import clipboardservice
|
2007-01-06 22:29:13 +01:00
|
|
|
from sugar import util
|
2006-11-15 13:56:19 +01:00
|
|
|
|
2007-02-21 21:12:27 +01:00
|
|
|
class ClipboardIcon(CanvasIcon):
|
2006-11-15 13:56:19 +01:00
|
|
|
|
2007-02-21 21:12:27 +01:00
|
|
|
def __init__(self, popup_context, object_id, name):
|
|
|
|
CanvasIcon.__init__(self)
|
|
|
|
self._popup_context = popup_context
|
2006-12-13 22:36:05 +01:00
|
|
|
self._object_id = object_id
|
2006-12-04 20:12:24 +01:00
|
|
|
self._name = name
|
|
|
|
self._percent = 0
|
2007-01-05 21:13:46 +01:00
|
|
|
self._preview = None
|
2007-01-11 23:57:06 +01:00
|
|
|
self._activity = None
|
2007-02-22 22:51:24 +01:00
|
|
|
self.props.box_width = units.grid_to_pixels(1)
|
|
|
|
self.props.box_height = units.grid_to_pixels(1)
|
|
|
|
self.props.scale = units.STANDARD_ICON_SCALE
|
2006-12-04 20:12:24 +01:00
|
|
|
self.connect('activated', self._icon_activated_cb)
|
|
|
|
self._menu = None
|
|
|
|
|
2007-02-21 21:12:27 +01:00
|
|
|
def get_popup(self):
|
2007-01-11 23:57:06 +01:00
|
|
|
self._menu = ClipboardMenu(self._name, self._percent, self._preview,
|
|
|
|
self._activity)
|
2006-12-04 20:12:24 +01:00
|
|
|
self._menu.connect('action', self._popup_action_cb)
|
|
|
|
return self._menu
|
2006-11-15 13:56:19 +01:00
|
|
|
|
2007-02-21 21:12:27 +01:00
|
|
|
def get_popup_context(self):
|
|
|
|
return self._popup_context
|
|
|
|
|
2007-01-11 23:57:06 +01:00
|
|
|
def set_state(self, name, percent, icon_name, preview, activity):
|
2007-01-05 21:13:46 +01:00
|
|
|
self._name = name
|
2006-12-04 20:12:24 +01:00
|
|
|
self._percent = percent
|
2007-01-05 21:13:46 +01:00
|
|
|
self._preview = preview
|
2007-01-11 23:57:06 +01:00
|
|
|
self._activity = activity
|
|
|
|
self.set_property("icon_name", icon_name)
|
2006-12-04 20:12:24 +01:00
|
|
|
if self._menu:
|
2007-01-11 23:57:06 +01:00
|
|
|
self._menu.set_state(name, percent, preview, activity)
|
2007-01-05 21:13:46 +01:00
|
|
|
|
2007-01-11 23:57:06 +01:00
|
|
|
if activity and percent < 100:
|
2007-02-24 14:23:18 +01:00
|
|
|
self.props.xo_color = XoColor("#000000,#424242")
|
2007-01-05 21:13:46 +01:00
|
|
|
else:
|
2007-02-24 14:23:18 +01:00
|
|
|
self.props.xo_color = XoColor("#000000,#FFFFFF")
|
2007-01-07 06:04:30 +01:00
|
|
|
|
2007-01-11 23:57:06 +01:00
|
|
|
def _open_file(self):
|
|
|
|
if self._percent < 100 or not self._activity:
|
2007-01-07 06:04:30 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
logging.debug("_icon_activated_cb: " + self._object_id)
|
|
|
|
|
2007-02-28 16:41:50 +01:00
|
|
|
activityfactory.create_with_uri(self._activity, self._object_id)
|
2007-01-11 23:57:06 +01:00
|
|
|
|
|
|
|
def _icon_activated_cb(self, icon):
|
|
|
|
self._open_file()
|
|
|
|
|
2007-02-21 21:12:27 +01:00
|
|
|
def _popup_action_cb(self, popup, menu_item):
|
|
|
|
action = menu_item.props.action_id
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
if action == ClipboardMenu.ACTION_STOP_DOWNLOAD:
|
|
|
|
raise "Stopping downloads still not implemented."
|
|
|
|
elif action == ClipboardMenu.ACTION_DELETE:
|
2006-12-13 22:36:05 +01:00
|
|
|
cb_service = clipboardservice.get_instance()
|
|
|
|
cb_service.delete_object(self._object_id)
|
2007-01-11 23:57:06 +01:00
|
|
|
elif action == ClipboardMenu.ACTION_OPEN:
|
|
|
|
self._open_file()
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
def get_object_id(self):
|
|
|
|
return self._object_id
|
2007-02-24 14:35:31 +01:00
|
|
|
|
|
|
|
def prelight(self, enter):
|
|
|
|
if enter:
|
|
|
|
self.props.background_color = color.BLACK.get_int()
|
|
|
|
else:
|
|
|
|
self.props.background_color = color.TOOLBAR_BACKGROUND.get_int()
|