sioyek-python-extensions icon indicating copy to clipboard operation
sioyek-python-extensions copied to clipboard

_add_text extension is not working

Open apalermo01 opened this issue 10 months ago • 1 comments

When I run add_text, no text appears in the selected rectangle.

Here's my config:

startup_commands toggle_custom_color
new_command _embed_annotations_in_file python /home/alex/scripts/embed_annotations_in_file.py %{sioyek_path} %{local_database} %{shared_database} %{file_path}

new_command _add_text python -m sioyek.add_text %{sioyek_path} %{local_database} %{shared_database} %{file_path} %{selected_rect} %{command_text}

I found that putting the parameters in quotes like in the readme throws an error:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/lib/python3.13/site-packages/sioyek/add_text.py", line 55, in <module>
    selected_page, selected_rect = parse_rect(rect_string)
                                   ~~~~~~~~~~^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/sioyek/add_text.py", line 7, in parse_rect
    page = int(parts[0])
ValueError: invalid literal for int() with base 10: '"0'

This is the full terminal output when I open up sioyek and just try to run select_rect then _add_text (I added a few print statements to add_text.py to make sure the arguments are getting parsed correctly):

➤ sioyek statistical_rethinking_text.pdf
default_config_path: /etc/sioyek/prefs.config
default_keys_path: /etc/sioyek/keys.config
user_config_path: [ 0 ] /etc/xdg/sioyek/prefs_user.config
user_config_path: [ 1 ] /home/alex/.config/sioyek/prefs_user.config
user_keys_path: [ 0 ] /etc/xdg/sioyek/keys_user.config
user_keys_path: [ 1 ] /home/alex/.config/sioyek/keys_user.config
database_file_path: /home/alex/.local/share/sioyek/test.db
local_database_file_path: /home/alex/.local/share/sioyek/local.db
global_database_file_path: /home/alex/.local/share/sioyek/shared.db
tutorial_path: /usr/share/sioyek/tutorial.pdf
last_opened_file_address_path: /home/alex/.local/share/sioyek/last_document_path.txt
shader_path: /usr/share/sioyek/shaders
Creating shared memory block...
Shared memory created: this is the primary application.
Starting IPC server...
IPC server started.
QString::arg: Argument missing: python -m sioyek.add_text %{sioyek_path} %{local_database} %{shared_database} %{file_path} %{selected_rect} %{command_text}, /home/alex/Documents/library/statistical_rethinking_text.pdf
Sioyek path =  /usr/bin/sioyek
local database path =  /home/alex/.local/share/sioyek/local.db
shared database path =  /home/alex/.local/share/sioyek/shared.db
file path =  /home/alex/Documents/library/statistical_rethinking_text.pdf
rect string =  0,16.4408,148.774,93.5231,254.426
added text =  TEST
params =  {}

Here's my system information:

  • Sioyek version: 2.0.0
  • OS: EndeavourOS
  • Kernel: Linux 6.12.10-arch1-1
  • Shell: Fish 3.7.1

I orignallly installed sioyek using the package in the AUR, however I also run into this issue when I installed sioyek in a virtual environmet.

I also attached a video of the issue.

https://github.com/user-attachments/assets/129a4b79-ff1c-45d0-98bb-53b736525b58

Please let me know if I'm doing something dumb or if this is an actual bug. If it is a bug, I'm open to attempting a fix myself.

apalermo01 avatar Jan 25 '25 21:01 apalermo01

Just wanted to share some updates after experimenting

I opened up the pdf file in okular and found that the annotations I created in sioyek do exist, however they're invisible. I opened up the annotations menu in okular, changed the border width from 0 to 0.1 (or anything that's not 0), hit apply, then the annotation appeared in both okular and sioyek.

I set up a minimal example script here:

import fitz

pdf_path = "tutorial.pdf"
doc = fitz.open(pdf_path)
page = doc[0]

rect = fitz.Rect(100, 100, 200, 150)
annot = page.add_freetext_annot(rect, "Test Annotation from minimal example")
# annot.set_border(width=1, color=(0, 0, 0))
annot.set_border(width=1)
annot.set_colors(stroke=(1, 0, 0), fill=(0.9, 0.9, 0.9))
annot.update()
doc.save("output.pdf")

And found that it produces the same behavior. However, the border width when I opened it in okular was 1 (as expected).

When I modify the example to write 2 annotations:

import fitz

pdf_path = "tutorial.pdf"
doc = fitz.open(pdf_path)
page = doc[0]

rect = fitz.Rect(100, 100, 200, 150)
annot = page.add_freetext_annot(rect, "Test Annotation from minimal example")
annot.set_border(width=1)
annot.set_colors(stroke=(1, 0, 0), fill=(0.9, 0.9, 0.9))
annot.set_popup(rect)

rect = fitz.Rect(200, 200, 300, 300)
annot = page.add_freetext_annot(rect, "Test Annotation from minimal example pt 2")
annot.set_border(width=1)
annot.set_colors(stroke=(1, 0, 0), fill=(0.9, 0.9, 0.9))
annot.set_popup(rect)
annot.update()

doc.save("output.pdf")

The FIRST annotation appears in okular and sioyek, but not the second.

I tried running one of the example scripts here and got the same result. I'll reach out to the pymupdf community once I have time to revisit this again in a few days.

apalermo01 avatar Jan 26 '25 04:01 apalermo01