@@ -216,14 +216,14 @@ class URWIDRepl(repl.Repl):
216
216
217
217
# XXX this is getting silly, need to split this up somehow
218
218
def __init__ (self , main_loop , frame , listbox , listwalker , overlay ,
219
- tooltiptext , interpreter , statusbar , config ):
219
+ tooltip , interpreter , statusbar , config ):
220
220
repl .Repl .__init__ (self , interpreter , config )
221
221
self .main_loop = main_loop
222
222
self .frame = frame
223
223
self .listbox = listbox
224
224
self .listwalker = listwalker
225
225
self .overlay = overlay
226
- self .tooltiptext = tooltiptext
226
+ self .tooltip = tooltip
227
227
self .edits = []
228
228
self .edit = None
229
229
self .statusbar = statusbar
@@ -279,12 +279,20 @@ def cw(self):
279
279
return text [- i :]
280
280
281
281
def _populate_completion (self , main_loop , user_data ):
282
+ widget_list = self .tooltip .body
283
+ widget_list [1 ] = urwid .Text ('' )
282
284
# This is just me flailing around wildly. TODO: actually write.
283
285
if self .complete ():
284
- text = ' ' .join (self .matches )
285
286
if self .argspec :
286
- text = '%s\n \n %r' % (text , self .argspec )
287
- self .tooltiptext .set_text (text )
287
+ text = repr (self .argspec )
288
+ else :
289
+ text = ''
290
+ if self .matches :
291
+ texts = [urwid .Text (match ) for match in self .matches ]
292
+ width = max (text .pack ()[0 ] for text in texts )
293
+ gridflow = urwid .GridFlow (texts , width , 1 , 0 , 'left' )
294
+ widget_list [1 ] = gridflow
295
+ widget_list [0 ].set_text (text )
288
296
self .frame .body = self .overlay
289
297
else :
290
298
self .frame .body = self .listbox
@@ -342,13 +350,22 @@ def _reposition_tooltip(self):
342
350
# Cursor off the screen (no clue if this can happen).
343
351
# Just clamp to 0.
344
352
y = 0
353
+
354
+ # XXX the tooltip is displayed way too huge now. The easiest way
355
+ # to fix that is probably to figure out how much size the
356
+ # listbox actually needs here and adjust height_amount.
357
+
345
358
# XXX not sure if these overlay attributes are meant to be public...
346
359
if y * 2 < screen_rows :
347
360
self .overlay .valign_type = 'fixed top'
348
361
self .overlay .valign_amount = y + 1
362
+ self .overlay .height_type = 'fixed bottom'
363
+ self .overlay .height_amount = 0
349
364
else :
350
365
self .overlay .valign_type = 'fixed bottom'
351
366
self .overlay .valign_amount = screen_rows - y - 1
367
+ self .overlay .height_type = 'fixed top'
368
+ self .overlay .height_amount = 0
352
369
353
370
def handle_input (self , event ):
354
371
if event == 'enter' :
@@ -417,13 +434,11 @@ def main(args=None, locals_=None, banner=None):
417
434
config .pastebin_key , config .last_output_key ,
418
435
config .show_source_key ))
419
436
420
- # XXX this is not great: if the tooltip is too large the bottom line
421
- # of the LineBox gets eaten. That should not happen, and there
422
- # should be a nice indicator that the Edit widget is truncated.
423
- tooltiptext = urwid .Text ('' )
424
- overlay = Tooltip (urwid .Filler (urwid .LineBox (tooltiptext )), listbox ,
437
+ tooltip = urwid .ListBox (urwid .SimpleListWalker ([
438
+ urwid .Text ('' ), urwid .Text ('' )]))
439
+ overlay = Tooltip (urwid .LineBox (tooltip ), listbox ,
425
440
'left' , ('relative' , 100 ),
426
- ('fixed top' , 0 ), ('relative ' , 50 ))
441
+ ('fixed top' , 0 ), ('fixed bottom ' , 0 ))
427
442
428
443
frame = urwid .Frame (overlay , footer = statusbar .widget )
429
444
@@ -437,7 +452,7 @@ def main(args=None, locals_=None, banner=None):
437
452
loop = urwid .MainLoop (frame , palette , event_loop = event_loop )
438
453
439
454
# TODO: hook up idle callbacks somewhere.
440
- myrepl = URWIDRepl (loop , frame , listbox , listwalker , overlay , tooltiptext ,
455
+ myrepl = URWIDRepl (loop , frame , listbox , listwalker , overlay , tooltip ,
441
456
interpreter , statusbar , config )
442
457
443
458
# XXX HACK: circular dependency between the event loop and repl.
0 commit comments