toot icon indicating copy to clipboard operation
toot copied to clipboard

'm' keypress image viewer crashes and/or doesn't detect available/suitable image viewers

Open draeath opened this issue 2 years ago • 4 comments

A picture is worth a thousand words, so here's what it looks like. I can't really tell if this is a problem with my environment (ImageMagick has really stupid binary names) or toot itself.

what

To replicate:

  1. Launch toot tui
  2. hit g and select "Global public timeline."
  3. Scroll to any post that contains an media attachment URL
  4. Press m

My brain skipped a few steps, for some reason I expected this to pop up the 'mute' that we see when we first press a to see the poster's account information.

I have absolutely no idea why IMageMagick is popping up, and this key is not documented in the TUI's help screen or in the status bar. Also note the error in the status bar:

display: attempt to perform an operation not allowed by the security policy `HTTPS' @ error/constitute.c/IsCoderAuthorized/454.


Some environmental details:

  • OpenSUSE tumbleweed (snapshot 20230730-0)
  • toot v0.38.1 installed via pip, within a python 3.11 venv
  • toot is running inside konsole via an X.org session

package ImageMagick-7.1.1.12-1.1.x86_64 installed, which provides these binaries in my path:

  • /usr/bin/animate
  • /usr/bin/compare
  • /usr/bin/composite
  • /usr/bin/conjure
  • /usr/bin/convert
  • /usr/bin/display
  • /usr/bin/identify
  • /usr/bin/import
  • /usr/bin/magick
  • /usr/bin/magick-script
  • /usr/bin/mogrify
  • /usr/bin/montage
  • /usr/bin/stream

draeath avatar Aug 01 '23 19:08 draeath

I removed ImageMagick and retried, and I receive a fun traceback that exposes what this is (trying to) accomplish. It looks like it's trying to open an image viewer.

I don't know how/why it tries to use ImageMagick for this - that seems like the wrong tool. Additionally, it throws a traceback and kills toot, instead of handling the condition better.

Additionally, it doesn't seem to be aware of KDE's image viewer(s)?

Traceback (most recent call last):
File "/home/draeath/.venvs/default/bin/toot", line 8, in <module>
    sys.exit(main())
            ^^^^^^
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/toot/console.py", line 961, in main
    run_command(app, user, command_name, args)
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/toot/console.py", line 943, in run_command
    return fn(app, user, parsed_args)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/toot/commands.py", line 571, in tui
    TUI.create(app, user, args).run()
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/toot/tui/app.py", line 149, in run
    self.loop.run()
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/urwid/main_loop.py", line 287, in run
    self._run()
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/urwid/main_loop.py", line 385, in _run
    self.event_loop.run()
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/urwid/main_loop.py", line 1494, in run
    reraise(*exc_info)
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/urwid/compat.py", line 58, in reraise
    raise value
File "/usr/lib64/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/urwid/raw_display.py", line 416, in <lambda>
    wrapper = lambda: self.parse_input(
                    ^^^^^^^^^^^^^^^^^
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/urwid/raw_display.py", line 515, in parse_input
    callback(processed, processed_codes)
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/urwid/main_loop.py", line 412, in _update
    self.process_input(keys)
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/urwid/main_loop.py", line 513, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/urwid/container.py", line 1135, in keypress
    return self.body.keypress( (maxcol, remaining), key )
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/toot/tui/timeline.py", line 196, in keypress
    self.tui.show_media(status)
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/toot/tui/app.py", line 518, in show_media
    show_media(urls)
File "/home/draeath/.venvs/general/lib64/python3.11/site-packages/toot/tui/utils.py", line 73, in show_media
    raise Exception("Cannot find an image viewer")
Exception: Cannot find an image viewer

draeath avatar Aug 01 '23 19:08 draeath

Putting the viewer detection itself aside, this exception should probably be handled with a status line message instead of being unhandled.

The docstring here seems quite on-point :D

I might suggest disabling this until it's cleaned up or refined? Or again, at least handling the exception better.

draeath avatar Aug 01 '23 19:08 draeath

I suggest:

  1. remove or deprioritize display from the list, since ImageMagick seems it doesn't understand what to do with a URL
  2. add gwenview to cover KDE users, it fills the same niche as eog does for Gnome. If given a URL as an argument, it does the correct thing and displays the image correctly. (tested with gwenview 23.04.3)

draeath avatar Aug 01 '23 19:08 draeath

Looks like display is at the end of the list.

Submitted PR #393 to add gwenview between it and eog

It might be worth adding a few popular web browsers to that list as well, below the dedicated image viewers. Firefox tests fine being used this way, though ideally one could add additional arguments and the current method of testing for them would break if you just added it to the string. That sort of thing would probably be best left to after a means to configure a custom viewer.

Edit: actually I bet it's a good idea to just use xdg-open or similar and let the user's environment elect the viewer to launch...

draeath avatar Aug 01 '23 19:08 draeath