-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathline.py
128 lines (96 loc) · 3.45 KB
/
line.py
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
from artist import Artist
class Line(Artist):
"""
Represent a line to draw on the canvas.
The line has start and end points, and properties defining
how the line will appear.
====================== ================= =======
Property Possible Values Description
====================== ================= =======
width int (1) The width of the line.
style | 'solid' The line style.
| 'dash'
| 'dot'
| 'dashdot'
| 'dashdotdot'
cap | 'square' How the end of the line should be drawn.
| 'flat'
| 'round'
join | 'bevel' How two lines should be joined. NOT SUPPORTED.
| 'miter'
| 'round'
====================== ================= =======
"""
def __init__(self, canvas, **kwprops):
initialProperties = {'width': 1,
'style': 'solid',
'cap': 'square',
'join': 'bevel',
}
initialProperties.update(kwprops)
Artist.__init__(self, canvas, **initialProperties)
self.setOrigin()
self.setPosition()
self.setEnd()
def setStart(self, x=0, y=0):
"""
Set the starting point of the line, in plot coordinates. Equivalent
to calling setPosition.
"""
self.setPosition(x, y)
def start(self):
"""
Return the starting point of the line, in plot coordinates.
Returns (x, y)
"""
return self.position()
def setEnd(self, x=0, y=0):
"""
Set the ending point of the line, in plot coordinates.
"""
self._ex = float(x)
self._ey = float(y)
def end(self):
"""
Return the ending point of the line, in plot coordinates.
Returns (x, y)
"""
return self._ex, self._ey
def setPoints(self, sx, sy, ex, ey, ox, oy):
"""
Set the start, end, and origin points for this line. Start and end are
in plot coordinates, and origin is in figure coordinates. Equivalent
to calling setStart, setEnd, and setOrigin separately.
"""
self.setOrigin(ox, oy)
self.setPosition(sx, sy)
self.setEnd(ex, ey)
def setWidth(self, width):
"""
Set the width of the line.
"""
self.setProps(width=int(width))
def setStyle(self, style):
"""
Set the style of the line.
"""
self.setProps(style=str(style))
def setCap(self, cap):
"""
Set the cap of the line.
"""
self.setProps(cap=str(cap))
def setJoin(self, join):
"""
Set the join of the line.
"""
self.setProps(join=str(join))
def _draw(self, *args, **kwargs):
return self.canvas().drawLine(self._x,
self._y,
self._ex,
self._ey,
self._ox,
self._oy,
clipPath=self.clipPath(),
**self.props())