timothycrosley / streamdeck-ui

A Linux compatible UI for the Elgato Stream Deck.

Home Page:https://timothycrosley.github.io/streamdeck-ui/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pillow 10.0.0 removed calls that StreamDeck relies upon.

flajann2 opened this issue · comments

Describe the bug
https://pillow.readthedocs.io/en/stable/releasenotes/10.0.0.html#font-size-and-offset-methods

Because the various calls were deleted,

File "/home/eltoro/.local/lib/python3.11/site-packages/streamdeck_ui/display/text_filter.py", line 43, in initialize
label_w, _ = backdrop_draw.textsize(self.text, font=self.true_font)
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ImageDraw' object has no attribute 'textsize'

To Reproduce
Steps to reproduce the behavior:

  1. Install streamdeck_ui with Pillow 10.0.0
  2. Run streamdeck from command-line.
  3. See error

Expected behavior
Streamdeck comes up and works normally, recognizing the plugged in Streamdeck.

Screenshots
If applicable, add screenshots, pictures or video to help explain your problem.

Operating system (please complete the following information)
OS: Arch Linux x86_64
Host: NH50_70RA
Kernel: 6.4.2-arch1-1
Uptime: 17 hours, 50 mins
Packages: 1577 (pacman), 9 (flatpak)
Shell: fish 3.6.1
Resolution: 3840x2160
DE: Plasma 5.27.6
WM: KWin
Theme: [Plasma], Breeze [GTK2/3]
Icons: [Plasma], breeze-dark [GTK2/3]
Terminal: tmux
CPU: Intel i5-9300H (8) @ 4.100GHz
GPU: NVIDIA GeForce GTX 1650 Mobile / Max-Q
GPU: Intel CoffeeLake-H GT2 [UHD Graphics 630]
Memory: 11902MiB / 31938MiB

Stream Deck Version

  • Mini

Facing exactly the same issue.

This happened just after the Manjaro update of 2023-07-10 and was fully functional just before.

Error message

$ streamdeck 
Exception in thread Thread-1 (_run):
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.11/site-packages/streamdeck_ui/stream_deck_monitor.py", line 113, in _run
    self.attached(streamdeck_id, streamdeck)
  File "/usr/lib/python3.11/site-packages/streamdeck_ui/api.py", line 188, in attached
    self.update_streamdeck_filters(serial_number)
  File "/usr/lib/python3.11/site-packages/streamdeck_ui/api.py", line 479, in update_streamdeck_filters
    self.update_button_filters(serial_number, page, button)
  File "/usr/lib/python3.11/site-packages/streamdeck_ui/api.py", line 514, in update_button_filters
    display_handler.replace(page, button, filters)
  File "/usr/lib/python3.11/site-packages/streamdeck_ui/display/display_grid.py", line 79, in replace
    filter.initialize(self.size)
  File "/usr/lib/python3.11/site-packages/streamdeck_ui/display/text_filter.py", line 43, in initialize
    label_w, _ = backdrop_draw.textsize(self.text, font=self.true_font)
                 ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ImageDraw' object has no attribute 'textsize'

Config

OS: Manjaro Linux x86_64
Host: X570 AORUS ELITE -CF
Kernel: 6.4.2-3-MANJARO
Uptime: 29 secs
Packages: 2517 (pacman), 29 (flatpak)
Shell: bash 5.1.16
Resolution: 3440x1440, 1920x1080, 1920x1080
DE: Cinnamon 5.8.3
WM: Mutter (Muffin)
WM Theme: Colloid-Dark (Matcha-aliz)
Theme: adw-gtk3 [GTK2/3]
Icons: Papirus [GTK2/3]
Terminal: guake
CPU: AMD Ryzen 5 3600 (12) @ 3.600GHz
GPU: AMD ATI Radeon RX Vega 56/64
Memory: 2245MiB / 32041MiB

Python packages installed

It seems related to a deprecation in the newest version of Pillow (10), but here are the complete list of packages

Package                   Version
------------------------- ----------------------------------
airdrop-ng                1.1
airgraph-ng               1.1
ansible                   8.1.0
ansible-compat            4.1.2
ansible-core              2.15.1
ansible-lint              6.15.1.dev45
anytree                   2.8.0
apparmor                  3.1.6
appdirs                   1.4.4
application-utility       1.3.2
apsw                      3.42.0.0
argcomplete               2.0.0
async-timeout             4.0.2
attrs                     22.2.0
autocommand               2.2.2
Automat                   22.10.0
bcrypt                    4.0.1
beautifulsoup4            4.12.2
black                     23.3.0
borgbackup                1.2.4
bracex                    2.3
Brotli                    1.0.9
brotlicffi                1.0.9.2
bs4                       0.0.1
btrfsutil                 6.3.2
build                     0.10.0
CacheControl              0.13.1
cachy                     0.3.0
cairocffi                 1.5.0
CairoSVG                  2.7.0
certifi                   2023.5.7
cffi                      1.15.1
chardet                   5.1.0
cleo                      2.0.1
click                     8.1.4
colorama                  0.4.6
commonmark                0.9.1
configobj                 5.0.8
constantly                15.1.0
contourpy                 1.1.0
crashtest                 0.4.1
crit                      3.18
cryptography              41.0.1
css-parser                1.0.9
cssselect                 1.2.0
cssselect2                0.7.0
cupshelpers               1.0
cycler                    0.11.0
Cython                    0.29.36
dbus-python               1.3.2
defusedxml                0.7.1
deluge                    2.1.1
discid                    1.2.0
distlib                   0.3.6
distro                    1.8.0
dnspython                 2.3.0
docopt                    0.6.2
docutils                  0.20.1
dulwich                   0.21.5
enrich                    1.2.8.dev0
evdev                     1.6.1
ewmh                      0.1.6
exceptiongroup            1.1.2
fail2ban                  1.0.2
fasteners                 0.18
fastjsonschema            2.17.1
faust-cchardet            2.1.18
feedparser                6.0.10
filelock                  3.12.0
filetype                  1.2.0
Flask                     2.2.5
fonttools                 4.40.0
future                    0.18.3
gallery-dl                1.25.7
GeoIP                     1.3.2
gitdb                     4.0.10
GitPython                 3.1.30
gpg                       1.20.0
grpcio                    1.55.1
grpcio-tools              1.55.1
guake                     3.11.dev0
gufw                      22.4.0
hidapi                    0.14.0
html2text                 2020.1.16
html5-parser              0.4.11
html5lib                  1.1
httplib2                  0.22.0
hyperlink                 21.0.0
hypothesis                6.75.3
idna                      3.4
ifaddr                    0.2.0
impacket                  0.9.24
importlib-metadata        5.0.0
incremental               22.10.0
indicator-sound-switcher  2.3.9
inflate64                 0.3.1
inflect                   6.1.0
iniconfig                 2.0.0
installer                 0.7.0
iotop                     0.6
itsdangerous              2.1.2
jaraco.classes            3.2.3
jaraco.context            4.3.0
jaraco.functools          3.8.0
jaraco.text               3.11.1
jarowinkler               1.2.3
jeepney                   0.8.0
Jinja2                    3.1.2
jsonschema                4.18.0
jsonschema-specifications 2023.6.1
keyring                   23.13.1
keyutils                  0.6
kiwisolver                1.4.4
lark                      1.1.5
ldap3                     2.9
lensfun                   0.3.3
Levenshtein               0.21.0
LibAppArmor               3.1.6
libtorrent                2.0.9
lit                       15.0.7.dev0
llfuse                    1.4.2
lockfile                  0.12.2
louis                     3.26.0
lxml                      4.9.2
Mako                      1.2.4
manjaro-sdk               0.1
Markdown                  3.4.3
markdown-it-py            2.2.0
MarkupSafe                2.1.3
matplotlib                3.7.1
mdurl                     0.1.2
mechanize                 0.4.8
meson                     1.1.1
minigalaxy                1.2.2
moddb                     0.8.1
more-itertools            9.1.0
msgpack                   1.0.5
mugshot                   0.4.3
multivolumefile           0.2.3
mutagen                   1.46.0
mypy-extensions           1.0.0
natsort                   8.4.0
netifaces                 0.11.0
netsnmp-python            1.0a1
nftables                  0.1
notify2                   0.3.1
npyscreen                 4.10.5
numpy                     1.25.0
openshot-qt               3.1.1
opensnitch-ui             1.6.0
ordered-set               4.1.0
packaging                 23.1
pacman-mirrors            4.23.2
paramiko                  2.11.1
pathspec                  0.11.1
pbr                       5.11.1
pcapy-ng                  1.0.5
pdftotext                 2.2.2
peewee                    3.16.2
pexpect                   4.8.0
picard                    2.8.5
Pillow                    10.0.0
pip                       23.1.2
pip-autoremove            0.10.0
pipdeptree                2.7.1
pipenv                    2023.6.18
pipx                      1.2.0
Pivy                      0.6.8
pkginfo                   1.9.6
platformdirs              3.5.1
pluggy                    1.0.0
ply                       3.11
poetry                    1.5.1
poetry-core               1.6.1
poetry-plugin-export      1.3.0
pooch                     1.7.0
protobuf                  4.23.4
psutil                    5.9.5
ptyprocess                0.7.0
pulsectl                  23.5.2
pwquality                 1.4.5
py7zr                     0.20.5
pyaml                     23.5.9
pyasn1                    0.4.8
pyasn1-modules            0.2.8
pybcj                     1.0.1
pybind11                  2.10.4
pycairo                   1.23.0
pychm                     0.8.6
pycparser                 2.21
pycryptodome              3.18.0
pycryptodomex             3.12.0
pycups                    2.0.1
pycurl                    7.45.2
pydantic                  1.10.9
Pygments                  2.15.1
PyGObject                 3.44.1
pyinotify                 0.9.6
PyJWT                     2.7.0
PyMuPDF                   1.22.5
PyNaCl                    1.4.0
pynput                    1.7.6
PyOpenGL                  3.1.6
pyOpenSSL                 23.2.0
pyparsing                 3.0.9
pyppmd                    1.0.0
pyproject_hooks           1.0.0
PyQt5                     5.15.9
PyQt5-sip                 12.12.1
PyQt6                     6.5.1
PyQt6-sip                 13.5.1
PyQt6-WebEngine           6.5.0
PyQtWebEngine             5.15.6
pyrate-limiter            2.10.0
pyrsistent                0.19.3
PySide2                   5.15.10
PySide6                   6.5.1.1
pysmbc                    1.0.25.1
PySocks                   1.7.1
pytest                    7.4.0
python-dateutil           2.8.2
python-distutils-extra    2.39
python-pam                2.0.2
python-slugify            8.0.1
python-xlib               0.33
pytz                      2023.3
pyxdg                     0.28
PyYAML                    6.0
pyzmq                     25.1.0
pyzstd                    0.15.7
qrtools                   2.1
quodlibet                 4.5.0
rapidfuzz                 3.1.1
rapidfuzz-capi            1.0.5
referencing               0.29.1
regex                     2023.6.3
rencode                   1.0.6
reportlab                 3.6.12
requests                  2.28.2
requests-toolbelt         1.0.0
resolvelib                1.0.1
rich                      13.4.2
rpds-py                   0.8.8
rpm                       4.18.1
ruamel.yaml               0.17.22
ruamel.yaml.clib          0.2.7
s-tui                     1.1.4
scikit-build              0.17.1
scipy                     1.11.1
screeninfo                0.8.1
SecretStorage             3.3.3
service-identity          23.1.0
setproctitle              1.3.2
setuptools                68.0.0
sgmllib3k                 1.0.0
shellingham               1.5.0.post1
shiboken2                 5.15.10
shiboken6                 6.5.1.1
shiboken6-generator       6.5.1.1
simplejson                3.19.1
six                       1.16.0
smbus                     1.1
smmap                     5.0.0
sortedcontainers          2.4.0
soundconverter            4.0.3
soupsieve                 2.4.1
streamdeck                0.9.3
streamdeck-ui             2.0.15
subprocess-tee            0.4.1
svglib                    1.5.1
syncthing-gtk             0.9.4.5
systemd-python            235
TBB                       0.2
termcolor                 2.3.0
terminator                2.1.3
text-unidecode            1.3
texttable                 1.6.7
tinycss2                  1.2.1
tomli                     2.0.1
tomlkit                   0.11.8
toolz                     0.12.0
torbrowser-launcher       0.3.6
tqdm                      4.65.0
trove-classifiers         2023.7.8
Twisted                   22.10.0
typer                     0.9.0
typing_extensions         4.7.0
uc-micro-py               1.0.2
udiskie                   2.4.2
ufw                       0.36.2
ulauncher                 5.15.2
unrardll                  0.1.7
urllib3                   1.26.15
urwid                     2.1.3.dev0
userpath                  1.8.0
validate                  5.0.8
validate-pyproject        0.13.post1.dev0+gb752273.d20230520
vidcutter                 6.0.5.1
virtualenv                20.21.0
virtualenv-clone          0.5.7
vorta                     0.8.12
Wand                      0.6.11
wcmatch                   8.4.1
wcwidth                   0.2.6
webencodings              0.5.1
websocket-client          1.6.1
Werkzeug                  2.3.2
wheel                     0.40.0
wxPython                  4.2.0
xcffib                    1.2.0
xmltodict                 0.13.0
yamllint                  1.32.0
yapf                      0.33.0
youtube-dl                2021.12.17
yq                        3.2.2
zeroconf                  0.63.0
zipp                      3.15.0
zope.interface            6.0

I can't understand what gap is calculating, but for the rest, I would suggest using the new text anchors to align text in https://github.com/timothycrosley/streamdeck-ui/blob/9b9c2699be6d478717ef153628dafba5242a114b/streamdeck_ui/display/text_filter.py:

     def initialize(self, size: Tuple[int, int]):
         self.image = Image.new("RGBA", size)
         backdrop_draw = ImageDraw.Draw(self.image)
 
-        # Calculate the height and width of the text we're drawing, using the font itself
-        label_w, _ = backdrop_draw.textsize(self.text, font=self.true_font)
 
-        # Calculate dimensions for text that include ascender (above the line)
-        # and below the line  (descender) characters. This is used to adust the
-        # font placement and should allow for button text to horizontally align
-        # across buttons. Basically we want to figure out what is the tallest
-        # text we will need to draw.
-        _, label_h = backdrop_draw.textsize("lLpgyL|", font=self.true_font)
 
-        gap = (size[1] - 5 * label_h) // 4
 
         if self.vertical_align == "top":
             label_y = 0
+            anchor = "ma"
         elif self.vertical_align == "middle-top":
-            label_y = gap + label_h
+            # ???
         elif self.vertical_align == "middle":
-            label_y = size[1] // 2 - (label_h // 2)
+            label_y = size[1] // 2
+            anchor = "mm"
         elif self.vertical_align == "middle-bottom":
-            label_y = (gap + label_h) * 3
+            # ???
         else:
-            label_y = size[1] - label_h
-            # Default or "bottom"
+            label_y = size[1]
+            anchor = "md"
 

-        label_pos = ((size[0] - label_w) // 2, label_y)
+        label_pos = (size[0] // 2, label_y)
 
-        backdrop_draw.text(label_pos, text=self.text, font=self.true_font, fill="black")
+        backdrop_draw.text(label_pos, text=self.text, font=self.true_font, fill="black", anchor=anchor)
         self.image = self.image.filter(TextFilter.font_blur)
 
         foreground_draw = ImageDraw.Draw(self.image)
-        foreground_draw.text(label_pos, text=self.text, font=self.true_font, fill="white")
+        foreground_draw.text(label_pos, text=self.text, font=self.true_font, fill="white", anchor=anchor)

I added a quick fix, if you want to give it a try. #354 @flajann2 @nulano @shakasan @abcminiuser @lhayhurst

hi, this project seems to be stale and a new fork as been made with the intention of replacing this one.

if this still an issue please reopen it at: https://github.com/streamdeck-linux-gui/streamdeck-linux-gui