diff options
author | Guido van Rossum <guido@python.org> | 1990-10-31 11:24:22 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1990-10-31 11:24:22 (GMT) |
commit | 36ddc9e31884d0143d9b23b7f72ddf4f3d45145f (patch) | |
tree | 97a5050b9050dbf0579a3bf8762f1032249a6616 /Lib/lib-stdwin/StripChart.py | |
parent | 6acc1b539aa007ad6896783031f473c2ebe11bc2 (diff) | |
download | cpython-36ddc9e31884d0143d9b23b7f72ddf4f3d45145f.zip cpython-36ddc9e31884d0143d9b23b7f72ddf4f3d45145f.tar.gz cpython-36ddc9e31884d0143d9b23b7f72ddf4f3d45145f.tar.bz2 |
Initial revision
Diffstat (limited to 'Lib/lib-stdwin/StripChart.py')
-rw-r--r-- | Lib/lib-stdwin/StripChart.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/Lib/lib-stdwin/StripChart.py b/Lib/lib-stdwin/StripChart.py new file mode 100644 index 0000000..2021cc4 --- /dev/null +++ b/Lib/lib-stdwin/StripChart.py @@ -0,0 +1,67 @@ +# Module 'StripChart' + + +import rect +from Buttons import * +from Resize import * + + +class StripChart() = LabelAppearance(), NoReactivity(), NoResize(): + # + def define(self, (win, bounds, scale)): + self.init_appearance(win, bounds) + self.init_reactivity() + self.init_resize() + self.ydata = [] + self.scale = scale + self.resetbounds() + return self + # + def setbounds(self, bounds): + LabelAppearance.setbounds(self, bounds) + self.resetbounds() + # + def resetbounds(self): + (left, top), (right, bottom) = self.bounds + self.width = right-left + self.height = bottom-top + excess = len(self.ydata) - self.width + if excess > 0: + del self.ydata[:excess] + elif excess < 0: + while len(self.ydata) < self.width: + self.ydata.insert(0, 0) + # + def append(self, y): + self.ydata.append(y) + excess = len(self.ydata) - self.width + if excess > 0: + del self.ydata[:excess] + if not self.limbo: + self.win.scroll(self.bounds, (-excess, 0)) + if not self.limbo: + (left, top), (right, bottom) = self.bounds + i = len(self.ydata) + area = (left+i-1, top), (left+i, bottom) + self.draw(self.win.begindrawing(), area) + # + def draw(self, (d, area)): + self.limbo = 0 + area = rect.intersect(area, self.bounds) + if area = rect.empty: + return + d.cliprect(area) + d.erase(self.bounds) + (a_left, a_top), (a_right, a_bottom) = area + (left, top), (right, bottom) = self.bounds + height = bottom - top + i1 = a_left - left + i2 = a_right - left + for i in range(max(0, i1), min(len(self.ydata), i2)): + split = bottom-self.ydata[i]*height/self.scale + d.paint((left+i, split), (left+i+1, bottom)) + if not self.enabled: + self.flipenable(d) + if self.hilited: + self.fliphilite(d) + d.noclip() |