Skip to content

Commit fbdc1fd

Browse files
committed
Cleanup and porting dialog, still broken
1 parent b87abc3 commit fbdc1fd

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

esp32/modules/dialogs.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import ugfx, badge, utime as time
77

8+
wait_for_interupt = True
9+
810
def notice(text, title="SHA2017", close_text="Close", width = 296, height = 128, font="Roboto_Regular12"):
911
prompt_boolean(text, title = title, true_text = close_text, false_text = None, width = width, height = height, font=font)
1012

@@ -14,10 +16,12 @@ def prompt_boolean(text, title="SHA2017", true_text="Yes", false_text="No", widt
1416
if 'false_text' is set to None only one button is displayed.
1517
If both 'true_text' and 'false_text' are given a boolean is returned
1618
"""
19+
global wait_for_interupt
20+
1721
window = ugfx.Container((ugfx.width() - width) // 2, (ugfx.height() - height) // 2, width, height)
1822
window.show()
1923
ugfx.set_default_font(font)
20-
window.text(5, 10, title, TILDA_COLOR)
24+
window.text(5, 10, title, ugfx.BLACK)
2125
window.line(0, 30, width, 30, ugfx.BLACK)
2226

2327
if false_text:
@@ -31,15 +35,17 @@ def prompt_boolean(text, title="SHA2017", true_text="Yes", false_text="No", widt
3135
try:
3236
ugfx.input_init()
3337

34-
# button_yes.attach_input(ugfx.BTN_A,0)
35-
# if button_no: button_no.attach_input(ugfx.BTN_B,0)
38+
button_yes.attach_input(ugfx.BTN_A,0)
39+
if button_no: button_no.attach_input(ugfx.BTN_B,0)
3640

3741
window.show()
42+
ugfx.flush()
3843

39-
# while True:
40-
# pyb.wfi() # TODO make this!!
41-
# if buttons.is_triggered("BTN_A"): return True
42-
# if buttons.is_triggered("BTN_B"): return False
44+
wait_for_interupt = True
45+
while wait_for_interupt:
46+
if buttons.is_triggered("BTN_A"): return True
47+
if buttons.is_triggered("BTN_B"): return False
48+
time.sleep(0.2)
4349

4450
finally:
4551
window.hide()
@@ -53,6 +59,7 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
5359
5460
Returns None if user aborts with button B
5561
"""
62+
global wait_for_interupt
5663

5764
window = ugfx.Container(int((ugfx.width()-width)/2), int((ugfx.height()-height)/2), width, height)
5865

@@ -75,18 +82,18 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
7582
try:
7683
ugfx.input_init()
7784

78-
# button_yes.attach_input(ugfx.BTN_MENU,0)
79-
# if button_no: button_no.attach_input(ugfx.BTN_B,0)
80-
# TODO ^^
85+
button_yes.attach_input(ugfx.BTN_MENU,0)
86+
if button_no: button_no.attach_input(ugfx.BTN_B,0)
8187

8288
window.show()
8389
edit.set_focus()
84-
# while True:
85-
# pyb.wfi()
86-
# ugfx.poll()
87-
# #if buttons.is_triggered("BTN_A"): return edit.text()
88-
# if buttons.is_triggered("BTN_B"): return None
89-
# if buttons.is_triggered("BTN_MENU"): return edit.text()
90+
ugfx.flush()
91+
92+
wait_for_interupt = True
93+
while wait_for_interupt:
94+
#if buttons.is_triggered("BTN_A"): return edit.text()
95+
if buttons.is_triggered("BTN_B"): return None
96+
if buttons.is_triggered("BTN_MENU"): return edit.text()
9097

9198
finally:
9299
window.hide()
@@ -104,6 +111,8 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
104111
If none_text is specified the user can use the B or Menu button to skip the selection
105112
if title is specified a blue title will be displayed about the text
106113
"""
114+
global wait_for_interupt
115+
107116
ugfx.set_default_font("Roboto_Regular12")
108117
window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10)
109118
window.show()
@@ -136,12 +145,11 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
136145
try:
137146
ugfx.input_init()
138147

139-
# while True:
140-
# pyb.wfi() # BLABLA TODO
141-
# ugfx.poll()
142-
# if buttons.is_triggered("BTN_A"): return options[options_list.selected_index()]
143-
# if button_none and buttons.is_triggered("BTN_B"): return None
144-
# if button_none and buttons.is_triggered("BTN_MENU"): return None
148+
wait_for_interupt = True
149+
while wait_for_interupt:
150+
if buttons.is_triggered("BTN_A"): return options[options_list.selected_index()]
151+
if button_none and buttons.is_triggered("BTN_B"): return None
152+
if button_none and buttons.is_triggered("BTN_MENU"): return None
145153

146154
finally:
147155
window.hide()
@@ -153,10 +161,10 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
153161

154162
class WaitingMessage:
155163
"""Shows a dialog with a certain message that can not be dismissed by the user"""
156-
def __init__(self, text = "Please Wait...", title="TiLDA"):
164+
def __init__(self, text = "Please Wait...", title="SHA2017Badge"):
157165
self.window = ugfx.Container(30, 30, ugfx.width() - 60, ugfx.height() - 60)
158166
self.window.show()
159-
self.window.text(5, 10, title, TILDA_COLOR)
167+
self.window.text(5, 10, title, ugfx.BLACK)
160168
self.window.line(0, 30, ugfx.width() - 60, 30, ugfx.BLACK)
161169
self.label = ugfx.Label(5, 40, self.window.width() - 10, ugfx.height() - 40, text = text, parent=self.window)
162170

@@ -183,3 +191,6 @@ def __enter__(self):
183191

184192
def __exit__(self, exc_type, exc_value, traceback):
185193
self.destroy()
194+
195+
ugfx.input_attach(ugfx.BTN_A, lambda pushed: wait_for_interupt = False)
196+
ugfx.input_attach(ugfx.BTN_B, lambda pushed: wait_for_interupt = False)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy