Mercurial > cpython-lru_cache-weakref
annotate Lib/stdwin/TextEdit.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 |
|---|---|
| 195 | 1 # Text editing widget |
| 2 | |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
3 # NB: this always assumes fixed bounds. |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
4 # For auto-growing TextEdit windows, different code would be needed. |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
5 |
| 195 | 6 from stdwinevents import * |
| 7 | |
| 538 | 8 class TextEdit: |
| 195 | 9 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
928
diff
changeset
|
10 def create(self, parent, (cols, rows)): |
| 195 | 11 parent.addchild(self) |
| 12 self.parent = parent | |
| 13 self.cols = cols | |
| 14 self.rows = rows | |
| 15 self.text = '' | |
| 16 # Creation of the editor is done in realize() | |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
17 self.editor = None |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
18 self.dh = self.dv = 0 |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
19 return self |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
20 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
928
diff
changeset
|
21 def createboxed(self, parent, (cols, rows), (dh, dv)): |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
22 self = self.create(parent, (cols, rows)) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
23 self.dh = max(0, dh) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
24 self.dv = max(0, dv) |
| 195 | 25 return self |
| 26 # | |
|
212
a793c9e880c7
Use text object's new settext() method.
Guido van Rossum <guido@python.org>
parents:
195
diff
changeset
|
27 def settext(self, text): |
|
a793c9e880c7
Use text object's new settext() method.
Guido van Rossum <guido@python.org>
parents:
195
diff
changeset
|
28 self.editor.settext(text) |
|
a793c9e880c7
Use text object's new settext() method.
Guido van Rossum <guido@python.org>
parents:
195
diff
changeset
|
29 # |
|
928
8725fa8d7ff9
Removed *.libs (now in ./sgi);
Guido van Rossum <guido@python.org>
parents:
538
diff
changeset
|
30 def gettext(self): |
|
8725fa8d7ff9
Removed *.libs (now in ./sgi);
Guido van Rossum <guido@python.org>
parents:
538
diff
changeset
|
31 return self.editor.gettext(text) |
|
8725fa8d7ff9
Removed *.libs (now in ./sgi);
Guido van Rossum <guido@python.org>
parents:
538
diff
changeset
|
32 # |
| 195 | 33 # Downcalls from parent to child |
| 34 # | |
| 35 def destroy(self): | |
| 36 del self.parent | |
| 37 del self.editor | |
| 38 del self.window | |
| 39 # | |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
928
diff
changeset
|
40 def getminsize(self, m, (width, height)): |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
41 width = max(0, width - 2*self.dh) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
42 height = max(0, height - 2*self.dv) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
43 if width > 0 and self.editor: |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
44 (left, top), (right, bottom) = self.editor.getrect() |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
45 act_width, act_height = right - left, bottom - top |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
46 if width >= act_width: |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
47 width = width + 2*self.dh |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
48 height = max(height, act_height) + 2*self.dv |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
49 return width, height |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
50 width = max(width, self.cols*m.textwidth('in')/2) + 2*self.dh |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
51 height = max(height, self.rows*m.lineheight()) + 2*self.dv |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
52 return width, height |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
53 # |
| 195 | 54 def setbounds(self, bounds): |
| 55 self.bounds = bounds | |
| 56 if self.editor: | |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
57 (left, top), (right, bottom) = bounds |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
58 left = left + self.dh |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
59 top = top + self.dv |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
60 right = right - self.dh |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
61 bottom = bottom - self.dv |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
62 self.editor.move((left, top), (right, bottom)) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
63 if self.dh and self.dv: |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
64 (left, top), (right, bottom) = bounds |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
65 left = left + 1 |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
66 top = top + 1 |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
67 right = right - 1 |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
68 bottom = bottom - 1 |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
69 bounds = (left, top), (right, bottom) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
70 self.editor.setview(bounds) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
71 # |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
72 def getbounds(self): |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
73 return self.bounds |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
74 # |
| 195 | 75 def realize(self): |
| 76 self.window = self.parent.getwindow() | |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
77 (left, top), (right, bottom) = self.bounds |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
78 left = left + self.dh |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
79 top = top + self.dv |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
80 right = right - self.dh |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
81 bottom = bottom - self.dv |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
82 self.editor = \ |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
83 self.window.textcreate((left, top), (right, bottom)) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
84 self.editor.setactive(0) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
85 bounds = self.bounds |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
86 if self.dh and self.dv: |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
87 (left, top), (right, bottom) = bounds |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
88 left = left + 1 |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
89 top = top + 1 |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
90 right = right - 1 |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
91 bottom = bottom - 1 |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
92 bounds = (left, top), (right, bottom) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
93 self.editor.setview(bounds) |
|
212
a793c9e880c7
Use text object's new settext() method.
Guido van Rossum <guido@python.org>
parents:
195
diff
changeset
|
94 self.editor.settext(self.text) |
| 195 | 95 self.parent.need_mouse(self) |
| 96 self.parent.need_keybd(self) | |
| 97 self.parent.need_altdraw(self) | |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
98 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
928
diff
changeset
|
99 def draw(self, d, area): |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
100 if self.dh and self.dv: |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
101 d.box(self.bounds) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
102 # |
| 195 | 103 def altdraw(self, area): |
| 104 self.editor.draw(area) | |
| 105 # | |
| 106 # Event downcalls | |
| 107 # | |
| 108 def mouse_down(self, detail): | |
| 109 x = self.editor.event(WE_MOUSE_DOWN, self.window, detail) | |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
110 # |
| 195 | 111 def mouse_move(self, detail): |
| 112 x = self.editor.event(WE_MOUSE_MOVE, self.window, detail) | |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
113 # |
| 195 | 114 def mouse_up(self, detail): |
| 115 x = self.editor.event(WE_MOUSE_UP, self.window, detail) | |
| 116 # | |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
928
diff
changeset
|
117 def keybd(self, type, detail): |
| 195 | 118 x = self.editor.event(type, self.window, detail) |
| 119 # | |
|
352
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
120 def activate(self): |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
121 self.editor.setfocus(0, 30000) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
122 self.editor.setactive(1) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
123 # |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
124 def deactivate(self): |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
125 self.editor.setactive(0) |
|
d93259cd379d
Added activate/deactivate.
Guido van Rossum <guido@python.org>
parents:
246
diff
changeset
|
126 # |
