Mercurial > cpython-lru_cache-weakref
annotate Lib/lib-stdwin/StripChart.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 1d06b1499eb9 |
| children |
| rev | line source |
|---|---|
| 55 | 1 # Module 'StripChart' |
| 2 | |
| 3 import rect | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
55
diff
changeset
|
4 from Buttons import LabelAppearance, NoReactivity |
| 55 | 5 |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
55
diff
changeset
|
6 # A StripChart doesn't really look like a label but it needs a base class. |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
55
diff
changeset
|
7 # LabelAppearance allows it to be disabled and hilited. |
| 55 | 8 |
| 531 | 9 class StripChart(LabelAppearance, NoReactivity): |
| 55 | 10 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
11 def define(self, parent, scale): |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
55
diff
changeset
|
12 self.parent = parent |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
55
diff
changeset
|
13 parent.addchild(self) |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
55
diff
changeset
|
14 self.init_appearance() |
| 55 | 15 self.init_reactivity() |
| 16 self.ydata = [] | |
| 17 self.scale = scale | |
| 18 self.resetbounds() | |
| 19 return self | |
| 20 # | |
| 211 | 21 def destroy(self): |
| 22 self.parent = 0 | |
| 23 # | |
| 55 | 24 def setbounds(self, bounds): |
| 25 LabelAppearance.setbounds(self, bounds) | |
| 26 self.resetbounds() | |
| 27 # | |
| 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 | |
| 33 if excess > 0: | |
| 34 del self.ydata[:excess] | |
| 35 elif excess < 0: | |
| 36 while len(self.ydata) < self.width: | |
| 37 self.ydata.insert(0, 0) | |
| 38 # | |
| 39 def append(self, y): | |
| 40 self.ydata.append(y) | |
| 41 excess = len(self.ydata) - self.width | |
| 42 if excess > 0: | |
| 43 del self.ydata[:excess] | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
55
diff
changeset
|
44 if self.bounds <> rect.empty: |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
55
diff
changeset
|
45 self.parent.scroll(self.bounds, (-excess, 0)) |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
55
diff
changeset
|
46 if self.bounds <> rect.empty: |
| 55 | 47 (left, top), (right, bottom) = self.bounds |
| 48 i = len(self.ydata) | |
| 49 area = (left+i-1, top), (left+i, bottom) | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
55
diff
changeset
|
50 self.draw(self.parent.begindrawing(), area) |
| 55 | 51 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
52 def draw(self, d, area): |
|
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
53 area = rect.intersect([area, self.bounds]) |
| 559 | 54 if area == rect.empty: |
| 55 | 55 return |
| 56 d.cliprect(area) | |
| 57 d.erase(self.bounds) | |
| 58 (a_left, a_top), (a_right, a_bottom) = area | |
| 59 (left, top), (right, bottom) = self.bounds | |
| 60 height = bottom - top | |
| 61 i1 = a_left - left | |
| 62 i2 = a_right - left | |
| 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)) | |
| 66 if not self.enabled: | |
| 67 self.flipenable(d) | |
| 68 if self.hilited: | |
| 69 self.fliphilite(d) | |
| 70 d.noclip() |
