Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit f1a54b1

Browse files
authored
Merge pull request SHA2017-badge#120 from SHA2017-badge/badge-installer-categories
Installer rewrite w/ category support
2 parents 8227cf2 + 6ada0f3 commit f1a54b1

File tree

1 file changed

+135
-61
lines changed

1 file changed

+135
-61
lines changed

esp32/modules/installer.py

Lines changed: 135 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,87 +16,161 @@
1616

1717
timeout = 250
1818
while not wifi.sta_if.isconnected():
19-
time.sleep(0.1)
20-
timeout = timeout - 1
21-
if (timeout<1):
22-
ugfx.clear(ugfx.BLACK)
23-
ugfx.string(5,5,"Failure.","Roboto_BlackItalic24",ugfx.WHITE)
24-
ugfx.flush()
25-
time.sleep(2)
26-
appglue.start_app("")
27-
pass
19+
time.sleep(0.1)
20+
timeout = timeout - 1
21+
if (timeout<1):
22+
ugfx.clear(ugfx.BLACK)
23+
ugfx.string(5,5,"Failure.","Roboto_BlackItalic24",ugfx.WHITE)
24+
ugfx.flush()
25+
time.sleep(2)
26+
appglue.start_app("")
27+
pass
2828

2929
ugfx.clear(ugfx.WHITE)
30-
ugfx.string(180,25,"STILL","Roboto_BlackItalic24",ugfx.BLACK)
31-
ugfx.string(160,50,"Hacking","PermanentMarker22",ugfx.BLACK)
32-
str_len = ugfx.get_string_width("Hacking","PermanentMarker22")
33-
ugfx.line(160, 72, 174 + str_len, 72, ugfx.BLACK)
34-
ugfx.line(170 + str_len, 52, 170 + str_len, 70, ugfx.BLACK)
35-
ugfx.string(170,75,"Anyway","Roboto_BlackItalic24",ugfx.BLACK)
3630

3731
def show_description(active):
38-
if active:
39-
text.text(packages[options.selected_index()]["description"])
40-
ugfx.flush()
32+
if active:
33+
text.text(packages[options.selected_index()]["description"])
34+
ugfx.flush()
4135

42-
def woezel_it(active):
43-
if active:
44-
ugfx.clear(ugfx.BLACK)
45-
ugfx.string(40,25,"Installing:","Roboto_BlackItalic24",ugfx.WHITE)
46-
ugfx.string(100,75, packages[options.selected_index()]["name"],"PermanentMarker22",ugfx.WHITE)
47-
ugfx.flush()
48-
import woezel
49-
woezel.install(packages[options.selected_index()]["slug"])
50-
ugfx.clear(ugfx.BLACK)
51-
ugfx.string(40,25,"Installed:","Roboto_BlackItalic24",ugfx.WHITE)
52-
ugfx.string(100,75, packages[options.selected_index()]["name"],"PermanentMarker22",ugfx.WHITE)
53-
ugfx.flush()
54-
55-
def start_app(pushed):
56-
if(pushed):
57-
ugfx.clear(ugfx.BLACK)
58-
ugfx.string(40,25,"Running:","Roboto_BlackItalic24",ugfx.WHITE)
59-
ugfx.string(100,75, packages[options.selected_index()]["name"],"PermanentMarker22",ugfx.WHITE)
60-
ugfx.flush()
61-
selected = packages[options.selected_index()]["slug"]
62-
appglue.start_app(selected)
63-
64-
def start_launcher(pushed):
65-
if(pushed):
66-
appglue.start_app('launcher')
36+
def empty_options():
37+
global options
38+
options.destroy()
39+
options = ugfx.List(0,0,int(ugfx.width()/2),ugfx.height())
6740

6841
ugfx.input_init()
6942

7043
window = ugfx.Container(0, 0, ugfx.width(), ugfx.height())
7144

72-
ugfx.input_attach(ugfx.JOY_UP, show_description)
73-
ugfx.input_attach(ugfx.JOY_DOWN, show_description)
74-
75-
ugfx.input_attach(ugfx.BTN_A, woezel_it)
76-
ugfx.input_attach(ugfx.BTN_B, start_launcher)
77-
78-
ugfx.input_attach(ugfx.BTN_START, start_app)
45+
options = ugfx.List(0,0,int(ugfx.width()/2),ugfx.height())
7946

8047
text = ugfx.Textbox(int(ugfx.width()/2),0, int(ugfx.width()/2), ugfx.height())
48+
text.text("Downloading category list...")
8149

82-
ugfx.set_lut(ugfx.LUT_FULL)
83-
ugfx.flush()
50+
ugfx.flush(ugfx.LUT_FULL)
8451
badge.eink_busy_wait()
8552
ugfx.set_lut(ugfx.LUT_FASTER)
8653

54+
packages = {} # global variable
55+
8756
gc.collect()
8857

89-
f = requests.get("https://badge.sha2017.org/eggs/list/json")
58+
f = requests.get("https://badge.sha2017.org/eggs/categories/json")
9059
try:
91-
packages = f.json()
60+
categories = f.json()
9261
finally:
93-
f.close()
62+
f.close()
9463

9564
gc.collect()
9665

97-
options = ugfx.List(0,0,int(ugfx.width()/2),ugfx.height())
98-
99-
for package in packages:
100-
options.add_item("%s rev. %s"% (package["name"], package["revision"]))
101-
102-
show_description(True)
66+
def show_category(active):
67+
if active:
68+
ugfx.string_box(148,0,148,26, "Hatchery", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter)
69+
text.text("Install or update eggs from the hatchery here.\nSelect a category to start, or press B to return to the launcher.\n\nbadge.sha2017.org")
70+
ugfx.flush()
71+
72+
def list_categories():
73+
global options
74+
global text
75+
76+
empty_options()
77+
text.destroy()
78+
text = ugfx.Textbox(int(ugfx.width()/2),26,int(ugfx.width()/2),ugfx.height()-26)
79+
80+
ugfx.input_attach(ugfx.JOY_UP, show_category)
81+
ugfx.input_attach(ugfx.JOY_DOWN, show_category)
82+
ugfx.input_attach(ugfx.BTN_A, select_category)
83+
ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("launcher") if pushed else 0)
84+
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else 0)
85+
86+
for category in categories:
87+
options.add_item("%s (%d) >" % (category["name"], category["eggs"]))
88+
89+
show_category(True)
90+
91+
def select_category(active):
92+
if active:
93+
global categories
94+
index = options.selected_index()
95+
category = categories[index]["slug"]
96+
list_apps(category)
97+
98+
def list_apps(slug):
99+
global options
100+
global text
101+
global packages
102+
103+
ugfx.input_attach(ugfx.JOY_UP, 0)
104+
ugfx.input_attach(ugfx.JOY_DOWN, 0)
105+
ugfx.input_attach(ugfx.BTN_A, 0)
106+
ugfx.input_attach(ugfx.BTN_B, 0)
107+
ugfx.input_attach(ugfx.BTN_START, 0)
108+
109+
empty_options()
110+
text.destroy()
111+
text = ugfx.Textbox(int(ugfx.width()/2),0, int(ugfx.width()/2), ugfx.height())
112+
text.text("Downloading list of eggs...")
113+
ugfx.flush(ugfx.LUT_FULL)
114+
badge.eink_busy_wait()
115+
116+
gc.collect()
117+
f = requests.get("https://badge.sha2017.org/eggs/category/%s/json" % slug)
118+
try:
119+
packages = f.json()
120+
finally:
121+
f.close()
122+
123+
gc.collect()
124+
125+
for package in packages:
126+
options.add_item("%s rev. %s" % (package["name"], package["revision"]))
127+
128+
ugfx.input_attach(ugfx.JOY_UP, show_description)
129+
ugfx.input_attach(ugfx.JOY_DOWN, show_description)
130+
ugfx.input_attach(ugfx.BTN_A, install_app)
131+
ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("installer") if pushed else 0)
132+
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("installer") if pushed else 0)
133+
134+
show_description(True)
135+
badge.eink_busy_wait()
136+
ugfx.set_lut(ugfx.LUT_FASTER)
137+
138+
def install_app(active):
139+
if active:
140+
global options
141+
global text
142+
global packages
143+
144+
index = options.selected_index()
145+
146+
options.destroy()
147+
text.destroy()
148+
149+
ugfx.input_attach(ugfx.JOY_UP, 0)
150+
ugfx.input_attach(ugfx.JOY_DOWN, 0)
151+
ugfx.input_attach(ugfx.BTN_A, 0)
152+
ugfx.input_attach(ugfx.BTN_B, 0)
153+
ugfx.input_attach(ugfx.BTN_START, 0)
154+
155+
ugfx.clear(ugfx.BLACK)
156+
ugfx.string(40,25,"Installing:","Roboto_BlackItalic24",ugfx.WHITE)
157+
ugfx.string(100,55, packages[index]["name"],"PermanentMarker22",ugfx.WHITE)
158+
ugfx.flush()
159+
160+
import woezel
161+
woezel.install(packages[index]["slug"])
162+
163+
ugfx.clear(ugfx.WHITE)
164+
ugfx.string(40,25,"Installed:","Roboto_BlackItalic24",ugfx.BLACK)
165+
ugfx.string(100,55, packages[index]["name"],"PermanentMarker22",ugfx.BLACK)
166+
text = ugfx.Textbox(0,100, ugfx.width(), ugfx.height()-100)
167+
text.text("Press A to start %s, or B to return to the installer" % packages[index]["name"])
168+
169+
ugfx.input_attach(ugfx.BTN_A, lambda pushed: appglue.start_app(packages[index]["slug"]) if pushed else 0)
170+
ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("installer"))
171+
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app(""))
172+
173+
ugfx.flush()
174+
175+
176+
list_categories()

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