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
|
# Copyright (C) 2009, Tomeu Vizoso
#
# 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
# We'd rather not depend on sugar in this class
from sugar.graphics import style
from gaphas.examples import Box, Text
class ThoughtView(Box):
_PADDING = style.zoom(15)
_LINE_WIDTH = style.zoom(2)
def __init__(self, thought_id, name, x, y, color):
Box.__init__(self)
logging.debug('ThoughtView %r %r' % (thought_id, name))
self.id = thought_id
self._name = name
self._color = color
self.set_position(x, y)
def set_name(self, name):
if self._name != name:
self._name = name
self.request_update(update=True, matrix=True)
def get_name(self):
return self._name
name = property(get_name, set_name)
def set_color(self, color):
if self._color != color:
self._color = color
self.request_update(update=True, matrix=True)
def get_color(self):
return self._color
color = property(get_color, set_color)
def set_position(self, x, y):
if (x, y) != self.get_position():
self.matrix = (1.0, 0.0, 0.0, 1, x, y)
def get_position(self):
return self.matrix[4], self.matrix[5]
position = property(get_position, set_position)
def draw(self, context):
super(ThoughtView, self).draw(context)
self._draw_label(context)
def _draw_label(self, context):
context.cairo.save()
layout = context.cairo.create_layout()
layout.set_text(self._name)
width, height = layout.get_pixel_size()
self.width = width + self._PADDING * 2
self.height = height + self._PADDING * 2
x = self._PADDING
y = self._PADDING
context.cairo.translate(x, y)
context.cairo.show_layout(layout)
context.cairo.restore()
|