Guido van Rossum | 2d844d1 | 1991-04-07 13:41:50 +0000 | [diff] [blame] | 1 | # Text editing widget |
| 2 | |
| 3 | from stdwinevents import * |
| 4 | |
| 5 | class TextEdit(): |
| 6 | # |
| 7 | def create(self, (parent, (cols, rows))): |
| 8 | parent.addchild(self) |
| 9 | self.parent = parent |
| 10 | self.cols = cols |
| 11 | self.rows = rows |
| 12 | self.text = '' |
| 13 | # Creation of the editor is done in realize() |
| 14 | self.editor = 0 |
| 15 | return self |
| 16 | # |
Guido van Rossum | a82a275 | 1991-04-21 19:27:48 +0000 | [diff] [blame^] | 17 | def settext(self, text): |
| 18 | self.editor.settext(text) |
| 19 | # |
Guido van Rossum | 2d844d1 | 1991-04-07 13:41:50 +0000 | [diff] [blame] | 20 | # Downcalls from parent to child |
| 21 | # |
| 22 | def destroy(self): |
| 23 | del self.parent |
| 24 | del self.editor |
| 25 | del self.window |
| 26 | # |
| 27 | def minsize(self, m): |
| 28 | return self.cols*m.textwidth('n'), self.rows*m.lineheight() |
| 29 | def setbounds(self, bounds): |
| 30 | self.bounds = bounds |
| 31 | if self.editor: |
| 32 | self.editor.move(bounds) |
| 33 | def getbounds(self, bounds): |
| 34 | if self.editor: |
| 35 | return self.editor.getrect() |
| 36 | else: |
| 37 | return self.bounds |
| 38 | def realize(self): |
| 39 | self.window = self.parent.getwindow() |
| 40 | self.editor = self.window.textcreate(self.bounds) |
Guido van Rossum | a82a275 | 1991-04-21 19:27:48 +0000 | [diff] [blame^] | 41 | self.editor.settext(self.text) |
Guido van Rossum | 2d844d1 | 1991-04-07 13:41:50 +0000 | [diff] [blame] | 42 | self.parent.need_mouse(self) |
| 43 | self.parent.need_keybd(self) |
| 44 | self.parent.need_altdraw(self) |
| 45 | def draw(self, (d, area)): |
| 46 | pass |
| 47 | def altdraw(self, area): |
| 48 | self.editor.draw(area) |
| 49 | # |
| 50 | # Event downcalls |
| 51 | # |
| 52 | def mouse_down(self, detail): |
| 53 | x = self.editor.event(WE_MOUSE_DOWN, self.window, detail) |
| 54 | def mouse_move(self, detail): |
| 55 | x = self.editor.event(WE_MOUSE_MOVE, self.window, detail) |
| 56 | def mouse_up(self, detail): |
| 57 | x = self.editor.event(WE_MOUSE_UP, self.window, detail) |
| 58 | # |
| 59 | def keybd(self, (type, detail)): |
| 60 | x = self.editor.event(type, self.window, detail) |
| 61 | # |