Skip to content

Commit a96d969

Browse files
committed
I can do python me . .
1 parent c81144e commit a96d969

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

esp32/modules/dialogs.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import ugfx, badge, utime as time
77

88
wait_for_interrupt = True
9+
button_pushed = ''
910

1011
def notice(text, title="SHA2017", close_text="Close", width = 296, height = 128, font="Roboto_Regular12"):
1112
prompt_boolean(text, title = title, true_text = close_text, false_text = None, width = width, height = height, font=font)
@@ -16,7 +17,7 @@ def prompt_boolean(text, title="SHA2017", true_text="Yes", false_text="No", widt
1617
if 'false_text' is set to None only one button is displayed.
1718
If both 'true_text' and 'false_text' are given a boolean is returned
1819
"""
19-
global wait_for_interrupt
20+
global wait_for_interrupt, button_pushed
2021

2122
window = ugfx.Container((ugfx.width() - width) // 2, (ugfx.height() - height) // 2, width, height)
2223
window.show()
@@ -43,8 +44,8 @@ def prompt_boolean(text, title="SHA2017", true_text="Yes", false_text="No", widt
4344

4445
wait_for_interrupt = True
4546
while wait_for_interrupt:
46-
if buttons.is_triggered("BTN_A"): return True
47-
if buttons.is_triggered("BTN_B"): return False
47+
if button_pushed == "A": return True
48+
if button_pushed == "B": return False
4849
time.sleep(0.2)
4950

5051
finally:
@@ -59,7 +60,7 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
5960
6061
Returns None if user aborts with button B
6162
"""
62-
global wait_for_interrupt
63+
global wait_for_interrupt, button_pushed
6364

6465
window = ugfx.Container(int((ugfx.width()-width)/2), int((ugfx.height()-height)/2), width, height)
6566

@@ -82,7 +83,7 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
8283
try:
8384
ugfx.input_init()
8485

85-
button_yes.attach_input(ugfx.BTN_MENU,0)
86+
button_yes.attach_input(ugfx.BTN_START,0)
8687
if button_no: button_no.attach_input(ugfx.BTN_B,0)
8788

8889
window.show()
@@ -91,9 +92,9 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
9192

9293
wait_for_interrupt = True
9394
while wait_for_interrupt:
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()
95+
if button_pushed == "B": return False
96+
if button_pushed == "START": return edit.text()
97+
time.sleep(0.2)
9798

9899
finally:
99100
window.hide()
@@ -111,7 +112,7 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
111112
If none_text is specified the user can use the B or Menu button to skip the selection
112113
if title is specified a blue title will be displayed about the text
113114
"""
114-
global wait_for_interrupt
115+
global wait_for_interrupt, button_pushed
115116

116117
ugfx.set_default_font("Roboto_Regular12")
117118
window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10)
@@ -147,9 +148,10 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
147148

148149
wait_for_interrupt = True
149150
while wait_for_interrupt:
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
151+
if button_pushed == "A": return options[options_list.selected_index()]
152+
if button_pushed == "B": return None
153+
if button_none and button_pushed == "START": return None
154+
time.sleep(0.2)
153155

154156
finally:
155157
window.hide()
@@ -160,12 +162,14 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
160162
ugfx.poll()
161163

162164

163-
def do_interrupt(pushed):
164-
global wait_for_interrupt
165+
def do_interrupt(button):
166+
global wait_for_interrupt, button_pushed
165167
wait_for_interrupt = False
168+
button_pushed = button
166169

167-
ugfx.input_attach(ugfx.BTN_A, do_interrupt)
168-
ugfx.input_attach(ugfx.BTN_B, do_interrupt)
170+
ugfx.input_attach(ugfx.BTN_A, do_interrupt('A'))
171+
ugfx.input_attach(ugfx.BTN_B, do_interrupt('B'))
172+
ugfx.input_attach(ugfx.BTN_START, do_interrupt('START'))
169173

170174
class WaitingMessage:
171175
"""Shows a dialog with a certain message that can not be dismissed by the user"""

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