adamviola / textual-imageview

A simple terminal-based image viewer.
MIT License
76 stars 3 forks source link

When the image is changed, the widget is not redrawn #4

Open rhuygen opened 2 months ago

rhuygen commented 2 months ago

I created a simple class that extends from ImageViewer and when I update this loading a new Image, the widget is not redrawn.

class ImageWidget(ImageViewer):

    def __init__(self, image: Image.Image | None, id=None):
        if image is None:
            image = Image.new('L', (2295, 4540), 0)
        super().__init__(image)
        self.id = id

    def update(self, image: Image.Image):
        self.image = ImageView(image)
        self.refresh()

The solution that I found is to set the container coordinates and use on_show() instead of refresh():

class ImageWidget(ImageViewer):

    def __init__(self, image: Image.Image | None, id=None):
        if image is None:
            image = Image.new('L', (2295, 4540), 0)
        super().__init__(image)
        self.id = id

    def update(self, image: Image.Image):
        self.image = ImageView(image)
        self.image.set_container_size(*self.container_size)
        self.on_show()