1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# Copyright (C) 2007, One Laptop Per Child
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import logging
from gettext import gettext as _
import gobject
import gtk
from sugar.graphics import style
from sugar.graphics.icon import CanvasIcon
from jarabe.journal.expandedentry import ExpandedEntry
from jarabe.journal import model
class DetailView(gtk.VBox):
__gtype_name__ = 'DetailView'
__gsignals__ = {
'go-back-clicked': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
}
def __init__(self, **kwargs):
self._metadata = None
self._expanded_entry = None
root_box = gtk.EventBox()
root_box.modify_bg(gtk.STATE_NORMAL,
style.COLOR_WHITE.get_gdk_color())
self._root = gtk.VBox()
root_box.add(self._root)
back_bar = BackBar()
back_bar.connect('button-release-event',
self.__back_bar_release_event_cb)
self._root.pack_start(back_bar, False, False, style.DEFAULT_SPACING)
gobject.GObject.__init__(self, **kwargs)
gtk.VBox.__init__(self)
self.pack_start(root_box, True, True, 0)
self._root.show()
self.show_all()
def _fav_icon_activated_cb(self, fav_icon):
keep = not self._expanded_entry.get_keep()
self._expanded_entry.set_keep(keep)
fav_icon.props.keep = keep
def __back_bar_release_event_cb(self, back_bar, event):
self.emit('go-back-clicked')
return False
def _update_view(self):
if self._expanded_entry is None:
self._expanded_entry = ExpandedEntry()
self._root.pack_start(self._expanded_entry)
self._expanded_entry.set_metadata(self._metadata)
self._root.show_all()
def refresh(self):
logging.debug('DetailView.refresh')
self._metadata = model.get(self._metadata['uid'])
self._update_view()
def get_metadata(self):
return self._metadata
def set_metadata(self, metadata):
self._metadata = metadata
self._update_view()
metadata = gobject.property(
type=object, getter=get_metadata, setter=set_metadata)
class BackBar(gtk.EventBox):
def __init__(self):
gtk.EventBox.__init__(self)
self.set_border_width(style.DEFAULT_SPACING)
self.modify_bg(gtk.STATE_NORMAL,
style.COLOR_PANEL_GREY.get_gdk_color())
hbox = gtk.HBox()
icon = CanvasIcon(icon_name='go-previous',
size=style.SMALL_ICON_SIZE,
fill_color=style.COLOR_TOOLBAR_GREY.get_svg())
hbox.pack_start(icon, False, False, style.DEFAULT_SPACING)
label = gtk.Label()
label.set_text(_('Back'))
halign = gtk.Alignment(0, 0, 0, 0)
halign.add(label)
hbox.pack_start(halign, True, True, style.DEFAULT_SPACING)
hbox.show()
self.add(hbox)
if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL:
hbox.reverse()
self.connect('motion-notify-event', self.__motion_notify_event_cb)
def __motion_notify_event_cb(self, box, event):
if event.detail == 1: # TODO: enter
box.props.background_color = style.COLOR_SELECTION_GREY.get_gdk_color()
elif event.detail == 0: # TODO: leave
box.props.background_color = style.COLOR_PANEL_GREY.get_gdk_color()
return False
|