ahrm / sioyek-python-extensions

Python wrapper and simple addons for sioyek PDF viewer
GNU General Public License v3.0
164 stars 7 forks source link

Problem with argument parsing #3

Open leephillips opened 1 year ago

leephillips commented 1 year ago

The scripts fail for me with errors about arguments: they seem to be quoted and parsed incorrectly. For example, when trying to use _add_text I get

ValueError: invalid literal for int() with base 10: '"15'

when Iā€™m on page 15 of the document.

ahrm commented 1 year ago

I think instead of

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

You should use

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

on some platforms.

leephillips commented 1 year ago

That worked; thank you. (Iā€™m on Debian, python 3.9.2.)

wenbopeng commented 1 year ago

On Window11 22H2,

# new_command _add_text python -m sioyek.add_text "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}" "%{selected_rect}" "%{command_text}"
new_command _add_text python -m sioyek.add_text "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}" %{selected_rect} "%{command_text}"
# new_command _add_red_text python -m sioyek.add_text "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}" "%{selected_rect}" "%{command_text}" fontsize=5 text_color=255,0,0
new_command _add_red_text python -m sioyek.add_text "%{sioyek_path}" "%{local_database}" "%{shared_database}" "%{file_path}" %{selected_rect} "%{command_text}" fontsize=5 text_color=255,0,0

Both are none responded.

image

Other extension commands work fine!

wenbopeng commented 1 year ago

I installed an old version of the Python extension. After uninstalling it with python -m pip uninstall sioyek and then python -m pip install sioyek I can use the extension again.šŸ˜€šŸ˜€šŸ˜€šŸ˜€

unsigned-enby commented 1 year ago

A better fix (albeit one needing a name change) might be to simply pass the selected_rectangle to clean_path (it worked for me anyhow) to remove the the quotes (as that's all clean_path does). Git diff for reference:

diff --git a/src/sioyek/add_text.py b/src/sioyek/add_text.py
index 5ad5b70..54352e2 100644
--- a/src/sioyek/add_text.py
+++ b/src/sioyek/add_text.py
@@ -37,7 +37,7 @@ if __name__ == '__main__':
     LOCAL_DATABASE_PATH = clean_path(sys.argv[2])
     SHARED_DATABASE_PATH = clean_path(sys.argv[3])
     FILE_PATH = clean_path(sys.argv[4])
-    rect_string = sys.argv[5]
+    rect_string = clean_path(sys.argv[5])
     added_text = sys.argv[6]

     params = parse_params(sys.argv[7:])