3 # NB: this always assumes fixed bounds.
4 # For auto-growing TextEdit windows, different code would be needed.
6 from stdwinevents
import *
10 def create(self
, parent
, (cols
, rows
)):
16 # Creation of the editor is done in realize()
21 def createboxed(self
, parent
, (cols
, rows
), (dh
, dv
)):
22 self
= self
.create(parent
, (cols
, rows
))
27 def settext(self
, text
):
28 self
.editor
.settext(text
)
31 return self
.editor
.gettext(text
)
33 # Downcalls from parent to child
40 def getminsize(self
, m
, (width
, height
)):
41 width
= max(0, width
- 2*self
.dh
)
42 height
= max(0, height
- 2*self
.dv
)
43 if width
> 0 and self
.editor
:
44 (left
, top
), (right
, bottom
) = self
.editor
.getrect()
45 act_width
, act_height
= right
- left
, bottom
- top
46 if width
>= act_width
:
47 width
= width
+ 2*self
.dh
48 height
= max(height
, act_height
) + 2*self
.dv
50 width
= max(width
, self
.cols
*m
.textwidth('in')/2) + 2*self
.dh
51 height
= max(height
, self
.rows
*m
.lineheight()) + 2*self
.dv
54 def setbounds(self
, bounds
):
57 (left
, top
), (right
, bottom
) = bounds
60 right
= right
- self
.dh
61 bottom
= bottom
- self
.dv
62 self
.editor
.move((left
, top
), (right
, bottom
))
63 if self
.dh
and self
.dv
:
64 (left
, top
), (right
, bottom
) = bounds
69 bounds
= (left
, top
), (right
, bottom
)
70 self
.editor
.setview(bounds
)
76 self
.window
= self
.parent
.getwindow()
77 (left
, top
), (right
, bottom
) = self
.bounds
80 right
= right
- self
.dh
81 bottom
= bottom
- self
.dv
83 self
.window
.textcreate((left
, top
), (right
, bottom
))
84 self
.editor
.setactive(0)
86 if self
.dh
and self
.dv
:
87 (left
, top
), (right
, bottom
) = bounds
92 bounds
= (left
, top
), (right
, bottom
)
93 self
.editor
.setview(bounds
)
94 self
.editor
.settext(self
.text
)
95 self
.parent
.need_mouse(self
)
96 self
.parent
.need_keybd(self
)
97 self
.parent
.need_altdraw(self
)
99 def draw(self
, d
, area
):
100 if self
.dh
and self
.dv
:
103 def altdraw(self
, area
):
104 self
.editor
.draw(area
)
108 def mouse_down(self
, detail
):
109 x
= self
.editor
.event(WE_MOUSE_DOWN
, self
.window
, detail
)
111 def mouse_move(self
, detail
):
112 x
= self
.editor
.event(WE_MOUSE_MOVE
, self
.window
, detail
)
114 def mouse_up(self
, detail
):
115 x
= self
.editor
.event(WE_MOUSE_UP
, self
.window
, detail
)
117 def keybd(self
, type, detail
):
118 x
= self
.editor
.event(type, self
.window
, detail
)
121 self
.editor
.setfocus(0, 30000)
122 self
.editor
.setactive(1)
124 def deactivate(self
):
125 self
.editor
.setactive(0)