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
18 from gettext
import gettext
as _
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'
36 'jobject' : (object, None, None,
37 gobject
.PARAM_READWRITE
)
41 'go-back-clicked': (gobject
.SIGNAL_RUN_FIRST
, gobject
.TYPE_NONE
, ([]))
44 def __init__(self
, **kwargs
):
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
)
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
)
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')
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()
82 self
._expanded
_entry
= ExpandedEntry(self
._jobject
.object_id
)
83 self
._root
.append(self
._expanded
_entry
, hippo
.PACK_EXPAND
)
86 logging
.debug('DetailView.refresh')
88 self
._jobject
= datastore
.get(self
._jobject
.object_id
)
91 def do_set_property(self
, pspec
, value
):
92 if pspec
.name
== 'jobject':
98 def do_get_property(self
, pspec
):
99 if pspec
.name
== 'jobject':
105 class BackBar(hippo
.CanvasBox
):
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())
121 label
= hippo
.CanvasText(text
=_('Back'),
122 font_desc
=style
.FONT_NORMAL
.get_pango_desc())
125 if gtk
.widget_get_default_direction() == gtk
.TEXT_DIR_RTL
:
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()