Commit from One Laptop Per Child: Translation System by user HoboPrimate. 31 of 31...
[journal-activity.git] / detailview.py
blob2939548616dbb565e4276dd5654ed3690ffecaf8
1 # Copyright (C) 2007, 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 logging
18 from gettext import gettext as _
20 import gobject
21 import gtk
22 import hippo
24 from sugar.graphics import style
25 from sugar.graphics.icon import CanvasIcon
26 from sugar.graphics.toolbutton import ToolButton
27 from sugar.datastore import datastore
29 from expandedentry import ExpandedEntry
30 from keepicon import KeepIcon
32 class DetailView(gtk.VBox):
33 __gtype_name__ = 'DetailView'
35 __gproperties__ = {
36 'jobject' : (object, None, None,
37 gobject.PARAM_READWRITE)
40 __gsignals__ = {
41 'go-back-clicked': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
44 def __init__(self, **kwargs):
45 self._jobject = None
46 self._expanded_entry = None
48 canvas = hippo.Canvas()
50 self._root = hippo.CanvasBox()
51 self._root.props.background_color = style.COLOR_PANEL_GREY.get_int()
52 canvas.set_root(self._root)
54 back_bar = BackBar()
55 back_bar.connect('button-release-event',
56 self.__back_bar_release_event_cb)
57 self._root.append(back_bar)
59 gobject.GObject.__init__(self, **kwargs)
61 self.pack_start(canvas)
62 canvas.show()
64 def _fav_icon_activated_cb(self, fav_icon):
65 keep = not self._expanded_entry.get_keep()
66 self._expanded_entry.set_keep(keep)
67 fav_icon.props.keep = keep
69 def __back_bar_release_event_cb(self, back_bar, event):
70 self.emit('go-back-clicked')
71 return False
73 def _update_view(self):
74 if self._expanded_entry:
75 self._root.remove(self._expanded_entry)
77 # Work around pygobject bug #479227
78 self._expanded_entry.remove_all()
79 import gc
80 gc.collect()
81 if self._jobject:
82 self._expanded_entry = ExpandedEntry(self._jobject.object_id)
83 self._root.append(self._expanded_entry, hippo.PACK_EXPAND)
85 def refresh(self):
86 logging.debug('DetailView.refresh')
87 if self._jobject:
88 self._jobject = datastore.get(self._jobject.object_id)
89 self._update_view()
91 def do_set_property(self, pspec, value):
92 if pspec.name == 'jobject':
93 self._jobject = value
94 self._update_view()
95 else:
96 raise AssertionError
98 def do_get_property(self, pspec):
99 if pspec.name == 'jobject':
100 return self._jobject
101 else:
102 raise AssertionError
105 class BackBar(hippo.CanvasBox):
106 def __init__(self):
107 hippo.CanvasBox.__init__(self,
108 orientation=hippo.ORIENTATION_HORIZONTAL,
109 border=style.LINE_WIDTH,
110 background_color=style.COLOR_PANEL_GREY.get_int(),
111 border_color=style.COLOR_SELECTION_GREY.get_int(),
112 padding=style.DEFAULT_PADDING,
113 padding_left=style.DEFAULT_SPACING,
114 spacing=style.DEFAULT_SPACING)
116 icon = CanvasIcon(icon_name='go-previous',
117 size=style.SMALL_ICON_SIZE,
118 fill_color=style.COLOR_TOOLBAR_GREY.get_svg())
119 self.append(icon)
121 label = hippo.CanvasText(text=_('Back'),
122 font_desc=style.FONT_NORMAL.get_pango_desc())
123 self.append(label)
125 if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL:
126 self.reverse()
128 self.connect('motion-notify-event', self.__motion_notify_event_cb)
130 def __motion_notify_event_cb(self, box, event):
131 if event.detail == hippo.MOTION_DETAIL_ENTER:
132 box.props.background_color = style.COLOR_SELECTION_GREY.get_int()
133 elif event.detail == hippo.MOTION_DETAIL_LEAVE:
134 box.props.background_color = style.COLOR_PANEL_GREY.get_int()
135 return False