2
# Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
4
# Jockey is free software; you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License as published by the
6
# Free Software Foundation; either version 2, or (at your option) any
9
# Jockey is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23
from pychart_types import *
26
class T(chart_object.T):
27
__doc__ = text_box_doc.doc
28
keys = {"text": (StringType, "???", "Text body. <<font>>"),
29
"loc": (TupleType, (0,0),
30
"The location of the text box."),
31
"line_style": (line_style.T, line_style.default,
32
"""The line style of the surrounding frame."""),
33
"fill_style": (fill_style.T, fill_style.white,
34
"Specifies the fill style of the text box."),
35
"top_fudge": (UnitType, 0,
36
"The amount of space (in points) above the first line"),
37
"bottom_fudge": (UnitType, 5,
38
"The amount of space below the last line"),
39
"left_fudge": (UnitType, 5,
40
"The amount of space left of the box"),
41
"right_fudge": (UnitType, 5,
42
"The amount of space right of the box"),
43
"_arrows": (ListType, pychart_util.new_list, "The list of arrows. Not to be touched by the user directly"),
44
"radius": (UnitType, 0,
45
"""Radius of the four corners of the rectangle.
46
If the value is zero, a sharp-cornered
47
rectangle is drawn."""),
48
"shadow": (ShadowType, None,
49
pychart_util.shadow_desc)
51
##AUTOMATICALLY GENERATED
53
##END AUTOMATICALLY GENERATED
54
def get_dimension(self):
55
x = self.loc[0] - self.left_fudge
56
y = self.loc[1] - self.bottom_fudge
57
width = font.text_width(self.text) + self.right_fudge + self.left_fudge
58
height = (font.text_height(self.text))[0] + self.top_fudge + self.bottom_fudge
59
return (x, y, width, height)
61
def choose_end_point(self, tipx, tipy):
62
(x, y, width, height) = self.get_dimension()
71
if tipx >= x and tipx < x+width:
72
vertices.append((tipx, y))
73
vertices.append((tipx, y+height))
74
if tipy >= y and tipy < y+height:
75
vertices.append((x, tipy))
76
vertices.append((x+width, tipy))
78
for startPoint in vertices:
79
dist = ((startPoint[0] - tipx) **2 + (startPoint[1] - tipy) **2)
80
if not minPoint or dist < minDist:
86
def add_arrow(self, tipLoc, tail=None, arrow = arrow.default):
87
"""This method adds a straight arrow that points to
88
@var{TIPLOC}, which is a tuple of integers. @var{TAIL}
89
specifies the starting point of the arrow. It is either None
90
or a string consisting of the following letters: 'l', 'c',
91
'r', 't', 'm,', and 'b'. Letters 'l', 'c', or 'r' means to
92
start the arrow from the left, center, or right of the text
93
box, respectively. Letters 't', 'm', or 'b' means to start the
94
arrow from the top, middle or bottom of the text box. For
95
example, when @samp{tail = 'tc'} then arrow is drawn from
96
top-center point of the text box. ARROW specifies the style of
99
self._arrows.append((tipLoc, tail, arrow))
101
def draw(self, can = None):
103
can = canvas.default_canvas()
106
text_width = font.text_width(self.text)
107
text_height = font.text_height(self.text)[0]
108
(halign, valign, angle) = font.get_align(self.text)
110
if self.line_style or self.fill_style:
111
width = text_width+self.left_fudge+self.right_fudge
112
height = text_height+self.bottom_fudge+self.top_fudge
113
can.round_rectangle(self.line_style, self.fill_style,
114
x-self.left_fudge, y-self.bottom_fudge,
115
x-self.left_fudge+width, y-self.bottom_fudge+height,
116
self.radius, self.shadow)
119
can.show(x, y, self.text)
121
can.show(x+text_width/2.0, y, self.text)
123
can.show(x+text_width, y, self.text)
125
raise Exception, "Unsupported alignment (" + halign + ")"
128
for t in self._arrows:
129
(tipLoc, tail, arrow) = t
131
(x, y, width, height) = self.get_dimension()
137
origin[0] = x+width/2.0
143
origin[1] = y+height/2.0
147
raise ValueError, tail + ": unknown tail location spec."
149
origin = self.choose_end_point(tipLoc[0], tipLoc[1])
150
arrow.draw((origin, tipLoc), can)