1 # Copyright (C) 2008 One Laptop Per Child
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program 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
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 from gettext
import gettext
as _
25 from sugar
import profile
26 from sugar
.graphics
import style
27 from sugar
.graphics
.palette
import Palette
28 from sugar
.graphics
.menuitem
import MenuItem
29 from sugar
.graphics
.icon
import Icon
30 from sugar
.datastore
import datastore
31 from sugar
.graphics
.xocolor
import XoColor
35 class ObjectPalette(Palette
):
36 def __init__(self
, jobject
):
38 self
._jobject
= jobject
40 activity_icon
= Icon(icon_size
=gtk
.ICON_SIZE_LARGE_TOOLBAR
)
41 activity_icon
.props
.file = misc
.get_icon_name(jobject
)
42 if jobject
.metadata
.has_key('icon-color') and \
43 jobject
.metadata
['icon-color']:
44 activity_icon
.props
.xo_color
= \
45 XoColor(jobject
.metadata
['icon-color'])
47 activity_icon
.props
.xo_color
= \
48 XoColor('%s,%s' % (style
.COLOR_BUTTON_GREY
.get_svg(),
49 style
.COLOR_TRANSPARENT
.get_svg()))
51 if jobject
.metadata
.has_key('title'):
52 title
= jobject
.metadata
['title']
56 Palette
.__init
__(self
, primary_text
=title
,
59 if jobject
.metadata
.get('activity_id', ''):
60 resume_label
= _('Resume')
62 resume_label
= _('Start')
63 menu_item
= MenuItem(resume_label
, 'activity-start')
64 menu_item
.connect('activate', self
.__start
_activate
_cb
)
65 self
.menu
.append(menu_item
)
68 # TODO: Add "Start with" menu item
70 menu_item
= MenuItem(_('Copy'))
71 icon
= Icon(icon_name
='edit-copy', xo_color
=profile
.get_color(),
72 icon_size
=gtk
.ICON_SIZE_MENU
)
73 menu_item
.set_image(icon
)
74 menu_item
.connect('activate', self
.__copy
_activate
_cb
)
75 self
.menu
.append(menu_item
)
78 menu_item
= MenuItem(_('Erase'), 'list-remove')
79 menu_item
.connect('activate', self
.__erase
_activate
_cb
)
80 self
.menu
.append(menu_item
)
83 def __start_activate_cb(self
, menu_item
):
84 self
._jobject
.resume()
86 def __copy_activate_cb(self
, menu_item
):
87 clipboard
= gtk
.Clipboard()
88 clipboard
.set_with_data([('text/uri-list', 0, 0)],
89 self
.__clipboard
_get
_func
_cb
,
90 self
.__clipboard
_clear
_func
_cb
)
92 def __clipboard_get_func_cb(self
, clipboard
, selection_data
, info
, data
):
93 selection_data
.set('text/uri-list', 8, self
._jobject
.file_path
)
95 def __clipboard_clear_func_cb(self
, clipboard
, data
):
98 def __erase_activate_cb(self
, menu_item
):
99 bundle
= misc
.get_bundle(self
._jobject
)
100 if bundle
is not None and bundle
.is_installed():
102 datastore
.delete(self
._jobject
.object_id
)
105 class BuddyPalette(Palette
):
106 def __init__(self
, buddy
):
110 buddy_icon
= Icon(icon_name
='computer-xo',
111 icon_size
=style
.STANDARD_ICON_SIZE
,
112 xo_color
=XoColor(colors
))
114 Palette
.__init
__(self
, primary_text
=nick
,
117 # TODO: Support actions on buddies, like make friend, invite, etc.