Default to numeric input for phone number inputs
parent
966958873f
commit
8bf11d271f
|
@ -72,7 +72,7 @@ def prompt_boolean(text, title="TiLDA", true_text="Yes", false_text="No", font=F
|
||||||
if button_no: button_no.destroy()
|
if button_no: button_no.destroy()
|
||||||
label.destroy()
|
label.destroy()
|
||||||
|
|
||||||
def prompt_text(description, init_text="", true_text="OK", false_text="Back", font=FONT_MEDIUM_BOLD, style=default_style_badge):
|
def prompt_text(description, init_text="", true_text="OK", false_text="Back", font=FONT_MEDIUM_BOLD, style=default_style_badge, numeric=False):
|
||||||
"""Shows a dialog and keyboard that allows the user to input/change a string
|
"""Shows a dialog and keyboard that allows the user to input/change a string
|
||||||
|
|
||||||
Returns None if user aborts with button B
|
Returns None if user aborts with button B
|
||||||
|
@ -102,7 +102,7 @@ def prompt_text(description, init_text="", true_text="OK", false_text="Back", fo
|
||||||
if buttons.is_triggered(buttons.Buttons.BTN_A): return edit.text()
|
if buttons.is_triggered(buttons.Buttons.BTN_A): return edit.text()
|
||||||
if buttons.is_triggered(buttons.Buttons.BTN_B): return None
|
if buttons.is_triggered(buttons.Buttons.BTN_B): return None
|
||||||
if buttons.is_triggered(buttons.Buttons.BTN_Menu): return edit.text()
|
if buttons.is_triggered(buttons.Buttons.BTN_Menu): return edit.text()
|
||||||
handle_keypad(edit)
|
handle_keypad(edit, numeric)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
window.hide()
|
window.hide()
|
||||||
|
@ -116,7 +116,7 @@ def prompt_text(description, init_text="", true_text="OK", false_text="Back", fo
|
||||||
|
|
||||||
last_key = None
|
last_key = None
|
||||||
last_keytime = None
|
last_keytime = None
|
||||||
def handle_keypad(edit):
|
def handle_keypad(edit, numeric):
|
||||||
global last_key, last_keytime
|
global last_key, last_keytime
|
||||||
threshold = 1000
|
threshold = 1000
|
||||||
keymap = {
|
keymap = {
|
||||||
|
@ -136,7 +136,9 @@ def handle_keypad(edit):
|
||||||
|
|
||||||
for key, chars in keymap.items():
|
for key, chars in keymap.items():
|
||||||
if buttons.is_triggered(key):
|
if buttons.is_triggered(key):
|
||||||
if key != last_key:
|
if numeric:
|
||||||
|
edit.text(edit.text() + chars[-1])
|
||||||
|
elif key != last_key:
|
||||||
edit.text(edit.text() + chars[0])
|
edit.text(edit.text() + chars[0])
|
||||||
else:
|
else:
|
||||||
if last_keytime is None or (time.ticks_ms() - last_keytime) > threshold:
|
if last_keytime is None or (time.ticks_ms() - last_keytime) > threshold:
|
||||||
|
|
|
@ -19,7 +19,7 @@ ugfx.clear()
|
||||||
|
|
||||||
|
|
||||||
def makecall():
|
def makecall():
|
||||||
notocall = prompt_text("Number to call:")
|
notocall = prompt_text("Number to call:", numeric=True)
|
||||||
if (notocall):
|
if (notocall):
|
||||||
sim800.call(notocall)
|
sim800.call(notocall)
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ def send_message():
|
||||||
number = ""
|
number = ""
|
||||||
message = ""
|
message = ""
|
||||||
while True:
|
while True:
|
||||||
number = prompt_text("Number to message:", init_text=number)
|
number = prompt_text("Number to message:", init_text=number, numeric=True)
|
||||||
if number is None:
|
if number is None:
|
||||||
return
|
return
|
||||||
message = prompt_text("Message:", init_text=message)
|
message = prompt_text("Message:", init_text=message)
|
||||||
|
|
Loading…
Reference in New Issue