|
16 | 16 |
|
17 | 17 | timeout = 250
|
18 | 18 | 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 |
28 | 28 |
|
29 | 29 | 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) |
36 | 30 |
|
37 | 31 | 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() |
41 | 35 |
|
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()) |
67 | 40 |
|
68 | 41 | ugfx.input_init()
|
69 | 42 |
|
70 | 43 | window = ugfx.Container(0, 0, ugfx.width(), ugfx.height())
|
71 | 44 |
|
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()) |
79 | 46 |
|
80 | 47 | text = ugfx.Textbox(int(ugfx.width()/2),0, int(ugfx.width()/2), ugfx.height())
|
| 48 | +text.text("Downloading category list...") |
81 | 49 |
|
82 |
| -ugfx.set_lut(ugfx.LUT_FULL) |
83 |
| -ugfx.flush() |
| 50 | +ugfx.flush(ugfx.LUT_FULL) |
84 | 51 | badge.eink_busy_wait()
|
85 | 52 | ugfx.set_lut(ugfx.LUT_FASTER)
|
86 | 53 |
|
| 54 | +packages = {} # global variable |
| 55 | + |
87 | 56 | gc.collect()
|
88 | 57 |
|
89 |
| -f = requests.get("https://badge.sha2017.org/eggs/list/json") |
| 58 | +f = requests.get("https://badge.sha2017.org/eggs/categories/json") |
90 | 59 | try:
|
91 |
| - packages = f.json() |
| 60 | + categories = f.json() |
92 | 61 | finally:
|
93 |
| - f.close() |
| 62 | + f.close() |
94 | 63 |
|
95 | 64 | gc.collect()
|
96 | 65 |
|
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