Skip to content

Fix zerodivision errors in pdfviewer when windows are extremely small #2465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jmoraleda
Copy link
Contributor

@jmoraleda jmoraleda commented Oct 8, 2023

This fixes the error:

  File "/Users/mysuser/virtualenv/cytopar/lib/python3.11/site-packages/wx/lib/pdfviewer/viewer.py", line 217, in LoadFile
    self.CalculateDimensions()      # to get initial visible page range
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/myuser/virtualenv/cytopar/lib/python3.11/site-packages/wx/lib/pdfviewer/viewer.py", line 371, in CalculateDimensions
    self.frompage = int(min(self.y0/self.Ypagepixels, self.numpages-1))
                            ~~~~~~~^~~~~~~~~~~~~~~~~
ZeroDivisionError: division by zero

which can be observed by trying to resize a window containing a pdfviewer to extremely small sizes.

I remark that this PR expands on a previous PR of mine a few years ago, which handled the case when window client sizes were exactly zero on initialization #1519 but did not consider cases where window client sizes were very small, which would, through rounding from floating point to int, also result in ZeroDivision errors as shown above.

@jmoraleda
Copy link
Contributor Author

@swt2c Hello Scott. I noticed you just merged #2470 . I wonder if you would be able to review and merge this one too. It is on the same module and related to visualization too. I discovered both issues together. Thank you.

@jmoraleda
Copy link
Contributor Author

I am closing this PR in favor of #2480

@jmoraleda jmoraleda closed this Nov 15, 2023
@jmoraleda jmoraleda deleted the pdfviewer_bugfix_when_window_very_small branch November 15, 2023 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant