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
|
# 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 sugar.graphics import style
from sugar.graphics.roundbox import CanvasRoundBox
from jarabe.journal.homogenetable import VHomogeneTable
class Cell(gtk.EventBox):
def __init__(self):
gtk.EventBox.__init__(self)
self.select(False)
def do_fill_in_cell_content(self, table, offset, metadata):
# needs to be overriden
pass
def do_fill_in(self, table, cell_index):
result_set = table.get_result_set()
result_set.seek(cell_index)
self.do_fill_in_cell_content(table, cell_index, result_set.read())
if table.hover_selection:
self.select(table.cursor == cell_index)
def select(self, selected):
if selected:
self.modify_bg(gtk.STATE_NORMAL,
style.COLOR_SELECTION_GREY.get_gdk_color())
else:
self.modify_bg(gtk.STATE_NORMAL,
style.COLOR_WHITE.get_gdk_color())
class HomogeneView(VHomogeneTable):
__gsignals__ = {
'entry-activated': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([str])),
}
def __init__(self, cell_class, **kwargs):
assert(issubclass(cell_class, Cell))
VHomogeneTable.__init__(self, cell_class, **kwargs)
self._result_set = None
self.hover_selection = False
self.connect('cursor-changed', self.__cursor_changed_cb)
def get_result_set(self):
return self._result_set
def set_result_set(self, result_set):
if self._result_set is result_set:
return
self._result_set = result_set
result_set_length = result_set.get_length()
if self.cell_count == result_set_length:
self.refill()
else:
self.cell_count = result_set_length
def __cursor_changed_cb(self, table, old_cursor):
if not self.hover_selection:
return
old_cell = table[old_cursor]
if old_cell is not None:
old_cell.select(False)
new_cell = table[table.cursor]
if new_cell is not None:
new_cell.select(True)
|