Phoenix icon indicating copy to clipboard operation
Phoenix copied to clipboard

Broken pdfviewer - TypeError

Open onvav opened this issue 3 years ago • 1 comments

Description of the problem: When wxPython 4.2.0 demo "PDFViewer" (uses PyMuPDF 1.20.1) is launched and any PDF file is loaded, then following exception is thrown out:

Traceback (most recent call last):
  File "C:\Programs\Python310\lib\site-packages\wx\core.py", line 3427, in <lambda>
    lambda event: event.callable(*event.args, **event.kw) )
  File "C:\Programs\Python310\lib\site-packages\wx\lib\pdfviewer\viewer.py", line 410, in Render
    self.pagebuffer = wx.Bitmap(self.pagebufferwidth, self.pagebufferheight)
TypeError: Bitmap(): arguments did not match any overloaded call:
  overload 1: too many arguments
  overload 2: argument 1 has unexpected type 'int'
  overload 3: argument 1 has unexpected type 'int'
  overload 4: argument 2 has unexpected type 'float'
  overload 5: argument 1 has unexpected type 'int'
  overload 6: argument 2 has unexpected type 'float'
  overload 7: argument 1 has unexpected type 'int'
  overload 8: argument 1 has unexpected type 'int'
  overload 9: argument 1 has unexpected type 'int'
  overload 10: too many arguments

Operating system: M$ Windows 10 wxPython version & source: wxPython 4.2.0 from pypi (official release) Python version & source: Python 3.10.6 64-bit from python.org

It seems that some results of computations are float numbers instead of expected integers. When I have tried to fix the issue by this patch, it works fine now (just added conversions into integers):

Patch for file wx\lib\pdfviewer\viewer.py:


299c299
<             self.Scroll(0, pagenum*self.Ypagepixels/self.GetScrollPixelsPerUnit()[1] + 1)
---
>             self.Scroll(0, int(pagenum*self.Ypagepixels/self.GetScrollPixelsPerUnit()[1]) + 1)
356a357
> 
358c359
<             self.Ypagepixels = nhi
---
>             self.Ypagepixels = int(nhi)
360c361
<             self.Ypagepixels = nlo
---
>             self.Ypagepixels = int(nlo)

onvav avatar Aug 09 '22 08:08 onvav

See #2255 for my patch fixing this - it's slightly different, I changed the division operators to use // instead.

Infernio avatar Sep 01 '22 12:09 Infernio