DistributedProofreaders / guiguts-py

Guiguts rewrite using Python/tkinter
GNU General Public License v2.0
2 stars 7 forks source link

Improve/test/fix image viewer #56

Closed windymilla closed 1 month ago

windymilla commented 10 months ago

Image viewer is very rudimentary, allowing pan/zoom by mouse only (drag, Control+mouse wheel, maybe scroll gestures on mousepads)

Also hasn't been tested on different platforms.

At minimum it needs

Also consider what zoom/position to use when new image is loaded, which could be different size/aspect ratio. Also what to do if floating window is resized.

srjfoo commented 10 months ago

On modern Macs, for those who use a trackpad (tested on a MBP M1, not on a desktop with an external trackpad), control plus one of shift, option or cmd and the two-finger drag, zooming in and out works. control plus the two finger drag is a system default for zooming in on the whole screen, or a portion of the screen as set by the system preferences.

I don't know how easy it would be to implement, but certain applications allow "pinch to zoom". For instance, in this browser window, I am allowed to pinch to zoom within the browser window, and it doesn't affect anything else.

It would also be nice to see the ctrl/cmd plus + and - keyboard shortcuts implemented for zooming in and out.

srjfoo commented 6 months ago

When testing, I occasionally play with the image resizing currently in place (which is pretty painful on a Mac), and I ponder images in gg2. This time, I actually did some searching, and found https://stackoverflow.com/questions/63787755/dynamic-resizing-of-image-using-pil-and-tkinter. It may ultimately not be of use, but I thought I'd mention it, just in case it is when the time comes.

windymilla commented 5 months ago

Bug discovered by @srjfoo when auto imaging through file:

I brought up gg2 in the footnotes branch (making sure ahead of time that the project actually had some footnotes: the first project I tried didn't). Opened the images. I think I resized the image: I usually do. When I do that, the image area generally comes down to where the scrollbars disappear, because I generally size the image to fit inside the image pane/set the image pane size to be no smaller in either dimension than the image. When I opened the Footnote results list, the image area was immediately resized to max. The screenshot is designed to show that the image pane essentially doubled in height and width (according to the extra space at the botto.m and the lengths of the scrollbars that weren't there before). Actually, more than doubled. I zoomed out far enough that the scrollbars went away again, and the image is about the size of a postage stamp: about a quarter of the width of the image pane. If I close footnote fixup, and reopen, the background for the image gets even larger, and at some point, I can't scroll out anymore.

21:35:10: ERROR - root.py:45 - Tkinter Exception
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tkinter/__init__.py", line 1967, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "/Users/<username>/dpdev/guiguts-py-3.11/src/guiguts/mainwindow.py", line 373, in wheel_scroll
    self.show_image()
  File "/Users/<username>/dpdev/guiguts-py-3.11/src/guiguts/mainwindow.py", line 345, in show_image
    image.resize(
  File "/Users/<username>/Library/Caches/pypoetry/virtualenvs/guiguts-gE8TiuTD-py3.11/lib/python3.11/site-packages/PIL/Image.py", line 2200, in resize
    return self._new(self.im.resize(size, resample, box))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: height and width must be > 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tkinter/__init__.py", line 1967, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "/Users/<username>/dpdev/guiguts-py-3.11/src/guiguts/mainwindow.py", line 345, in show_image
    image.resize(
  File "/Users/<username>/Library/Caches/pypoetry/virtualenvs/guiguts-gE8TiuTD-py3.11/lib/python3.11/site-packages/PIL/Image.py", line 2200, in resize
    return self._new(self.im.resize(size, resample, box))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: height and width must be > 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tkinter/__init__.py", line 1967, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "/Users/<username>/dpdev/guiguts-py-3.11/src/guiguts/mainwindow.py", line 345, in show_image
    image.resize(
  File "/Users/<username>/Library/Caches/pypoetry/virtualenvs/guiguts-gE8TiuTD-py3.11/lib/python3.11/site-packages/PIL/Image.py", line 2200, in resize
    return self._new(self.im.resize(size, resample, box))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: height and width must be > 0
srjfoo commented 4 months ago

Stashing python-image-processing-libraries/ for future reference.

windymilla commented 1 month ago

I don't know how easy it would be to implement, but certain applications allow "pinch to zoom". For instance, in this browser window, I am allowed to pinch to zoom within the browser window, and it doesn't affect anything else.

According to this, it has been requested, but isn't supported yet: https://core.tcl-lang.org/tips/doc/trunk/tip/570.md

windymilla commented 1 month ago

Fixed by #456