Mercurial > cpython-lru_cache-weakref
annotate Lib/lib-stdwin/textwin.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 | 8b4a274e546d |
| children |
| rev | line source |
|---|---|
| 5 | 1 # Module 'textwin' |
| 2 | |
| 3 # Text windows, a subclass of gwin | |
| 4 | |
| 5 import stdwin | |
| 6 import gwin | |
| 533 | 7 from stdwinevents import * |
| 5 | 8 |
| 9 | |
| 10 def fixsize(w): | |
| 11 docwidth, docheight = w.text.getrect()[1] | |
| 12 winheight = w.getwinsize()[1] | |
| 13 if winheight > docheight: docheight = winheight | |
| 14 w.setdocsize(0, docheight) | |
| 15 fixeditmenu(w) | |
| 16 | |
| 17 def cut(w, m, id): | |
| 18 s = w.text.getfocustext() | |
| 19 if s: | |
|
104
4ec8c263ab48
Adapted to new cutbuffer interface.
Guido van Rossum <guido@python.org>
parents:
5
diff
changeset
|
20 stdwin.setcutbuffer(0, s) |
| 5 | 21 w.text.replace('') |
| 22 fixsize(w) | |
| 23 | |
| 24 def copy(w, m, id): | |
| 25 s = w.text.getfocustext() | |
| 26 if s: | |
|
104
4ec8c263ab48
Adapted to new cutbuffer interface.
Guido van Rossum <guido@python.org>
parents:
5
diff
changeset
|
27 stdwin.setcutbuffer(0, s) |
| 5 | 28 fixeditmenu(w) |
| 29 | |
| 30 def paste(w, m, id): | |
|
104
4ec8c263ab48
Adapted to new cutbuffer interface.
Guido van Rossum <guido@python.org>
parents:
5
diff
changeset
|
31 w.text.replace(stdwin.getcutbuffer(0)) |
| 5 | 32 fixsize(w) |
| 33 | |
| 34 def addeditmenu(w): | |
| 35 m = w.editmenu = w.menucreate('Edit') | |
| 36 m.action = [] | |
| 37 m.additem('Cut', 'X') | |
| 38 m.action.append(cut) | |
| 39 m.additem('Copy', 'C') | |
| 40 m.action.append(copy) | |
| 41 m.additem('Paste', 'V') | |
| 42 m.action.append(paste) | |
| 43 | |
| 44 def fixeditmenu(w): | |
| 45 m = w.editmenu | |
| 46 f = w.text.getfocus() | |
| 47 can_copy = (f[0] < f[1]) | |
| 48 m.enable(1, can_copy) | |
| 49 if not w.readonly: | |
| 50 m.enable(0, can_copy) | |
|
104
4ec8c263ab48
Adapted to new cutbuffer interface.
Guido van Rossum <guido@python.org>
parents:
5
diff
changeset
|
51 m.enable(2, (stdwin.getcutbuffer(0) <> '')) |
| 5 | 52 |
| 53 def draw(w, area): # Draw method | |
| 54 w.text.draw(area) | |
| 55 | |
| 56 def size(w, newsize): # Size method | |
| 57 w.text.move((0, 0), newsize) | |
| 58 fixsize(w) | |
| 59 | |
| 60 def close(w): # Close method | |
| 61 del w.text # Break circular ref | |
| 62 gwin.close(w) | |
| 63 | |
| 64 def char(w, c): # Char method | |
| 65 w.text.replace(c) | |
| 66 fixsize(w) | |
| 67 | |
| 68 def backspace(w): # Backspace method | |
| 533 | 69 void = w.text.event(WE_COMMAND, w, WC_BACKSPACE) |
| 5 | 70 fixsize(w) |
| 71 | |
| 72 def arrow(w, detail): # Arrow method | |
| 73 w.text.arrow(detail) | |
| 74 fixeditmenu(w) | |
| 75 | |
| 76 def mdown(w, detail): # Mouse down method | |
| 533 | 77 void = w.text.event(WE_MOUSE_DOWN, w, detail) |
| 5 | 78 fixeditmenu(w) |
| 79 | |
| 80 def mmove(w, detail): # Mouse move method | |
| 533 | 81 void = w.text.event(WE_MOUSE_MOVE, w, detail) |
| 5 | 82 |
| 83 def mup(w, detail): # Mouse up method | |
| 533 | 84 void = w.text.event(WE_MOUSE_UP, w, detail) |
| 5 | 85 fixeditmenu(w) |
| 86 | |
| 87 def activate(w): # Activate method | |
| 88 fixeditmenu(w) | |
| 89 | |
| 90 def open(title, str): # Display a string in a window | |
| 91 w = gwin.open(title) | |
| 92 w.readonly = 0 | |
| 93 w.text = w.textcreate((0, 0), w.getwinsize()) | |
| 94 w.text.replace(str) | |
| 95 w.text.setfocus(0, 0) | |
| 96 addeditmenu(w) | |
| 97 fixsize(w) | |
| 98 w.draw = draw | |
| 99 w.size = size | |
| 100 w.close = close | |
| 101 w.mdown = mdown | |
| 102 w.mmove = mmove | |
| 103 w.mup = mup | |
| 104 w.char = char | |
| 105 w.backspace = backspace | |
| 106 w.arrow = arrow | |
| 107 w.activate = activate | |
| 108 return w | |
| 109 | |
| 110 def open_readonly(title, str): # Same with char input disabled | |
| 111 w = open(title, str) | |
| 112 w.readonly = 1 | |
| 113 w.char = w.backspace = gwin.nop | |
| 114 # Disable Cut and Paste menu item; leave Copy alone | |
| 115 w.editmenu.enable(0, 0) | |
| 116 w.editmenu.enable(2, 0) | |
| 117 return w |
