Error on saving PDF: AttributeError: 'Shape' object has no attribute 'drawRect' #6

Closed
opened 6 months ago by akorune · 6 comments

I installed plakativ (version 0.5.1) with pipx (tried python 3.8.18 and python 3.11.5 same result). The GUI works as expected, I can select the page format, and the output format.

If I select "print cutting guide", upon saving the PDF (with a different) name, nothing happen. Looking at the terminal from which I started the program, I can see the following error message:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/home/sylvain/.pyenv/versions/3.8.18/lib/python3.8/tkinter/__init__.py", line 1892, in __call__
    return self.func(*args)
  File "/home/sylvain/.local/pipx/venvs/plakativ/lib/python3.8/site-packages/plakativ.py", line 1404, in on_save_button
    self.plakativ.render(
  File "/home/sylvain/.local/pipx/venvs/plakativ/lib/python3.8/site-packages/plakativ.py", line 817, in render
    shape.drawRect(
AttributeError: 'Shape' object has no attribute 'drawRect'

If the "print cutting guide" option is not selected, saving the file works as expected.

I installed plakativ (version 0.5.1) with pipx (tried python 3.8.18 and python 3.11.5 same result). The GUI works as expected, I can select the page format, and the output format. If I select "print cutting guide", upon saving the PDF (with a different) name, nothing happen. Looking at the terminal from which I started the program, I can see the following error message: ``` Exception in Tkinter callback Traceback (most recent call last): File "/home/sylvain/.pyenv/versions/3.8.18/lib/python3.8/tkinter/__init__.py", line 1892, in __call__ return self.func(*args) File "/home/sylvain/.local/pipx/venvs/plakativ/lib/python3.8/site-packages/plakativ.py", line 1404, in on_save_button self.plakativ.render( File "/home/sylvain/.local/pipx/venvs/plakativ/lib/python3.8/site-packages/plakativ.py", line 817, in render shape.drawRect( AttributeError: 'Shape' object has no attribute 'drawRect' ``` If the "print cutting guide" option is not selected, saving the file works as expected.
josch commented 6 months ago
Owner

This is probably related to your version of pymupdf. Which version are you using?

This is probably related to your version of pymupdf. Which version are you using?
Poster

I am using Manjaro. The "python-pymupdf" package (version 1.23.5) is available in the repository but is not currently installed on my machine.

The library was not installed either in the python environment when I installed plakativ with pipx. I manually installed pymupdf (1.23.5) using pip in the environment created by pipx, but it does not seems to change anything, the same error message and the file is not saved.

I am using Manjaro. The "python-pymupdf" package (version 1.23.5) is available in the repository but is not currently installed on my machine. The library was not installed either in the python environment when I installed plakativ with pipx. I manually installed pymupdf (1.23.5) using pip in the environment created by pipx, but it does not seems to change anything, the same error message and the file is not saved.
josch commented 6 months ago
Owner

Yes, that's because I never tried plakativ with pymupdf 1.23.5. It works fine with 1.21.1 so the interface changed between these two versions. Would you like to try a patch and see if that fixes things for you?

Yes, that's because I never tried plakativ with pymupdf 1.23.5. It works fine with 1.21.1 so the interface changed between these two versions. Would you like to try a patch and see if that fixes things for you?
Poster

Sure

Sure
josch commented 6 months ago
Owner

Does this fix things for you?

diff --git a/plakativ.py b/plakativ.py
index 81e7add..a2f0109 100755
--- a/plakativ.py
+++ b/plakativ.py
@@ -712,7 +712,11 @@ class Plakativ:
                     shape = page.new_shape()
                 else:
                     shape = page.newShape()
-                shape.drawRect(
+                if hasattr(shape, "draw_rect"):
+                    dr = shape.draw_rect
+                else:
+                    dr = shape.drawRect
+                dr(
                     fitz.Rect(
                         x0,
                         y0,
@@ -722,7 +726,7 @@ class Plakativ:
                 )
                 shape.finish(color=(0, 0, 1))
                 # outer rectangle
-                shape.drawRect(
+                dr(
                     fitz.Rect(
                         x0 - left,
                         y0 - top,
@@ -816,9 +820,13 @@ class Plakativ:
                 shape = page.new_shape()
             else:
                 shape = page.newShape()
+            if hasattr(shape, "draw_rect"):
+                dr = shape.draw_rect
+            else:
+                dr = shape.drawRect
             if guides:
                 if portrait:
-                    shape.drawRect(
+                    dr(
                         fitz.Rect(
                             mm_to_pt(self.layout["border_left"]),
                             mm_to_pt(self.layout["border_top"]),
@@ -827,7 +835,7 @@ class Plakativ:
                         )
                     )
                 else:
-                    shape.drawRect(
+                    dr(
                         fitz.Rect(
                             mm_to_pt(self.layout["border_bottom"]),
                             mm_to_pt(self.layout["border_left"]),
@@ -863,7 +871,7 @@ class Plakativ:
                     )
             if border:
                 if portrait:
-                    shape.drawRect(
+                    dr(
                         fitz.Rect(
                             mm_to_pt(self.layout["border_left"] - x),
                             mm_to_pt(self.layout["border_top"] - y),
@@ -880,7 +888,7 @@ class Plakativ:
                         )
                     )
                 else:
-                    shape.drawRect(
+                    dr(
                         fitz.Rect(
                             mm_to_pt(self.layout["border_bottom"] - x),
                             mm_to_pt(self.layout["border_left"] - y),
Does this fix things for you? ```patch diff --git a/plakativ.py b/plakativ.py index 81e7add..a2f0109 100755 --- a/plakativ.py +++ b/plakativ.py @@ -712,7 +712,11 @@ class Plakativ: shape = page.new_shape() else: shape = page.newShape() - shape.drawRect( + if hasattr(shape, "draw_rect"): + dr = shape.draw_rect + else: + dr = shape.drawRect + dr( fitz.Rect( x0, y0, @@ -722,7 +726,7 @@ class Plakativ: ) shape.finish(color=(0, 0, 1)) # outer rectangle - shape.drawRect( + dr( fitz.Rect( x0 - left, y0 - top, @@ -816,9 +820,13 @@ class Plakativ: shape = page.new_shape() else: shape = page.newShape() + if hasattr(shape, "draw_rect"): + dr = shape.draw_rect + else: + dr = shape.drawRect if guides: if portrait: - shape.drawRect( + dr( fitz.Rect( mm_to_pt(self.layout["border_left"]), mm_to_pt(self.layout["border_top"]), @@ -827,7 +835,7 @@ class Plakativ: ) ) else: - shape.drawRect( + dr( fitz.Rect( mm_to_pt(self.layout["border_bottom"]), mm_to_pt(self.layout["border_left"]), @@ -863,7 +871,7 @@ class Plakativ: ) if border: if portrait: - shape.drawRect( + dr( fitz.Rect( mm_to_pt(self.layout["border_left"] - x), mm_to_pt(self.layout["border_top"] - y), @@ -880,7 +888,7 @@ class Plakativ: ) ) else: - shape.drawRect( + dr( fitz.Rect( mm_to_pt(self.layout["border_bottom"] - x), mm_to_pt(self.layout["border_left"] - y), ```
Poster

Yep, the patch applies cleanly and no more error message, the cutting guide are shown on the final PDF. It seems to fix the issue for me.

Thanks a lot!

Yep, the patch applies cleanly and no more error message, the cutting guide are shown on the final PDF. It seems to fix the issue for me. Thanks a lot!
josch closed this issue 6 months ago
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 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#6
Loading…
There is no content yet.