6
6
import ugfx , badge , utime as time
7
7
8
8
wait_for_interrupt = True
9
+ button_pushed = ''
9
10
10
11
def notice (text , title = "SHA2017" , close_text = "Close" , width = 296 , height = 128 , font = "Roboto_Regular12" ):
11
12
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
16
17
if 'false_text' is set to None only one button is displayed.
17
18
If both 'true_text' and 'false_text' are given a boolean is returned
18
19
"""
19
- global wait_for_interrupt
20
+ global wait_for_interrupt , button_pushed
20
21
21
22
window = ugfx .Container ((ugfx .width () - width ) // 2 , (ugfx .height () - height ) // 2 , width , height )
22
23
window .show ()
@@ -43,8 +44,8 @@ def prompt_boolean(text, title="SHA2017", true_text="Yes", false_text="No", widt
43
44
44
45
wait_for_interrupt = True
45
46
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
48
49
time .sleep (0.2 )
49
50
50
51
finally :
@@ -59,7 +60,7 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
59
60
60
61
Returns None if user aborts with button B
61
62
"""
62
- global wait_for_interrupt
63
+ global wait_for_interrupt , button_pushed
63
64
64
65
window = ugfx .Container (int ((ugfx .width ()- width )/ 2 ), int ((ugfx .height ()- height )/ 2 ), width , height )
65
66
@@ -82,7 +83,7 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
82
83
try :
83
84
ugfx .input_init ()
84
85
85
- button_yes .attach_input (ugfx .BTN_MENU ,0 )
86
+ button_yes .attach_input (ugfx .BTN_START ,0 )
86
87
if button_no : button_no .attach_input (ugfx .BTN_B ,0 )
87
88
88
89
window .show ()
@@ -91,9 +92,9 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
91
92
92
93
wait_for_interrupt = True
93
94
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 )
97
98
98
99
finally :
99
100
window .hide ()
@@ -111,7 +112,7 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
111
112
If none_text is specified the user can use the B or Menu button to skip the selection
112
113
if title is specified a blue title will be displayed about the text
113
114
"""
114
- global wait_for_interrupt
115
+ global wait_for_interrupt , button_pushed
115
116
116
117
ugfx .set_default_font ("Roboto_Regular12" )
117
118
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:"
147
148
148
149
wait_for_interrupt = True
149
150
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 )
153
155
154
156
finally :
155
157
window .hide ()
@@ -160,12 +162,14 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
160
162
ugfx .poll ()
161
163
162
164
163
- def do_interrupt (pushed ):
164
- global wait_for_interrupt
165
+ def do_interrupt (button ):
166
+ global wait_for_interrupt , button_pushed
165
167
wait_for_interrupt = False
168
+ button_pushed = button
166
169
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' ))
169
173
170
174
class WaitingMessage :
171
175
"""Shows a dialog with a certain message that can not be dismissed by the user"""
0 commit comments