5
5
6
6
import ugfx , badge , utime as time
7
7
8
+ wait_for_interupt = True
9
+
8
10
def notice (text , title = "SHA2017" , close_text = "Close" , width = 296 , height = 128 , font = "Roboto_Regular12" ):
9
11
prompt_boolean (text , title = title , true_text = close_text , false_text = None , width = width , height = height , font = font )
10
12
@@ -14,10 +16,12 @@ def prompt_boolean(text, title="SHA2017", true_text="Yes", false_text="No", widt
14
16
if 'false_text' is set to None only one button is displayed.
15
17
If both 'true_text' and 'false_text' are given a boolean is returned
16
18
"""
19
+ global wait_for_interupt
20
+
17
21
window = ugfx .Container ((ugfx .width () - width ) // 2 , (ugfx .height () - height ) // 2 , width , height )
18
22
window .show ()
19
23
ugfx .set_default_font (font )
20
- window .text (5 , 10 , title , TILDA_COLOR )
24
+ window .text (5 , 10 , title , ugfx . BLACK )
21
25
window .line (0 , 30 , width , 30 , ugfx .BLACK )
22
26
23
27
if false_text :
@@ -31,15 +35,17 @@ def prompt_boolean(text, title="SHA2017", true_text="Yes", false_text="No", widt
31
35
try :
32
36
ugfx .input_init ()
33
37
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 )
36
40
37
41
window .show ()
42
+ ugfx .flush ()
38
43
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 )
43
49
44
50
finally :
45
51
window .hide ()
@@ -53,6 +59,7 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
53
59
54
60
Returns None if user aborts with button B
55
61
"""
62
+ global wait_for_interupt
56
63
57
64
window = ugfx .Container (int ((ugfx .width ()- width )/ 2 ), int ((ugfx .height ()- height )/ 2 ), width , height )
58
65
@@ -75,18 +82,18 @@ def prompt_text(description, init_text = "", true_text="OK", false_text="Back",
75
82
try :
76
83
ugfx .input_init ()
77
84
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 )
81
87
82
88
window .show ()
83
89
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 ()
90
97
91
98
finally :
92
99
window .hide ()
@@ -104,6 +111,8 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
104
111
If none_text is specified the user can use the B or Menu button to skip the selection
105
112
if title is specified a blue title will be displayed about the text
106
113
"""
114
+ global wait_for_interupt
115
+
107
116
ugfx .set_default_font ("Roboto_Regular12" )
108
117
window = ugfx .Container (5 , 5 , ugfx .width () - 10 , ugfx .height () - 10 )
109
118
window .show ()
@@ -136,12 +145,11 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
136
145
try :
137
146
ugfx .input_init ()
138
147
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
145
153
146
154
finally :
147
155
window .hide ()
@@ -153,10 +161,10 @@ def prompt_option(options, index=0, text = "Please select one of the following:"
153
161
154
162
class WaitingMessage :
155
163
"""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 " ):
157
165
self .window = ugfx .Container (30 , 30 , ugfx .width () - 60 , ugfx .height () - 60 )
158
166
self .window .show ()
159
- self .window .text (5 , 10 , title , TILDA_COLOR )
167
+ self .window .text (5 , 10 , title , ugfx . BLACK )
160
168
self .window .line (0 , 30 , ugfx .width () - 60 , 30 , ugfx .BLACK )
161
169
self .label = ugfx .Label (5 , 40 , self .window .width () - 10 , ugfx .height () - 40 , text = text , parent = self .window )
162
170
@@ -183,3 +191,6 @@ def __enter__(self):
183
191
184
192
def __exit__ (self , exc_type , exc_value , traceback ):
185
193
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