1
# Copyright (C) 2007, One Laptop Per Child
3
# This library is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU Lesser General Public
5
# License as published by the Free Software Foundation; either
6
# version 2 of the License, or (at your option) any later version.
8
# This library is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# Lesser General Public License for more details.
13
# You should have received a copy of the GNU Lesser General Public
14
# License along with this library; if not, write to the
15
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16
# Boston, MA 02111-1307, USA.
21
from gettext import gettext as _
27
from sugar.graphics.palette import Palette
28
from sugar.graphics.tray import TrayButton
29
from sugar.graphics.icon import Icon
30
from sugar.graphics import style
33
class LinkButton(TrayButton, gobject.GObject):
34
__gtype_name__ = 'LinkButton'
36
'remove_link': (gobject.SIGNAL_RUN_FIRST,
37
gobject.TYPE_NONE, ([str]))
39
def __init__(self, url, buffer, color, title, owner, index, hash):
40
TrayButton.__init__(self)
41
self.set_image(buffer, color.split(',')[1], color.split(',')[0])
44
info = title +'\n'+ owner
45
self.setup_rollover_options(info)
47
def set_image(self, buffer, fill='#0000ff', stroke='#4d4c4f'):
49
loader = gtk.gdk.PixbufLoader()
52
pixbuf = loader.get_pixbuf()
55
xo_buddy = os.path.join(os.path.dirname(__file__), "icons/link.svg")
56
pixbuf_bg = self._read_link_background(xo_buddy, fill, stroke)
57
pixbuf_bg = pixbuf_bg.scale_simple(style.zoom(120),
59
gtk.gdk.INTERP_BILINEAR)
60
dest_x = style.zoom(10)
61
dest_y = style.zoom(20)
62
w = pixbuf.get_width()
63
h = pixbuf.get_height()
67
pixbuf.composite(pixbuf_bg, dest_x, dest_y, w, h, dest_x, dest_y,
68
scale_x, scale_y, gtk.gdk.INTERP_BILINEAR, 255)
69
img.set_from_pixbuf(pixbuf_bg)
70
self.set_icon_widget(img)
76
def _read_link_background(self, filename, fill_color, stroke_color):
77
icon_file = open(filename, 'r')
78
data = icon_file.read()
82
entity = '<!ENTITY fill_color "%s">' % fill_color
83
data = re.sub('<!ENTITY fill_color .*>', entity, data)
86
entity = '<!ENTITY stroke_color "%s">' % stroke_color
87
data = re.sub('<!ENTITY stroke_color .*>', entity, data)
90
return rsvg.Handle(data=data).get_pixbuf()
92
def setup_rollover_options(self, info):
93
palette = Palette(info, text_maxlen=50)
94
self.set_palette(palette)
96
menu_item = gtk.MenuItem(_('Remove'))
97
menu_item.connect('activate', self.item_remove_cb)
98
palette.menu.append(menu_item)
101
def item_remove_cb(self, widget):
102
self.emit('remove_link', self.hash)