fix AttributeError with insertTextbox #10

Open
thp wants to merge 1 commit from thp/plakativ:insert_textbox into main
First-time contributor

Thanks for the useful tool! On Ubuntu 24.04 with Python 3.12, I'm getting the following error when trying to render a PDF (via pip install plakativ):

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.12/tkinter/__init__.py", line 1967, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "/home/thp/.local/lib/python3.12/site-packages/plakativ.py", line 1425, in on_save_button
    self.plakativ.render(
  File "/home/thp/.local/lib/python3.12/site-packages/plakativ.py", line 743, in render
    shape.insertTextbox(
    ^^^^^^^^^^^^^^^^^^^
AttributeError: 'Shape' object has no attribute 'insertTextbox'. Did you mean: 'insert_textbox'?
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.12/tkinter/__init__.py", line 1967, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "/home/thp/.local/lib/python3.12/site-packages/plakativ.py", line 1425, in on_save_button
    self.plakativ.render(
  File "/home/thp/.local/lib/python3.12/site-packages/plakativ.py", line 743, in render
    shape.insertTextbox(
    ^^^^^^^^^^^^^^^^^^^
AttributeError: 'Shape' object has no attribute 'insertTextbox'. Did you mean: 'insert_textbox'?

Changing the code to use insert_textbox() instead of insertTextbox() seems to fix the issue for me. I tried grep'ing around for insertTextbox() vs insert_textbox() in the cpython (tkinter) and tk (https://github.com/tcltk/tk) sources, but didn't find anything, so not sure when the change took place and if there is a need for special-casing this code to be compatible with older versions (of Python? of Tk?).

The Tk and Python 3 packages installed on my system:

% dpkg -l | egrep '^ii\s+tk|python3(\.12|-tk)'
ii  libpython3.12-dev:amd64                                     3.12.3-1ubuntu0.1                          amd64        Header files and a static library for Python (v3.12)
ii  libpython3.12-minimal:amd64                                 3.12.3-1ubuntu0.1                          amd64        Minimal subset of the Python language (version 3.12)
ii  libpython3.12-stdlib:amd64                                  3.12.3-1ubuntu0.1                          amd64        Interactive high-level object-oriented language (standard library, version 3.12)
ii  libpython3.12t64:amd64                                      3.12.3-1ubuntu0.1                          amd64        Shared Python runtime library (version 3.12)
ii  python3-tk:amd64                                            3.12.3-0ubuntu1                            amd64        Tkinter - Writing Tk applications with Python 3.x
ii  python3.12                                                  3.12.3-1ubuntu0.1                          amd64        Interactive high-level object-oriented language (version 3.12)
ii  python3.12-dev                                              3.12.3-1ubuntu0.1                          amd64        Header files and a static library for Python (v3.12)
ii  python3.12-doc                                              3.12.3-1ubuntu0.1                          all          Documentation for the high-level object-oriented language Python (v3.12)
ii  python3.12-minimal                                          3.12.3-1ubuntu0.1                          amd64        Minimal subset of the Python language (version 3.12)
ii  python3.12-venv                                             3.12.3-1ubuntu0.1                          amd64        Interactive high-level object-oriented language (pyvenv binary, version 3.12)
ii  tk                                                          8.6.14build1                               amd64        Toolkit for Tcl and X11 (default version) - windowing shell
ii  tk8.6                                                       8.6.14-1build1                             amd64        Tk toolkit for Tcl and X11 v8.6 - windowing shell
ii  tk8.6-blt2.5                                                2.5.3+dfsg-7build1                         amd64        graphics extension library for Tcl/Tk - library
Thanks for the useful tool! On Ubuntu 24.04 with Python 3.12, I'm getting the following error when trying to render a PDF (via `pip install plakativ`): ``` Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python3.12/tkinter/__init__.py", line 1967, in __call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "/home/thp/.local/lib/python3.12/site-packages/plakativ.py", line 1425, in on_save_button self.plakativ.render( File "/home/thp/.local/lib/python3.12/site-packages/plakativ.py", line 743, in render shape.insertTextbox( ^^^^^^^^^^^^^^^^^^^ AttributeError: 'Shape' object has no attribute 'insertTextbox'. Did you mean: 'insert_textbox'? Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python3.12/tkinter/__init__.py", line 1967, in __call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "/home/thp/.local/lib/python3.12/site-packages/plakativ.py", line 1425, in on_save_button self.plakativ.render( File "/home/thp/.local/lib/python3.12/site-packages/plakativ.py", line 743, in render shape.insertTextbox( ^^^^^^^^^^^^^^^^^^^ AttributeError: 'Shape' object has no attribute 'insertTextbox'. Did you mean: 'insert_textbox'? ``` Changing the code to use `insert_textbox()` instead of `insertTextbox()` seems to fix the issue for me. I tried grep'ing around for `insertTextbox()` vs `insert_textbox()` in the `cpython` (tkinter) and `tk` (https://github.com/tcltk/tk) sources, but didn't find anything, so not sure when the change took place and if there is a need for special-casing this code to be compatible with older versions (of Python? of Tk?). The Tk and Python 3 packages installed on my system: ``` % dpkg -l | egrep '^ii\s+tk|python3(\.12|-tk)' ii libpython3.12-dev:amd64 3.12.3-1ubuntu0.1 amd64 Header files and a static library for Python (v3.12) ii libpython3.12-minimal:amd64 3.12.3-1ubuntu0.1 amd64 Minimal subset of the Python language (version 3.12) ii libpython3.12-stdlib:amd64 3.12.3-1ubuntu0.1 amd64 Interactive high-level object-oriented language (standard library, version 3.12) ii libpython3.12t64:amd64 3.12.3-1ubuntu0.1 amd64 Shared Python runtime library (version 3.12) ii python3-tk:amd64 3.12.3-0ubuntu1 amd64 Tkinter - Writing Tk applications with Python 3.x ii python3.12 3.12.3-1ubuntu0.1 amd64 Interactive high-level object-oriented language (version 3.12) ii python3.12-dev 3.12.3-1ubuntu0.1 amd64 Header files and a static library for Python (v3.12) ii python3.12-doc 3.12.3-1ubuntu0.1 all Documentation for the high-level object-oriented language Python (v3.12) ii python3.12-minimal 3.12.3-1ubuntu0.1 amd64 Minimal subset of the Python language (version 3.12) ii python3.12-venv 3.12.3-1ubuntu0.1 amd64 Interactive high-level object-oriented language (pyvenv binary, version 3.12) ii tk 8.6.14build1 amd64 Toolkit for Tcl and X11 (default version) - windowing shell ii tk8.6 8.6.14-1build1 amd64 Tk toolkit for Tcl and X11 v8.6 - windowing shell ii tk8.6-blt2.5 2.5.3+dfsg-7build1 amd64 graphics extension library for Tcl/Tk - library ```
thp added 1 commit 2024-09-02 13:46:44 +00:00
Author
First-time contributor

For the record, this also happens with Plakativ installed via apt 0.5.2-1 from the Ubuntu 24.04 repos.

To reproduce, I needed to open a PDF, then tick the following "Output options":

  • Print layout cover page

And then hit "Save PDF".

For the record, this also happens with Plakativ installed via `apt` 0.5.2-1 from the Ubuntu 24.04 repos. To reproduce, I needed to open a PDF, then tick the following "Output options": * Print layout cover page And then hit "Save PDF".
Owner

Hi, thank you for your contribution. The pymupdf project is continuously breaking its api, converting functions from snake_case naming to CamelCase. Similar fixes have been performed in commits d6d0a6ea06 (in June 2022) or fab6925674 (in October 2023). Apparently, now is the turn of insertTextbox. Could you please change your MR so that it does something similar as the other commits I cited? I.e. that you write:

if hasattr(shape, "insert_textbox"):
    inserttextbox = shape.insert_textbox
else:
    inserttextbox = shape.insertTextbox

Thanks!

Hi, thank you for your contribution. The pymupdf project is continuously breaking its api, converting functions from `snake_case` naming to `CamelCase`. Similar fixes have been performed in commits d6d0a6ea061df482324ac1607df8c24c78f6aa74 (in June 2022) or fab69256741b1b025d305f536941e71e21b9f1e0 (in October 2023). Apparently, now is the turn of `insertTextbox`. Could you please change your MR so that it does something similar as the other commits I cited? I.e. that you write: ```python if hasattr(shape, "insert_textbox"): inserttextbox = shape.insert_textbox else: inserttextbox = shape.insertTextbox ``` Thanks!
First-time contributor

hasattr()-guarding all pymupdf CamelCase → sanke_case renamings sounds like a nightmare. I'd be prepared to bet this is not what upstream wanted, and they probably expect you to bump the pymupdf requirement instead.
As in josch/img2pdf#202 (comment), I respect your wish for backwards compatibility and agree this may be convenient for packagers / end users, but in the case of pymupdf you might be tilting at windmills...
Anyway, thanks a lot for this project and your commitment to OSS!

`hasattr()`-guarding all pymupdf CamelCase → sanke_case renamings sounds like a nightmare. I'd be prepared to bet this is not what upstream wanted, and they probably expect you to bump the pymupdf requirement instead. As in https://gitlab.mister-muffin.de/josch/img2pdf/pulls/202#issuecomment-2660, I respect your wish for backwards compatibility and agree this may be convenient for packagers / end users, but in the case of pymupdf you might be tilting at windmills... Anyway, thanks a lot for this project and your commitment to OSS!
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u insert_textbox:thp-insert_textbox
git checkout thp-insert_textbox

Merge

Merge the changes and update on Forgejo.
git checkout main
git merge --no-ff thp-insert_textbox
git checkout main
git merge --ff-only thp-insert_textbox
git checkout thp-insert_textbox
git rebase main
git checkout main
git merge --no-ff thp-insert_textbox
git checkout main
git merge --squash thp-insert_textbox
git checkout main
git merge --ff-only thp-insert_textbox
git checkout main
git merge thp-insert_textbox
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: josch/plakativ#10
No description provided.