2626 "WAutoComplete" ,
2727)
2828
29+
2930class Dialog (Widget ):
3031
3132 finish_on_esc = True
@@ -108,6 +109,8 @@ def change_focus(self, widget):
108109 widget .set_cursor ()
109110
110111 def move_focus (self , direction ):
112+ if self .focus_idx is None :
113+ self .focus_idx = 0
111114 prev_idx = (self .focus_idx + direction ) % len (self .childs )
112115 self .focus_idx , new_w = self .find_focusable_by_idx (prev_idx , direction )
113116 self .change_focus (new_w )
@@ -137,14 +140,13 @@ def handle_mouse(self, x, y):
137140 # Work in absolute coordinates
138141 if self .inside (x , y ):
139142 self .focus_idx , w = self .find_focusable_by_xy (x , y )
140- # print(w)
143+ # print(w)
141144 if w :
142145 self .change_focus (w )
143146 return w .handle_mouse (x , y )
144147
145148
146149class WLabel (Widget ):
147-
148150 def __init__ (self , text , w = 0 ):
149151 self .t = text
150152 self .h = 1
@@ -158,7 +160,6 @@ def redraw(self):
158160
159161
160162class WFrame (Widget ):
161-
162163 def __init__ (self , w , h , title = "" ):
163164 self .w = w
164165 self .h = h
@@ -173,7 +174,6 @@ def redraw(self):
173174
174175
175176class WButton (FocusableWidget ):
176-
177177 def __init__ (self , w , text ):
178178 Widget .__init__ (self )
179179 self .t = text
@@ -217,7 +217,6 @@ def on_click(self):
217217
218218
219219class WCheckbox (ChoiceWidget ):
220-
221220 def __init__ (self , title , choice = False ):
222221 super ().__init__ (choice )
223222 self .t = title
@@ -251,7 +250,6 @@ def handle_key(self, key):
251250
252251
253252class WRadioButton (ItemSelWidget ):
254-
255253 def __init__ (self , items ):
256254 super ().__init__ (items )
257255 self .h = len (items )
@@ -282,7 +280,6 @@ def handle_key(self, key):
282280
283281
284282class WListBox (EditorExt , ChoiceWidget ):
285-
286283 def __init__ (self , w , h , items ):
287284 EditorExt .__init__ (self )
288285 ChoiceWidget .__init__ (self , 0 )
@@ -310,7 +307,7 @@ def show_line(self, l, i):
310307 else :
311308 self .attr_color (C_BLACK , C_GREEN )
312309 if i != - 1 :
313- l = self .render_line (l )[:self .width ]
310+ l = self .render_line (l )[: self .width ]
314311 self .wr (l )
315312 self .clear_num_pos (self .width - len (l ))
316313 if hlite :
@@ -342,9 +339,7 @@ def cursor(self, state):
342339
343340
344341class WPopupList (Dialog ):
345-
346342 class OneShotList (WListBox ):
347-
348343 def handle_key (self , key ):
349344 if key == KEY_ENTER :
350345 return ACTION_OK
@@ -378,7 +373,6 @@ def get_selected_value(self):
378373
379374
380375class WDropDown (ChoiceWidget ):
381-
382376 def __init__ (self , w , items , * , dropdown_h = 5 ):
383377 super ().__init__ (0 )
384378 self .items = items
@@ -398,7 +392,9 @@ def redraw(self):
398392 self .wr (DOWN_ARROW )
399393
400394 def handle_mouse (self , x , y ):
401- popup = WPopupList (self .x , self .y + 1 , self .w , self .dropdown_h , self .items , self .choice )
395+ popup = WPopupList (
396+ self .x , self .y + 1 , self .w , self .dropdown_h , self .items , self .choice
397+ )
402398 res = popup .loop ()
403399 if res == ACTION_OK :
404400 self .choice = popup .get_choice ()
@@ -410,7 +406,6 @@ def handle_key(self, key):
410406
411407
412408class WTextEntry (EditorExt , EditableWidget ):
413-
414409 def __init__ (self , w , text ):
415410 EditorExt .__init__ (self , width = w , height = 1 )
416411 self .t = text
@@ -466,13 +461,11 @@ def show_line(self, l, i):
466461
467462
468463class WPasswdEntry (WTextEntry ):
469-
470464 def show_line (self , l , i ):
471465 super ().show_line ("*" * len (l ), i )
472466
473467
474468class WMultiEntry (EditorExt , EditableWidget ):
475-
476469 def __init__ (self , w , h , lines ):
477470 EditorExt .__init__ (self , width = w , height = h )
478471 self .h = h
@@ -514,7 +507,9 @@ def get_choices(self, substr):
514507
515508 def show_popup (self ):
516509 choices = self .get_choices (self .get ())
517- popup = self .popup_class (self .x , self .y + 1 , self .longest (choices ) + 2 , self .popup_h , choices )
510+ popup = self .popup_class (
511+ self .x , self .y + 1 , self .longest (choices ) + 2 , self .popup_h , choices
512+ )
518513 popup .main_widget = self
519514 res = popup .loop ()
520515 if res == ACTION_OK :
@@ -541,12 +536,12 @@ def handle_mouse(self, x, y):
541536
542537
543538class WCompletionList (WPopupList ):
544-
545539 def __init__ (self , x , y , w , h , items ):
546540 Dialog .__init__ (self , x , y , w , h )
547541 self .list = self .OneShotList (w - 2 , h - 2 , items )
548542 self .add (1 , 1 , self .list )
549543 chk = WCheckbox ("Prefix" )
544+
550545 def is_prefix_changed (wid ):
551546 main = self .main_widget
552547 choices = main .get_choices (main .get (), wid .choice )
@@ -555,6 +550,7 @@ def is_prefix_changed(wid):
555550 self .list .cur_line = 0
556551 self .list .row = 0
557552 self .list .redraw ()
553+
558554 chk .on ("changed" , is_prefix_changed )
559555 self .add (1 , h - 1 , chk )
560556
0 commit comments