Mercurial > cpython-lru_cache-weakref
annotate Lib/lib-stdwin/Buttons.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 1d06b1499eb9 |
| children |
| rev | line source |
|---|---|
| 31 | 1 # Module 'Buttons' |
| 28 | 2 |
| 3 | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
4 # Import module 'rect' renamed as '_rect' to avoid exporting it on |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
5 # 'from Buttons import *' |
| 28 | 6 # |
| 7 import rect | |
| 8 _rect = rect | |
| 9 del rect | |
| 10 | |
| 11 | |
| 12 # Field indices in mouse event detail | |
| 13 # | |
| 14 _HV = 0 | |
| 15 _CLICKS = 1 | |
| 16 _BUTTON = 2 | |
| 17 _MASK = 3 | |
| 18 | |
| 19 | |
| 31 | 20 # LabelAppearance provides defaults for all appearance methods. |
| 21 # selected state not visible | |
| 22 # disabled --> crossed out | |
| 23 # hilited --> inverted | |
| 28 | 24 # |
| 531 | 25 class LabelAppearance: |
| 28 | 26 # |
| 27 # Initialization | |
| 28 # | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
29 def init_appearance(self): |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
30 self.bounds = _rect.empty |
| 28 | 31 self.enabled = 1 |
| 32 self.hilited = 0 | |
| 33 self.selected = 0 | |
| 34 self.text = '' | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
35 # |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
36 # Size enquiry |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
37 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
38 def getminsize(self, m, (width, height)): |
|
345
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
39 width = max(width, m.textwidth(self.text) + 6) |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
40 height = max(height, m.lineheight() + 6) |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
41 return width, height |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
42 # |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
43 def getbounds(self): |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
44 return self.bounds |
| 28 | 45 # |
| 46 # Changing the parameters | |
| 47 # | |
| 48 def settext(self, text): | |
| 49 self.text = text | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
50 if self.bounds <> _rect.empty: |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
51 self.recalctextpos() |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
52 self.redraw() |
| 28 | 53 # |
| 54 def setbounds(self, bounds): | |
| 55 self.bounds = bounds | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
56 if self.bounds <> _rect.empty: |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
57 self.recalc() |
| 28 | 58 # |
|
188
d81818e62671
Added dummy realize() method.
Guido van Rossum <guido@python.org>
parents:
63
diff
changeset
|
59 def realize(self): |
|
d81818e62671
Added dummy realize() method.
Guido van Rossum <guido@python.org>
parents:
63
diff
changeset
|
60 pass |
|
d81818e62671
Added dummy realize() method.
Guido van Rossum <guido@python.org>
parents:
63
diff
changeset
|
61 # |
| 28 | 62 # Changing the state bits |
| 63 # | |
| 64 def enable(self, flag): | |
| 65 if flag <> self.enabled: | |
| 66 self.enabled = flag | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
67 if self.bounds <> _rect.empty: |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
68 self.flipenable(self.parent.begindrawing()) |
| 28 | 69 # |
| 70 def hilite(self, flag): | |
| 71 if flag <> self.hilited: | |
| 72 self.hilited = flag | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
73 if self.bounds <> _rect.empty: |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
74 self.fliphilite(self.parent.begindrawing()) |
| 28 | 75 # |
| 76 def select(self, flag): | |
| 77 if flag <> self.selected: | |
| 78 self.selected = flag | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
79 if self.bounds <> _rect.empty: |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
80 self.redraw() |
| 28 | 81 # |
| 31 | 82 # Recalculate the box bounds and text position. |
| 83 # This can be overridden by buttons that draw different boxes | |
| 84 # or want their text in a different position. | |
| 85 # | |
| 86 def recalc(self): | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
87 if self.bounds <> _rect.empty: |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
88 self.recalcbounds() |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
89 self.recalctextpos() |
| 31 | 90 # |
| 91 def recalcbounds(self): | |
| 92 self.hilitebounds = _rect.inset(self.bounds, (3, 3)) | |
| 93 self.crossbounds = self.bounds | |
| 94 # | |
| 95 def recalctextpos(self): | |
| 96 (left, top), (right, bottom) = self.bounds | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
97 m = self.parent.beginmeasuring() |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
98 h = (left + right - m.textwidth(self.text)) / 2 |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
99 v = (top + bottom - m.lineheight()) / 2 |
| 31 | 100 self.textpos = h, v |
| 101 # | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
102 # Generic drawing interface. |
| 31 | 103 # Do not override redraw() or draw() methods; override drawit() c.s. |
| 28 | 104 # |
| 105 def redraw(self): | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
106 if self.bounds <> _rect.empty: |
|
245
43133d885c4c
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
188
diff
changeset
|
107 d = self.parent.begindrawing() |
|
43133d885c4c
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
188
diff
changeset
|
108 d.erase(self.bounds) |
|
43133d885c4c
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
188
diff
changeset
|
109 self.draw(d, self.bounds) |
| 28 | 110 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
111 def draw(self, d, area): |
|
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
112 area = _rect.intersect([area, self.bounds]) |
| 559 | 113 if area == _rect.empty: |
| 28 | 114 return |
| 115 d.cliprect(area) | |
| 116 self.drawit(d) | |
| 117 d.noclip() | |
| 118 # | |
| 119 # The drawit() method is fairly generic but may be overridden. | |
| 120 # | |
| 121 def drawit(self, d): | |
| 31 | 122 self.drawpict(d) |
| 28 | 123 if self.text: |
| 31 | 124 d.text(self.textpos, self.text) |
| 28 | 125 if not self.enabled: |
| 126 self.flipenable(d) | |
| 127 if self.hilited: | |
| 128 self.fliphilite(d) | |
| 129 # | |
| 130 # Default drawing detail functions. | |
| 131 # Overriding these is normally sufficient to get different | |
| 132 # appearances. | |
| 133 # | |
| 134 def drawpict(self, d): | |
| 135 pass | |
| 136 # | |
| 137 def flipenable(self, d): | |
| 31 | 138 _xorcross(d, self.crossbounds) |
| 28 | 139 # |
| 140 def fliphilite(self, d): | |
| 31 | 141 d.invert(self.hilitebounds) |
| 28 | 142 |
| 143 | |
|
345
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
144 # A Strut is a label with no width of its own. |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
145 |
| 531 | 146 class StrutAppearance(LabelAppearance): |
|
345
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
147 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
148 def getminsize(self, m, (width, height)): |
|
345
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
149 height = max(height, m.lineheight() + 6) |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
150 return width, height |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
151 # |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
152 |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
153 |
| 28 | 154 # ButtonAppearance displays a centered string in a box. |
| 155 # selected --> bold border | |
| 156 # disabled --> crossed out | |
| 157 # hilited --> inverted | |
| 158 # | |
| 531 | 159 class ButtonAppearance(LabelAppearance): |
| 28 | 160 # |
| 161 def drawpict(self, d): | |
| 162 d.box(_rect.inset(self.bounds, (1, 1))) | |
| 163 if self.selected: | |
| 164 # Make a thicker box | |
| 165 d.box(self.bounds) | |
| 166 d.box(_rect.inset(self.bounds, (2, 2))) | |
| 167 d.box(_rect.inset(self.bounds, (3, 3))) | |
| 168 # | |
| 169 | |
| 170 | |
| 171 # CheckAppearance displays a small square box and a left-justified string. | |
| 172 # selected --> a cross appears in the box | |
| 173 # disabled --> whole button crossed out | |
| 174 # hilited --> box is inverted | |
| 175 # | |
| 531 | 176 class CheckAppearance(LabelAppearance): |
| 28 | 177 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
178 def getminsize(self, m, (width, height)): |
|
345
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
179 minwidth = m.textwidth(self.text) + 6 |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
180 minheight = m.lineheight() + 6 |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
181 width = max(width, minwidth + minheight + m.textwidth(' ')) |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
182 height = max(height, minheight) |
|
2e0ea6d5c6ce
Added class StrutAppearance (a label with with 0).
Guido van Rossum <guido@python.org>
parents:
245
diff
changeset
|
183 return width, height |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
184 # |
| 28 | 185 def drawpict(self, d): |
| 31 | 186 d.box(self.boxbounds) |
| 187 if self.selected: _xorcross(d, self.boxbounds) | |
| 28 | 188 # |
| 31 | 189 def recalcbounds(self): |
| 190 LabelAppearance.recalcbounds(self) | |
| 28 | 191 (left, top), (right, bottom) = self.bounds |
| 31 | 192 self.size = bottom - top - 4 |
| 193 self.boxbounds = (left+2, top+2), (left+2+self.size, bottom-2) | |
| 194 self.hilitebounds = self.boxbounds | |
| 28 | 195 # |
| 31 | 196 def recalctextpos(self): |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
197 m = self.parent.beginmeasuring() |
| 31 | 198 (left, top), (right, bottom) = self.boxbounds |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
199 h = right + m.textwidth(' ') |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
200 v = top + (self.size - m.lineheight()) / 2 |
| 31 | 201 self.textpos = h, v |
| 28 | 202 # |
| 203 | |
| 204 | |
| 205 # RadioAppearance displays a round indicator and a left-justified string. | |
| 206 # selected --> a dot appears in the indicator | |
| 207 # disabled --> whole button crossed out | |
| 208 # hilited --> indicator is inverted | |
| 209 # | |
| 531 | 210 class RadioAppearance(CheckAppearance): |
| 28 | 211 # |
| 212 def drawpict(self, d): | |
| 31 | 213 (left, top), (right, bottom) = self.boxbounds |
| 214 radius = self.size / 2 | |
|
245
43133d885c4c
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
188
diff
changeset
|
215 center = left + radius, top + radius |
|
43133d885c4c
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
188
diff
changeset
|
216 d.circle(center, radius) |
| 28 | 217 if self.selected: |
|
245
43133d885c4c
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
188
diff
changeset
|
218 d.fillcircle(center, radius*3/5) |
| 28 | 219 # |
| 220 | |
| 221 | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
222 # NoReactivity ignores mouse events. |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
223 # |
| 531 | 224 class NoReactivity: |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
225 def init_reactivity(self): pass |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
226 |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
227 |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
228 # BaseReactivity defines hooks and asks for mouse events, |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
229 # but provides only dummy mouse event handlers. |
| 28 | 230 # The trigger methods call the corresponding hooks set by the user. |
| 231 # Hooks (and triggers) mean the following: | |
| 232 # down_hook called on some mouse-down events | |
| 31 | 233 # move_hook called on some mouse-move events |
| 28 | 234 # up_hook called on mouse-up events |
| 235 # on_hook called for buttons with on/off state, when it goes on | |
| 236 # hook called when a button 'fires' or a radiobutton goes on | |
| 237 # There are usually extra conditions, e.g., hooks are only called | |
| 238 # when the button is enabled, or active, or selected (on). | |
| 239 # | |
| 531 | 240 class BaseReactivity: |
| 28 | 241 # |
| 242 def init_reactivity(self): | |
| 31 | 243 self.down_hook = self.move_hook = self.up_hook = \ |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
244 self.on_hook = self.off_hook = \ |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
245 self.hook = self.active = 0 |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
246 self.parent.need_mouse(self) |
| 28 | 247 # |
| 248 def mousetest(self, hv): | |
| 249 return _rect.pointinrect(hv, self.bounds) | |
| 250 # | |
| 251 def mouse_down(self, detail): | |
| 252 pass | |
| 253 # | |
| 254 def mouse_move(self, detail): | |
| 255 pass | |
| 256 # | |
| 257 def mouse_up(self, detail): | |
| 258 pass | |
| 259 # | |
| 260 def down_trigger(self): | |
| 261 if self.down_hook: self.down_hook(self) | |
| 262 # | |
| 31 | 263 def move_trigger(self): |
| 264 if self.move_hook: self.move_hook(self) | |
| 28 | 265 # |
| 266 def up_trigger(self): | |
| 267 if self.up_hook: self.up_hook(self) | |
| 268 # | |
| 269 def on_trigger(self): | |
| 270 if self.on_hook: self.on_hook(self) | |
| 271 # | |
| 272 def off_trigger(self): | |
| 273 if self.off_hook: self.off_hook(self) | |
| 274 # | |
| 275 def trigger(self): | |
| 276 if self.hook: self.hook(self) | |
| 277 | |
| 278 | |
| 279 # ToggleReactivity acts like a simple pushbutton. | |
| 280 # It toggles its hilite state on mouse down events. | |
| 281 # | |
| 531 | 282 class ToggleReactivity(BaseReactivity): |
| 28 | 283 # |
| 284 def mouse_down(self, detail): | |
| 285 if self.enabled and self.mousetest(detail[_HV]): | |
| 286 self.active = 1 | |
| 287 self.hilite(not self.hilited) | |
| 288 self.down_trigger() | |
| 289 # | |
| 290 def mouse_move(self, detail): | |
| 291 if self.active: | |
| 31 | 292 self.move_trigger() |
| 28 | 293 # |
| 294 def mouse_up(self, detail): | |
| 295 if self.active: | |
| 296 self.up_trigger() | |
| 297 self.active = 0 | |
| 298 # | |
| 299 def down_trigger(self): | |
| 300 if self.hilited: | |
| 301 self.on_trigger() | |
| 302 else: | |
| 303 self.off_trigger() | |
| 304 self.trigger() | |
| 305 # | |
| 306 | |
| 307 | |
| 308 # TriggerReactivity acts like a fancy pushbutton. | |
| 309 # It hilites itself while the mouse is down within its bounds. | |
| 310 # | |
| 531 | 311 class TriggerReactivity(BaseReactivity): |
| 28 | 312 # |
| 313 def mouse_down(self, detail): | |
| 314 if self.enabled and self.mousetest(detail[_HV]): | |
| 315 self.active = 1 | |
| 316 self.hilite(1) | |
| 317 self.down_trigger() | |
| 318 # | |
| 319 def mouse_move(self, detail): | |
| 320 if self.active: | |
| 321 self.hilite(self.mousetest(detail[_HV])) | |
| 322 if self.hilited: | |
| 31 | 323 self.move_trigger() |
| 28 | 324 # |
| 325 def mouse_up(self, detail): | |
| 326 if self.active: | |
| 327 self.hilite(self.mousetest(detail[_HV])) | |
| 328 if self.hilited: | |
| 329 self.up_trigger() | |
| 330 self.trigger() | |
| 331 self.active = 0 | |
| 332 self.hilite(0) | |
| 333 # | |
| 334 | |
| 335 | |
| 336 # CheckReactivity handles mouse events like TriggerReactivity, | |
| 337 # It overrides the up_trigger method to flip its selected state. | |
| 338 # | |
| 531 | 339 class CheckReactivity(TriggerReactivity): |
| 28 | 340 # |
| 341 def up_trigger(self): | |
| 342 self.select(not self.selected) | |
| 343 if self.selected: | |
| 344 self.on_trigger() | |
| 345 else: | |
| 346 self.off_trigger() | |
| 347 self.trigger() | |
| 348 | |
| 349 | |
| 350 # RadioReactivity turns itself on and the other buttons in its group | |
| 351 # off when its up_trigger method is called. | |
| 352 # | |
| 531 | 353 class RadioReactivity(TriggerReactivity): |
| 28 | 354 # |
| 355 def init_reactivity(self): | |
| 356 TriggerReactivity.init_reactivity(self) | |
| 357 self.group = [] | |
| 358 # | |
| 359 def up_trigger(self): | |
| 360 for b in self.group: | |
| 361 if b <> self: | |
| 362 if b.selected: | |
| 363 b.select(0) | |
| 364 b.off_trigger() | |
| 365 self.select(1) | |
| 366 self.on_trigger() | |
| 367 self.trigger() | |
| 368 | |
| 369 | |
| 370 # Auxiliary class for 'define' method. | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
371 # Call the initializers in the right order. |
| 28 | 372 # |
| 531 | 373 class Define: |
| 28 | 374 # |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
375 def define(self, parent): |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
376 self.parent = parent |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
377 parent.addchild(self) |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
378 self.init_appearance() |
| 28 | 379 self.init_reactivity() |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
380 return self |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
381 # |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
382 def destroy(self): |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
383 self.parent = 0 |
|
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
384 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
385 def definetext(self, parent, text): |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
386 self = self.define(parent) |
| 31 | 387 self.settext(text) |
| 28 | 388 return self |
| 389 | |
| 390 | |
| 31 | 391 # Subroutine to cross out a rectangle. |
| 392 # | |
| 393 def _xorcross(d, bounds): | |
| 394 ((left, top), (right, bottom)) = bounds | |
| 395 # This is s bit funny to make it look better | |
| 396 left = left + 2 | |
| 397 right = right - 2 | |
| 398 top = top + 2 | |
| 399 bottom = bottom - 3 | |
| 400 d.xorline(((left, top), (right, bottom))) | |
| 401 d.xorline((left, bottom), (right, top)) | |
| 402 | |
| 403 | |
|
63
61311506f2cd
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
52
diff
changeset
|
404 # Ready-made button classes. |
| 28 | 405 # |
| 531 | 406 class Label(NoReactivity, LabelAppearance, Define): pass |
| 407 class Strut(NoReactivity, StrutAppearance, Define): pass | |
| 408 class PushButton(TriggerReactivity, ButtonAppearance, Define): pass | |
| 409 class CheckButton(CheckReactivity, CheckAppearance, Define): pass | |
| 410 class RadioButton(RadioReactivity, RadioAppearance, Define): pass | |
| 411 class ToggleButton(ToggleReactivity, ButtonAppearance, Define): pass |
