misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
10a3500d27
commit
0b07bf3621
@ -1,21 +1,17 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
import argparse
|
import argparse
|
||||||
from http.server import HTTPServer
|
|
||||||
import shutil
|
|
||||||
import logging
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
sys.path.insert(0,
|
sys.path.insert(0,
|
||||||
os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||||
'../sdcard/rootfs/root/pwnagotchi/scripts/'))
|
'../pwnagotchi/'))
|
||||||
|
|
||||||
from pwnagotchi.ui.display import Display, VideoHandler
|
from pwnagotchi.ui.display import Display, VideoHandler
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
class CustomDisplay(Display):
|
class CustomDisplay(Display):
|
||||||
|
|
||||||
def __init__(self, config, state):
|
def __init__(self, config, state):
|
||||||
@ -41,6 +37,7 @@ class DummyPeer:
|
|||||||
def name():
|
def name():
|
||||||
return "beta"
|
return "beta"
|
||||||
|
|
||||||
|
|
||||||
def append_images(images, horizontal=True, xmargin=0, ymargin=0):
|
def append_images(images, horizontal=True, xmargin=0, ymargin=0):
|
||||||
w, h = zip(*(i.size for i in images))
|
w, h = zip(*(i.size for i in images))
|
||||||
|
|
||||||
@ -57,14 +54,15 @@ def append_images(images, horizontal=True, xmargin=0, ymargin=0):
|
|||||||
y_offset = 0
|
y_offset = 0
|
||||||
|
|
||||||
for im in images:
|
for im in images:
|
||||||
result.paste(im, (x_offset,y_offset))
|
result.paste(im, (x_offset, y_offset))
|
||||||
if horizontal:
|
if horizontal:
|
||||||
x_offset += im.size[0] + xmargin
|
x_offset += im.size[0] + xmargin
|
||||||
else:
|
else:
|
||||||
y_offset += im.size[1] + ymargin
|
y_offset += im.size[1] + ymargin
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="This program emulates\
|
parser = argparse.ArgumentParser(description="This program emulates\
|
||||||
the pwnagotchi display")
|
the pwnagotchi display")
|
||||||
@ -97,11 +95,10 @@ def main():
|
|||||||
list_of_displays = list()
|
list_of_displays = list()
|
||||||
for display_type in args.displays:
|
for display_type in args.displays:
|
||||||
config = yaml.safe_load(config_template.format(display=display_type,
|
config = yaml.safe_load(config_template.format(display=display_type,
|
||||||
lang=args.lang))
|
lang=args.lang))
|
||||||
display = CustomDisplay(config=config, state={'name': f"{display_type}>"})
|
display = CustomDisplay(config=config, state={'name': f"{display_type}>"})
|
||||||
list_of_displays.append(display)
|
list_of_displays.append(display)
|
||||||
|
|
||||||
|
|
||||||
columns = list()
|
columns = list()
|
||||||
|
|
||||||
for display in list_of_displays:
|
for display in list_of_displays:
|
||||||
@ -162,10 +159,10 @@ def main():
|
|||||||
# append them all together (vertical)
|
# append them all together (vertical)
|
||||||
columns.append(append_images(emotions, horizontal=False, xmargin=args.xmargin, ymargin=args.ymargin))
|
columns.append(append_images(emotions, horizontal=False, xmargin=args.xmargin, ymargin=args.ymargin))
|
||||||
|
|
||||||
|
|
||||||
# append columns side by side
|
# append columns side by side
|
||||||
final_image = append_images(columns, horizontal=True, xmargin=args.xmargin, ymargin=args.ymargin)
|
final_image = append_images(columns, horizontal=True, xmargin=args.xmargin, ymargin=args.ymargin)
|
||||||
final_image.save(args.output, 'PNG')
|
final_image.save(args.output, 'PNG')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
SystemExit(main())
|
SystemExit(main())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user