@@ -106,8 +106,8 @@ def scan_networks_thread(self):
106106 networks = wlan .scan ()
107107 self .ssids = list (set (n [0 ].decode () for n in networks ))
108108 else :
109- time .sleep (2 )
110- self .ssids = ["Home WiFi" , "Pretty Fly for a WiFi " , "Winternet is coming" , "The Promised LAN" ]
109+ time .sleep (1 )
110+ self .ssids = ["Home WiFi" , "Pretty Fly for a Wi Fi " , "Winternet is coming" , "The Promised LAN" ]
111111 print (f"scan_networks: Found networks: { self .ssids } " )
112112 except Exception as e :
113113 print (f"scan_networks: Scan failed: { e } " )
@@ -253,9 +253,7 @@ def onCreate(self):
253253 self .password_ta .set_size (200 ,30 )
254254 self .password_ta .set_one_line (True )
255255 self .password_ta .align_to (label , lv .ALIGN .OUT_BOTTOM_MID , 5 , 0 )
256- self .password_ta .add_event_cb (lambda * args : self .show_keyboard (), lv .EVENT .CLICKED , None ) # it might be focused, but keyboard hidden (because ready/cancel clicked)
257- self .password_ta .add_event_cb (lambda * args : self .show_keyboard (), lv .EVENT .FOCUSED , None )
258- #self.password_ta.add_event_cb(lambda *args: self.hide_keyboard(), lv.EVENT.DEFOCUSED, None) # doesn't work for non-touchscreen (Keypad) control because then focus needs to go to the lv_keyboard widget
256+ self .password_ta .add_event_cb (lambda * args : self .show_keyboard (), lv .EVENT .CLICKED , None )
259257 print ("PasswordPage: Creating Connect button" )
260258 self .connect_button = lv .button (password_page )
261259 self .connect_button .set_size (100 ,40 )
@@ -284,7 +282,7 @@ def onCreate(self):
284282 self .keyboard .add_event_cb (lambda * args : self .hide_keyboard (), lv .EVENT .READY , None )
285283 self .keyboard .add_event_cb (lambda * args : self .hide_keyboard (), lv .EVENT .CANCEL , None )
286284 self .keyboard .add_flag (lv .obj .FLAG .HIDDEN )
287- self .keyboard .add_event_cb (self .print_events , lv .EVENT .ALL , None )
285+ self .keyboard .add_event_cb (self .handle_keyboard_events , lv .EVENT .VALUE_CHANGED , None )
288286 print ("PasswordPage: Loading password page" )
289287 self .setContentView (password_page )
290288
@@ -315,49 +313,21 @@ def show_keyboard(self):
315313 mpos .ui .anim .smooth_show (self .keyboard )
316314 focusgroup = lv .group_get_default ()
317315 if focusgroup :
318- focusgroup .focus_next () # move the focus to the keypad
316+ focusgroup .focus_next () # move the focus to the keypad to save the user a "next" button press (optional but nice)
319317
320318 def hide_keyboard (self ):
321319 self .connect_button .remove_flag (lv .obj .FLAG .HIDDEN )
322320 self .cancel_button .remove_flag (lv .obj .FLAG .HIDDEN )
323- focusgroup = lv .group_get_default ()
324- if focusgroup :
325- focusgroup .focus_prev () # move the focus to the close button, otherwise it goes back to the textarea, which opens the keyboard again
326321 mpos .ui .anim .smooth_hide (self .keyboard )
327322
328- def print_events (self , event ):
329- event_code = event .get_code ()
330- #print(f"got event {event_code}")
331- # Ignore:
332- # =======
333- # 19: HIT_TEST
334- # COVER_CHECK
335- # DRAW_MAIN
336- # DRAW_MAIN_BEGIN
337- # DRAW_MAIN_END
338- # DRAW_POST
339- # DRAW_POST_BEGIN
340- # DRAW_POST_END
341- # 39: CHILD_CHANGED
342- # GET_SELF_SIZE
343- if event_code not in [19 ,23 ,25 ,26 ,27 ,28 ,29 ,30 ,39 ,49 ]:
344- name = mpos .ui .get_event_name (event_code )
345- print (f"lv_event_t: code={ event_code } , name={ name } " )
346- #target=event.get_target()
347- #print(f"target: {target}") # blob
348- if event_code == lv .EVENT .VALUE_CHANGED :
349- button = self .keyboard .get_selected_button ()
350- text = self .keyboard .get_button_text (button )
351- print (f"button { button } and text { text } " )
352- if text == lv .SYMBOL .NEW_LINE :
353- print ("Newline pressed, would be nice to close the keyboard but that triggers the cancel button..." )
354- #self.hide_keyboard() # makes cancel button click!
355- #self.keyboard.send_event(lv.EVENT.READY, None)
356- # workaround: dont change focus to cancel button:
357- #self.connect_button.remove_flag(lv.obj.FLAG.HIDDEN)
358- #self.cancel_button.remove_flag(lv.obj.FLAG.HIDDEN)
359- #mpos.ui.anim.smooth_hide(self.keyboard)
360- # => doesnt work because then the focus goes back to the keyboard which reopens
323+ def handle_keyboard_events (self , event ):
324+ target_obj = event .get_target_obj () # keyboard
325+ button = target_obj .get_selected_button ()
326+ text = target_obj .get_button_text (button )
327+ #print(f"button {button} and text {text}")
328+ if text == lv .SYMBOL .NEW_LINE :
329+ print ("Newline pressed, closing the keyboard..." )
330+ self .hide_keyboard ()
361331
362332 @staticmethod
363333 def setPassword (ssid , password ):
0 commit comments