-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocumentation.py
More file actions
99 lines (80 loc) · 3.32 KB
/
documentation.py
File metadata and controls
99 lines (80 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
from typing import Callable, Collection
from injector import Injector, provider, singleton
from PIL import Image
from PIL.ImageFilter import GaussianBlur
from app.App import App
from app.ClockApp import ClockApp
from app.DebugApp import DebugApp
from app.EnvironmentApp import EnvironmentApp
from app.FileManagerApp import FileManagerApp
from app.MapApp import MapApp
from app.RadioApp import RadioApp
from app.UpdateApp import UpdateApp
from core.decorator import override
from environment import Environment
from piboy import AppModule, AppState, draw_base
target = './docs/apps'
class DefaultEnvironmentAppModule(AppModule):
@singleton
@provider
@override
def provide_environment(self) -> Environment:
# make sure we have a default environment that is not loaded from file
return Environment()
@singleton
@provider
@override
def provide_draw_callback(self, state: AppState) -> Callable[[bool], None]:
# empty draw callback because it is not needed, and it also avoids that the display module is requested
return lambda partial: None
def blur(image: Image.Image, bbox: tuple[int, int, int, int]) -> Image.Image:
"""Blurs the given area"""
patch = image.crop(bbox)
patch = patch.filter(GaussianBlur(radius=4))
image.paste(patch, bbox)
return image
def main():
module = DefaultEnvironmentAppModule()
injector = Injector([module])
app_state = injector.get(AppState)
app_state.add_app(injector.get(FileManagerApp)) \
.add_app(injector.get(UpdateApp)) \
.add_app(injector.get(EnvironmentApp)) \
.add_app(injector.get(RadioApp)) \
.add_app(injector.get(DebugApp)) \
.add_app(injector.get(ClockApp)) \
.add_app(injector.get(MapApp))
app_state.active_app.on_app_enter()
app_bbox = (app_state.environment.app_config.app_side_offset,
app_state.environment.app_config.app_top_offset,
app_state.environment.app_config.width - app_state.environment.app_config.app_side_offset,
app_state.environment.app_config.height - app_state.environment.app_config.app_bottom_offset)
x_offset, y_offset = app_bbox[0:2]
# actions to perform on the app before drawing it
pre_steps: dict[str, Collection[Callable[[App], None]]] = {
'MAP': [lambda a: a.on_key_a() for _ in range(12)]
}
# actions to perform on the image after it was drawn
post_steps: dict[str, Collection[Callable[[Image.Image], Image]]] = {
'MAP': [lambda i: blur(i, (340, 30, 460, 90))]
}
for app in app_state.apps:
app.on_app_enter()
image = app_state.clear_buffer()
for patch, x0, y0 in draw_base(image, app_state):
image.paste(patch, (x0, y0))
if app.title in pre_steps:
for action in pre_steps[app.title]:
action(app)
for patch, x0, y0 in app.draw(app_state.image_buffer.crop(app_bbox), False):
image.paste(patch, (x0 + x_offset, y0 + y_offset))
if app.title in post_steps:
for action in post_steps[app.title]:
image = action(image)
image.save(os.path.join(target, f'{app.title.lower()}.png'))
print(f'drawn and saved {app.title} app')
app.on_app_leave()
app_state.next_app()
if __name__ == '__main__':
main()