Commit from One Laptop Per Child: Translation System by user HoboPrimate. 31 of 31...
[journal-activity.git] / palettes.py
blobec3de0b5902e069073fde44a966c5cee3f809051
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
17 import os
18 import statvfs
19 import logging
20 from gettext import gettext as _
22 import gtk
24 from sugar import env
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
33 import misc
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'])
46 else:
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']
53 else:
54 title = _('Untitled')
56 Palette.__init__(self, primary_text=title,
57 icon=activity_icon)
59 if jobject.metadata.get('activity_id', ''):
60 resume_label = _('Resume')
61 else:
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)
66 menu_item.show()
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)
76 menu_item.show()
78 menu_item = MenuItem(_('Erase'), 'list-remove')
79 menu_item.connect('activate', self.__erase_activate_cb)
80 self.menu.append(menu_item)
81 menu_item.show()
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):
96 pass
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():
101 bundle.uninstall()
102 datastore.delete(self._jobject.object_id)
105 class BuddyPalette(Palette):
106 def __init__(self, buddy):
107 self._buddy = buddy
109 nick, colors = 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,
115 icon=buddy_icon)
117 # TODO: Support actions on buddies, like make friend, invite, etc.