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

[Bug]: #344

Open
1 task done
SpotlightForBugs opened this issue Feb 19, 2025 · 1 comment
Open
1 task done

[Bug]: #344

SpotlightForBugs opened this issue Feb 19, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@SpotlightForBugs
Copy link

SpotlightForBugs commented Feb 19, 2025

Contact Details

@SpotlightForBugs

What happened?

I am not sure, but there is a tuple coming from somewhere.
I have created a fix that makes it work.

I am currently investigating this fix:

from PIL import Image, ImageOps
from textwrap import TextWrapper


class Widget(object):
    def __init__(self, xy, color=0):
        self.xy = xy
        self.color = color

    def draw(self, canvas, drawer):
        raise Exception("not implemented")


# canvas.paste: https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.paste
# takes mask variable, to identify color system. (not used for pwnagotchi yet)
# Pwn should use "1" since its mainly black or white displays.
class Bitmap(Widget):
    def __init__(self, path, xy, color=0):
        super().__init__(xy, color)
        self.image = Image.open(path)

    def draw(self, canvas, drawer):
        if self.color == 0xFF:
            self.image = ImageOps.invert(self.image)
        canvas.paste(self.image, self.xy)


class Line(Widget):
    def __init__(self, xy, color=0, width=1):
        super().__init__(xy, color)
        self.width = width

    def draw(self, canvas, drawer):
        drawer.line(self.xy, fill=self.color, width=self.width)


class Rect(Widget):
    def draw(self, canvas, drawer):
        drawer.rectangle(self.xy, outline=self.color)


class FilledRect(Widget):
    def draw(self, canvas, drawer):
        drawer.rectangle(self.xy, fill=self.color)


class Text(Widget):
    def __init__(self, value="", position=(0, 0), font=None, color=0, wrap=False, max_length=0, png=False):
        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

    def draw(self, canvas, drawer):
        if self.value is not None:
            if not self.png:
                if self.wrap:
                    text = '\n'.join(self.wrapper.wrap(str(self.value)))  # Ensure value is a string
                else:
                    text = str(self.value)  # Ensure value is a string
                drawer.text(self.xy, text, font=self.font, fill=self.color)
            else:
                self.image = Image.open(self.value)
                self.image = self.image.convert('RGBA')
                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.color == 255:
                    self._image = ImageOps.colorize(self.image.convert('L'), black = "white", white = "black")
                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)
        self.label = label
        self.value = value
        self.label_font = label_font
        self.text_font = text_font
        self.label_spacing = label_spacing

    def draw(self, canvas, drawer):
        if self.label is None:
            drawer.text(self.xy, self.value, font=self.label_font, fill=self.color)
        else:
            pos = self.xy
            drawer.text(pos, self.label, font=self.label_font, fill=self.color)
            drawer.text((pos[0] + self.label_spacing + 5 * len(self.label), pos[1]), self.value, font=self.text_font, fill=self.color)

Version

2.9.5.2

3rd Party Hardware

No

Relevant log output

Traceback (most recent call last):
  File "/usr/bin/pwnagotchi", line 8, in <module>
    sys.exit(pwnagotchi_cli())
             ^^^^^^^^^^^^^^^^
  File "/home/pi/.pwn/lib/python3.11/site-packages/pwnagotchi/cli.py", line 339, in pwnagotchi_cli
    do_auto_mode(agent)
[2025-02-19 23:13:37,886] [DEBUG] [UI Handler] : ohcapi on_ui_update
  File "/home/pi/.pwn/lib/python3.11/site-packages/pwnagotchi/cli.py", line 51, in do_auto_mode
[2025-02-19 23:13:37,914] [DEBUG] [UI Handler] : fix_services on_ui_update
[2025-02-19 23:13:37,922] [DEBUG] [Thread-5] : fix_services.ui_update: (<pwnagotchi.ui.display.Display object at 0xaeb207f0>,)
    agent.last_session.parse(agent.view(), args.skip_session)  # show stats in AUTO
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/.pwn/lib/python3.11/site-packages/pwnagotchi/log.py", line 202, in parse
[2025-02-19 23:13:37,933] [DEBUG] [UI Handler] : wpa-sec on_ui_update
[2025-02-19 23:13:37,956] [DEBUG] [UI Handler] : bt-tether on_ui_update
[2025-02-19 23:13:37,946] [DEBUG] [Thread-8] : wpa-sec.ui_update: (<pwnagotchi.ui.display.Display object at 0xaeb207f0>,)
    ui.on_reading_logs()
  File "/home/pi/.pwn/lib/python3.11/site-packages/pwnagotchi/ui/view.py", line 258, in on_reading_logs
    self.update()
  File "/home/pi/.pwn/lib/python3.11/site-packages/pwnagotchi/ui/view.py", line 397, in update
    lv.draw(self._canvas, drawer)
  File "/home/pi/.pwn/lib/python3.11/site-packages/pwnagotchi/ui/components.py", line 60, in draw
    text = '\n'.join(self.wrapper.wrap(self.value))
[2025-02-19 23:13:38,047] [DEBUG] [Renderer] : Horizontal
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/textwrap.py", line 356, in wrap
    chunks = self._split_chunks(text)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/textwrap.py", line 342, in _split_chunks
    text = self._munge_whitespace(text)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/textwrap.py", line 151, in _munge_whitespace
    text = text.expandtabs(self.tabsize)
           ^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'expandtabs'
[2025-02-19 23:13:38,254] [DEBUG] [Thread-11] : bt-tether.ui_update: (<pwnagotchi.ui.display.Display object at 0xaeb207f0>,)
[2025-02-19 23:13:38,281] [WARNING] [UI Handler] : non fatal error while updating view: 'tuple' object has no attribute 'expandtabs'
pi@PwnyZ0:~ $

Code of Conduct

  • I agree to follow this project's Code of Conduct
@SpotlightForBugs SpotlightForBugs added the bug Something isn't working label Feb 19, 2025
@SpotlightForBugs

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants