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

Commit c3073e6

Browse files
author
Niek Blankers
committed
Installer rewrite w/ category support
1 parent 9b1f023 commit c3073e6

File tree

1 file changed

+135
-59
lines changed

1 file changed

+135
-59
lines changed

esp32/modules/installer.py

Lines changed: 135 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,87 +16,163 @@
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

8250
ugfx.set_lut(ugfx.LUT_FULL)
8351
ugfx.flush()
8452
badge.eink_busy_wait()
8553
ugfx.set_lut(ugfx.LUT_FASTER)
8654

55+
packages = {} # global variable
56+
8757
gc.collect()
8858

89-
f = requests.get("https://badge.sha2017.org/eggs/list/json")
59+
f = requests.get("https://badge.sha2017.org/eggs/categories/json")
9060
try:
91-
packages = f.json()
61+
categories = f.json()
9262
finally:
93-
f.close()
63+
f.close()
9464

9565
gc.collect()
9666

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