2 # List windows, a subclass of gwin
7 def maxlinewidth(a
): # Compute maximum textwidth of lines in a sequence
10 width
= stdwin
.textwidth(line
)
11 if width
> max: max = width
14 def action(w
, string
, i
, detail
): # Default item selection method
17 def mup(w
, detail
): # Mouse up method
18 (h
, v
), clicks
, button
, mask
= detail
19 i
= divmod(v
, w
.lineheight
)[0]
20 if 0 <= i
< len(w
.data
):
21 w
.action(w
, w
.data
[i
], i
, detail
)
23 def draw(w
, ((left
, top
), (right
, bottom
))): # Text window draw method
28 ibot
= (bottom
-1)/lh
+ 1
30 if ibot
> len(data
): ibot
= len(data
)
31 for i
in range(itop
, ibot
): d
.text((0, i
*lh
), data
[i
])
33 def open(title
, data
): # Display a list of texts in a window
34 lineheight
= stdwin
.lineheight()
35 h
, v
= maxlinewidth(data
), len(data
)*lineheight
36 h0
, v0
= h
+ stdwin
.textwidth(' '), v
+ lineheight
37 if h0
> stdwin
.textwidth(' ')*80: h0
= 0
38 if v0
> stdwin
.lineheight()*24: v0
= 0
39 stdwin
.setdefwinsize(h0
, v0
)
42 w
.lineheight
= lineheight