sugar-toolkit-gtk3/shell/view/clipboardicon.py

118 lines
4.1 KiB
Python
Raw Normal View History

2007-03-14 04:57:29 +01:00
# Copyright (C) 2007, Red Hat, Inc.
# Copyright (C) 2007, One Laptop Per Child
2007-03-14 04:57:29 +01:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import logging
from gettext import gettext as _
import gobject
2007-02-21 21:12:27 +01:00
from sugar.graphics.canvasicon import CanvasIcon
from view.clipboardmenu import ClipboardMenu
2007-02-23 13:09:33 +01:00
from sugar.graphics.xocolor import XoColor
from sugar.graphics import style
from sugar.clipboard import clipboardservice
from sugar import util
from sugar import profile
2007-02-21 21:12:27 +01:00
class ClipboardIcon(CanvasIcon):
__gtype_name__ = 'SugarClipboardIcon'
__gproperties__ = {
'selected' : (bool, None, None, False,
gobject.PARAM_READWRITE)
}
2007-07-01 12:55:10 +02:00
def __init__(self, object_id, name):
2007-02-21 21:12:27 +01:00
CanvasIcon.__init__(self)
self._object_id = object_id
self._name = name
self._percent = 0
self._preview = None
self._activity = None
self._selected = False
self._hover = False
self.props.size = style.STANDARD_ICON_SIZE
2007-06-23 20:07:25 +02:00
self.props.xo_color = XoColor(profile.get_color().to_string())
2007-07-01 12:55:10 +02:00
cb_service = clipboardservice.get_instance()
obj = cb_service.get_object(self._object_id)
formats = obj['FORMATS']
self.palette = ClipboardMenu(self._object_id, self._name, self._percent,
self._preview, self._activity,
formats and formats[0] == 'application/vnd.olpc-x-sugar')
def do_set_property(self, pspec, value):
if pspec.name == 'selected':
self._set_selected(value)
self.emit_paint_needed(0, 0, -1, -1)
else:
CanvasIcon.do_set_property(self, pspec, value)
def do_get_property(self, pspec):
if pspec.name == 'selected':
return self._selected
else:
return CanvasIcon.do_get_property(self, pspec)
def _set_selected(self, selected):
self._selected = selected
if selected:
if not self._hover:
2007-08-08 10:56:12 +02:00
self.props.background_color = style.COLOR_SELECTION_GREY.get_int()
else:
2007-08-08 10:56:12 +02:00
self.props.background_color = style.COLOR_PANEL_GREY.get_int()
def set_state(self, name, percent, icon_name, preview, activity):
cb_service = clipboardservice.get_instance()
obj = cb_service.get_object(self._object_id)
if obj['FORMATS'] and obj['FORMATS'][0] == 'application/vnd.olpc-x-sugar':
installable = True
else:
installable = False
if icon_name:
self.props.icon_name = icon_name
else:
2007-08-16 13:06:39 +02:00
self.props.icon_name = 'theme:unknown-object'
self._name = name
self._percent = percent
self._preview = preview
self._activity = activity
2007-07-01 12:55:10 +02:00
self.palette.set_state(name, percent, preview, activity, installable)
if (activity or installable) and percent < 100:
self.props.xo_color = XoColor("#000000,#424242")
else:
2007-06-23 20:07:25 +02:00
self.props.xo_color = XoColor(profile.get_color().to_string())
def get_object_id(self):
return self._object_id
2007-02-24 14:35:31 +01:00
def prelight(self, enter):
if enter:
self._hover = True
2007-08-08 10:56:12 +02:00
self.props.background_color = style.COLOR_BLACK.get_int()
2007-02-24 14:35:31 +01:00
else:
self._hover = False
if self._selected:
2007-08-08 10:56:12 +02:00
self.props.background_color = style.COLOR_SELECTION_GREY.get_int()
else:
2007-08-08 10:56:12 +02:00
self.props.background_color = style.COLOR_PANEL_GREY.get_int()