rm-hull / luma.examples

Companion repo for running examples against the luma.oled, luma.lcd, luma.led_matrix and luma.emulator display drivers.
MIT License
367 stars 140 forks source link

Fix deprecated Pillow Commands #158

Closed toldcodger closed 1 year ago

toldcodger commented 1 year ago

Hi, I am not a Python expert but I have tried to solve this myself (unsuccessfully) before contacting you. Several Luma LCD examples throw up errors about upcoming deprecated Pillow commands. The unaltered examples run successfully until I try to change the textsixe line as described below. Below is an example of one such error in font_awsome.py

I edited the script to work with an ST7735 and renamed the file to font_awesomeSPI.py to reflect this.

  w, h = draw.textsize(text=code, font=font)
/home/*****/luma.examples/examples/font_awesomeSPI.py:162: DeprecationWarning: textsize is deprecated and will be removed in Pillow 10 (2023-07-01). Use textbbox or textlength instead.
  w, h = draw.textsize(text=code, font=font)

If I swap textsize for textbbox I get the error below:

    w, h = draw.textbbox(text=code, font=font)
TypeError: textbbox() missing 1 required positional argument: 'xy'

If I swap textsize for textlength I get the error below:

    w, h = draw.textlength(text=code, font=font)
TypeError: cannot unpack non-iterable float object

any help would be gratefully appreciated

Regards

Dave

thijstriemstra commented 1 year ago

Several Luma LCD examples throw up errors about upcoming deprecated Pillow commands.

This is probably related to fact you're using an older version of luma.core and luma.lcd. Try upgrading them, e.g.

pip3 install -U luma.lcd
thijstriemstra commented 1 year ago

Ah, you're right, the examples still need to updated for the latest Pillow, e.g. https://github.com/rm-hull/luma.examples/search?q=textsize

Updating to latest luma.lcd is the first step though.

toldcodger commented 1 year ago

Hi Thijs,

Thanks for the info. If we are just waiting for an update, and you don’t need to keep it open for your own purposes, please feel free to close this.

Thanks again, it’s good to know I’m not going crazy 😂😂😂

Regards

Dave

Sent from my iPad

On 29 Nov 2022, at 15:16, Thijs Triemstra @.***> wrote:

 Ah nevermind, you're right, the examples still need to updated for the latest Pillow, e.g. https://github.com/rm-hull/luma.examples/search?q=textsize

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.