4 from Buttons
import LabelAppearance
, NoReactivity
6 # A StripChart doesn't really look like a label but it needs a base class.
7 # LabelAppearance allows it to be disabled and hilited.
9 class StripChart(LabelAppearance
, NoReactivity
):
11 def define(self
, parent
, scale
):
14 self
.init_appearance()
15 self
.init_reactivity()
24 def setbounds(self
, bounds
):
25 LabelAppearance
.setbounds(self
, bounds
)
28 def resetbounds(self
):
29 (left
, top
), (right
, bottom
) = self
.bounds
30 self
.width
= right
-left
31 self
.height
= bottom
-top
32 excess
= len(self
.ydata
) - self
.width
34 del self
.ydata
[:excess
]
36 while len(self
.ydata
) < self
.width
:
37 self
.ydata
.insert(0, 0)
41 excess
= len(self
.ydata
) - self
.width
43 del self
.ydata
[:excess
]
44 if self
.bounds
<> rect
.empty
:
45 self
.parent
.scroll(self
.bounds
, (-excess
, 0))
46 if self
.bounds
<> rect
.empty
:
47 (left
, top
), (right
, bottom
) = self
.bounds
49 area
= (left
+i
-1, top
), (left
+i
, bottom
)
50 self
.draw(self
.parent
.begindrawing(), area
)
52 def draw(self
, d
, area
):
53 area
= rect
.intersect([area
, self
.bounds
])
54 if area
== rect
.empty
:
58 (a_left
, a_top
), (a_right
, a_bottom
) = area
59 (left
, top
), (right
, bottom
) = self
.bounds
63 for i
in range(max(0, i1
), min(len(self
.ydata
), i2
)):
64 split
= bottom
-self
.ydata
[i
]*height
/self
.scale
65 d
.paint((left
+i
, split
), (left
+i
+1, bottom
))