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
123
124
125
126
127
128
|
# Copyright (C) 2010, Aleksey Lim
#
# 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 gtk
import gobject
import logging
from jarabe.journal.homogeneview import HomogeneView
from jarabe.journal.homogeneview import Cell
from jarabe.journal.widgets import *
from jarabe.journal import preview
from jarabe.journal import entry
class _Cell(Cell):
def __init__(self):
Cell.__init__(self)
self._last_thumb_offset = None
self._last_thumb_mtime = None
cell = gtk.HBox()
self.add(cell)
# toolbar
toolbar = gtk.VBox()
cell.pack_start(toolbar, expand=False)
self._keep = KeepIcon()
toolbar.pack_start(self._keep, expand=False)
self._details = DetailsIcon()
toolbar.pack_start(self._details, expand=False)
# main
main = gtk.VBox()
main.props.spacing = style.DEFAULT_PADDING
cell.pack_end(main)
self._icon = ObjectIcon(
border=style.LINE_WIDTH,
border_color=style.COLOR_PANEL_GREY.get_int(),
box_width=preview.THUMB_WIDTH,
box_height=preview.THUMB_HEIGHT)
self._icon.show()
self._thumb = Thumb()
self._thumb.show()
self._thumb_box = gtk.HBox()
main.pack_start(self._thumb_box, expand=False)
self._title = Title(max_line_count=2)
main.pack_start(self._title, expand=False)
self._date = Timestamp(wrap=True, xalign=0.0)
self._date.set_size_request(preview.THUMB_WIDTH, -1)
main.pack_start(self._date, expand=False)
self.show_all()
def do_fill_in_cell_content(self, table, offset, metadata):
self._keep.fill_in(metadata)
self._details.fill_in(metadata)
self._title.fill_in(metadata)
self._date.fill_in(metadata)
self._icon.fill_in(metadata)
self._thumb.fill_in(metadata)
if self._last_thumb_offset != offset or \
self._last_thumb_mtime != metadata.get('timestamp'):
self._set_thumb_widget(self._icon)
self._last_thumb_offset = None
self._last_thumb_mtime = metadata.get('timestamp')
preview.fetch(offset, metadata)
else:
self._set_thumb_widget(self._thumb)
def fill_pixbuf_in(self, offset, pixbuf):
self._last_thumb_offset = offset
self._thumb.image.set_from_pixbuf(pixbuf)
self._set_thumb_widget(self._thumb)
def _set_thumb_widget(self, widget):
if widget not in self._thumb_box.get_children():
for child in self._thumb_box.get_children():
self._thumb_box.remove(child)
self._thumb_box.pack_start(widget, expand=False)
class ThumbsView(HomogeneView):
def __init__(self):
HomogeneView.__init__(self, _Cell)
cell_width = preview.THUMB_WIDTH + style.SMALL_ICON_SIZE + \
style.DEFAULT_PADDING + style.DEFAULT_SPACING * 2
cell_height = preview.THUMB_HEIGHT + entry.TEXT_HEIGHT * 4 + \
style.DEFAULT_PADDING * 3 + style.DEFAULT_SPACING
self.cell_size = (cell_width, cell_height)
self.connect('frame-scrolled', self.__frame_scrolled_cb)
preview.fetched.connect(self.__preview_fetched_cb)
def __frame_scrolled_cb(self, table):
preview.discard_queue(table.frame_range)
def __preview_fetched_cb(self, sender, signal, offset, pixbuf):
cell = self.get_cell(offset)
if cell is not None:
cell.fill_pixbuf_in(offset, pixbuf)
self.refill([offset])
|