Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ui.faces.scale = # to png faces #306

Open
wants to merge 3 commits into
base: noai
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pwnagotchi/defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ ui.faces.upload = "(1__0)"
ui.faces.upload1 = "(1__1)"
ui.faces.upload2 = "(0__1)"
ui.faces.png = false
ui.faces.scale = 1
ui.faces.position_x = 0
ui.faces.position_y = 34

Expand Down
27 changes: 21 additions & 6 deletions pwnagotchi/ui/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ def draw(self, canvas, drawer):


class Text(Widget):
def __init__(self, value="", position=(0, 0), font=None, color=0, wrap=False, max_length=0, png=False):
def __init__(self, value="", position=(0, 0), font=None, color=0, wrap=False, max_length=0, png=False, scale=1):
super().__init__(position, color)
self.value = value
self.font = font
self.wrap = wrap
self.max_length = max_length
self.wrapper = TextWrapper(width=self.max_length, replace_whitespace=False) if wrap else None
self.png = png
self.scale = scale

def draw(self, canvas, drawer):
if self.value is not None:
Expand All @@ -67,16 +68,30 @@ def draw(self, canvas, drawer):
self.pixels = self.image.load()
for y in range(self.image.size[1]):
for x in range(self.image.size[0]):
if self.pixels[x,y][3] < 255: # check alpha
self.pixels[x,y] = (255, 255, 255, 255)
if self.pixels[x, y][3] < 255:
self.pixels[x, y] = (255, 255, 255, 255)
if self.color == 255:
self._image = ImageOps.colorize(self.image.convert('L'), black = "white", white = "black")
self._image = ImageOps.colorize(self.image.convert('L'), black="white", white="black")
else:
self._image = self.image
self.image = self._image.convert('1')
if self.scale != 1:
width, height = self._image.size
new_width = int(width * self.scale)
new_height = int(height * self.scale)
scaled_image = Image.new('RGBA', (new_width, new_height))
original_pixels = self._image.load()
scaled_pixels = scaled_image.load()
for y in range(new_height):
for x in range(new_width):
original_x = x // self.scale
original_y = y // self.scale
scaled_pixels[x, y] = original_pixels[original_x, original_y]
self.image = scaled_image
else:
self.image = self._image
self.image = self.image.convert('1')
canvas.paste(self.image, self.xy)


class LabeledValue(Widget):
def __init__(self, label, value="", position=(0, 0), label_font=None, text_font=None, color=0, label_spacing=5):
super().__init__(position, color)
Expand Down
1 change: 1 addition & 0 deletions pwnagotchi/ui/faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
UPLOAD = '(1__0)'
UPLOAD1 = '(1__1)'
UPLOAD2 = '(0__1)'
SCALE = 1
PNG = False
POSITION_X = 0
POSITION_Y = 40
Expand Down
7 changes: 5 additions & 2 deletions pwnagotchi/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ def __init__(self, config, impl, state=None):
'line2': Line(self._layout['line2'], color=BLACK),

'face': Text(value=faces.SLEEP,
position=(config['ui']['faces']['position_x'], config['ui']['faces']['position_y']),
color=BLACK, font=fonts.Huge, png=config['ui']['faces']['png']),
position=(config['ui']['faces']['position_x'], config['ui']['faces']['position_y']),
color=BLACK, font=fonts.Huge,
png=config['ui']['faces']['png'],
scale = config['ui']['faces'].get('scale', 1)
),

# 'friend_face': Text(value=None, position=self._layout['friend_face'], font=fonts.Bold, color=BLACK),
'friend_name': Text(value=None, position=self._layout['friend_face'], font=fonts.BoldSmall, color=BLACK),
Expand Down