1 from FrameWork
import *
15 TEXTWIDTH
=4096 # More-or-less random value
27 def __init__(self
, wid
, r
):
30 left
, top
, right
, bottom
= r
31 self
.terect
= left
+MARGIN
+ICONSIZE
, top
+MARGIN
, \
32 right
-(MARGIN
+SCROLLBAR
), bottom
-(MARGIN
+SCROLLBAR
)
33 dr
= self
.terect
[0], self
.terect
[1], TEXTWIDTH
, self
.terect
[3]
37 self
.ted
= TE
.TENew(dr
, self
.terect
)
38 self
.ted
.TEAutoView(1)
41 rect
= right
-SCROLLBAR
, top
, right
, bottom
-SCROLLBAR
+1
42 self
.bary
= Ctl
.NewControl(self
.wid
, rect
, "", 1, 0, 0, 0, 16, 0)
43 rect
= left
, bottom
-SCROLLBAR
, right
-SCROLLBAR
+1, bottom
44 self
.barx
= Ctl
.NewControl(self
.wid
, rect
, "", 1, 0, 0, 0, 16, 0)
57 def setcontent(self
, file):
64 fp
= open(file, 'rb') # NOTE the binary
68 data
= 'Cannot open file:\r'+`arg`
73 self
.ted
.TESetText(data
)
77 self
.line_index
.append(cur
)
79 cur
= string
.index(data
, '\r', cur
+1)
82 self
.line_index
.append(len(data
))
83 Win
.InvalRect(self
.rect
)
84 self
.ted
.TESetSelect(0,0)
89 def setscrollbars(self
):
90 docleft
, doctop
, docright
, docbot
= self
.ted
.destRect
91 winleft
, wintop
, winright
, winbot
= self
.ted
.viewRect
92 docbot
= self
.ted
.nLines
*self
.ted
.lineHeight
+ doctop
93 self
.setbar(self
.barx
, docleft
, docright
, winleft
, winright
)
94 self
.setbar(self
.bary
, doctop
, docbot
, wintop
, winbot
)
96 def setbar(self
, bar
, minmin
, maxmax
, curmin
, curmax
):
97 if maxmax
-minmin
> 32767 or (curmin
<= minmin
and curmax
>= maxmax
):
98 bar
.SetControlMinimum(0)
99 bar
.SetControlMaximum(0)
100 bar
.SetControlValue(0)
102 bar
.SetControlMinimum(minmin
)
103 bar
.SetControlMaximum(maxmax
-(curmax
-curmin
))
104 bar
.SetControlValue(curmin
)
106 def update(self
, rgn
):
107 Qd
.EraseRect(self
.terect
)
108 Qd
.FrameRect(self
.rect
)
109 self
.ted
.TEUpdate(self
.terect
)
111 def activate(self
, onoff
):
113 self
.ted
.TEActivate()
115 self
.ted
.TEDeactivate()
117 def select(self
, line
):
118 if line
== None or line
<= 0 or not self
.have_data
:
119 self
.ted
.TESetSelect(0,0)
122 if line
> len(self
.line_index
)-1: line
= len(self
.line_index
)-1
124 self
.ted
.TESetSelect(0, self
.line_index
[1])
126 self
.ted
.TESetSelect(self
.line_index
[line
]+1, self
.line_index
[line
+1])
129 def click(self
, where
, modifiers
):
130 # First check scrollbars
131 ctltype
, control
= Ctl
.FindControl(where
, self
.wid
)
132 if ctltype
and control
:
133 partcode
= control
.TrackControl(where
)
135 self
.controlhit(control
, partcode
)
137 off
= self
.ted
.TEGetOffset(where
)
138 inborder
= where
[0] < self
.terect
[0]
139 l
, t
, r
, b
= self
.terect
140 if l
<= where
[0] <= r
and t
<= where
[1] <= b
or inborder
:
141 return self
.offsettoline(off
), inborder
142 return None, 0 # In the grow box or something.
144 def offsettoline(self
, offset
):
145 for i
in range(len(self
.line_index
)):
146 if offset
< self
.line_index
[i
]:
147 return i
# Not i-1: 1-based line numbers in files
150 def controlhit(self
, control
, partcode
):
151 if partcode
<> Controls
.inThumb
:
152 if control
== self
.barx
:
153 if partcode
== Controls
.inUpButton
:
155 if partcode
== Controls
.inDownButton
:
157 if partcode
== Controls
.inPageUp
:
158 delta
= 10-(self
.terect
[2]-self
.terect
[0])
159 if partcode
== Controls
.inPageDown
:
160 delta
= (self
.terect
[2]-self
.terect
[0])-10
161 old
= control
.GetControlValue()
162 control
.SetControlValue(old
+delta
)
163 if control
== self
.bary
:
164 if partcode
== Controls
.inUpButton
:
165 delta
= -self
.ted
.lineHeight
166 if partcode
== Controls
.inDownButton
:
167 delta
= self
.ted
.lineHeight
168 if partcode
== Controls
.inPageUp
:
169 delta
= self
.ted
.lineHeight
-(self
.terect
[3]-self
.terect
[1])
170 if partcode
== Controls
.inPageDown
:
171 delta
= (self
.terect
[3]-self
.terect
[1])-self
.ted
.lineHeight
172 old
= control
.GetControlValue()
173 control
.SetControlValue(old
+delta
)
174 newx
= self
.barx
.GetControlValue()
175 newy
= self
.bary
.GetControlValue()
176 oldx
= self
.ted
.viewRect
[0]
177 oldy
= self
.ted
.viewRect
[1]
178 self
.ted
.TEPinScroll(oldx
-newx
, oldy
-newy
)
179 self
.setscrollbars() # XXXX Bibbert, maar hoe anders?
181 class MT_IconTextWidget(MT_TextWidget
):
182 def __init__(self
, wid
, r
):
183 MT_TextWidget
.__init
__(self
, wid
, r
)
184 self
.breakpointlist
= []
186 self
.iconrect
= (self
.rect
[0]+1, self
.rect
[1]+1,
187 self
.terect
[0]-1, self
.rect
[3]-SCROLLBAR
)
188 self
.curlinerange
= (self
.terect
[1]+self
.ted
.lineHeight
,
189 self
.terect
[3]-2*self
.ted
.lineHeight
)
190 self
.piccurrent
= PIC_CURRENT
192 def setbreaks(self
, list):
193 self
.breakpointlist
= list[:]
195 Win
.InvalRect(self
.iconrect
)
197 def setcurline(self
, line
, pic
=PIC_CURRENT
):
199 self
.piccurrent
= pic
203 def showline(self
, line
):
204 if line
<= 0: line
= 1
205 if line
>= len(self
.line_index
): line
= len(self
.line_index
)-1
207 off
= self
.line_index
[line
]
208 x
, y
= self
.ted
.TEGetPoint(off
)
209 if self
.curlinerange
[0] <= y
<= self
.curlinerange
[1]:
210 return # It is in view
211 middle
= (self
.curlinerange
[0]+self
.curlinerange
[1])/2
212 self
.ted
.TEPinScroll(0, middle
-y
) # Of andersom?
215 def setscrollbars(self
):
216 MT_TextWidget
.setscrollbars(self
)
217 Win
.InvalRect(self
.iconrect
)
219 def update(self
, rgn
):
220 MT_TextWidget
.update(self
, rgn
)
223 def drawallicons(self
):
224 Qd
.EraseRect(self
.iconrect
)
225 Qd
.MoveTo(self
.iconrect
[2], self
.iconrect
[1])
226 Qd
.LineTo(self
.iconrect
[2], self
.iconrect
[3])
227 topoffset
= self
.ted
.TEGetOffset((self
.terect
[0], self
.terect
[1]))
228 botoffset
= self
.ted
.TEGetOffset((self
.terect
[0], self
.terect
[3]))
229 topline
= self
.offsettoline(topoffset
)
230 botline
= self
.offsettoline(botoffset
)
231 if topline
== None: topline
= 1 # ???
232 if botline
== None: botline
= len(self
.line_index
)
233 for i
in self
.breakpointlist
:
234 if topline
<= i
<= botline
:
235 self
.draw1icon(i
, PIC_BREAK
)
236 if self
.curline
<> None and topline
<= self
.curline
<= botline
:
237 self
.draw1icon(self
.curline
, self
.piccurrent
)
239 def draw1icon(self
, line
, which
):
240 offset
= self
.line_index
[line
]
241 botx
, boty
= self
.ted
.TEGetPoint(offset
)
242 rect
= self
.rect
[0]+2, boty
-self
.ted
.lineHeight
, \
243 self
.rect
[0]+ICONSIZE
-2, boty
244 if not picture_cache
.has_key(which
):
245 picture_cache
[which
] = Qd
.GetPicture(which
)
246 self
.drawicon(rect
, picture_cache
[which
])
248 def drawicon(self
, rect
, which
):
249 Qd
.DrawPicture(which
, rect
)
252 def __init__(self
, wid
, rect
, width
):
253 # wid is the window (dialog) where our list is going to be in
254 # rect is it's item rectangle (as in dialog item)
256 rect2
= rect
[0]+1, rect
[1]+1, rect
[2]-16, rect
[3]-1
257 self
.list = List
.LNew(rect2
, (0, 0, width
, 0), (0,0), 0, wid
,
262 def setcontent(self
, *content
):
263 self
.list.LDelRow(0, 1)
264 self
.list.LSetDrawingMode(0)
265 self
.list.LAddRow(len(content
[0]), 0)
266 for x
in range(len(content
)):
268 for y
in range(len(column
)):
269 self
.list.LSetCell(column
[y
], (x
, y
))
270 self
.list.LSetDrawingMode(1)
271 Win
.InvalRect(self
.rect
)
273 def deselectall(self
):
275 ok
, pt
= self
.list.LGetSelect(1, (0,0))
277 self
.list.LSetSelect(0, pt
)
279 def select(self
, num
):
283 for i
in range(self
.width
):
284 self
.list.LSetSelect(1, (i
, num
))
286 def click(self
, where
, modifiers
):
287 is_double
= self
.list.LClick(where
, modifiers
)
288 ok
, (x
, y
) = self
.list.LGetSelect(1, (0, 0))
292 return None, is_double
294 # draw a frame around the list, List Manager doesn't do that
297 Qd
.FrameRect(self
.rect
)
299 def update(self
, rgn
):
301 self
.list.LUpdate(rgn
)
303 def activate(self
, onoff
):
304 self
.list.LActivate(onoff
)
306 class MT_AnyList(MT_IndexList
):
308 def click(self
, where
, modifiers
):
309 is_double
= self
.list.LClick(where
, modifiers
)
310 ok
, (x
, y
) = self
.list.LGetSelect(1, (0, 0))
313 field0
= self
.list.LGetCell(1000,(0,y
))
316 return field0
, is_double