-
-
Notifications
You must be signed in to change notification settings - Fork 284
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
checks: Add explicit conversion to int in wxpyimgview #2704
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more appropriate to create a wrapper class for wx.PaintDC
inside gui/wxpython/gui_core/wrap.py module.
class PaintDC(wx.PaintDC):
"""Wrapper around wx.PaintDC to have more control
over the widget on different platforms/wxpython versions"""
def __init__(self, *args, **kwargs):
wx.PaintDC.__init__(self, *args, **kwargs)
def DrawBitmap(self, **kwargs):
x = kwargs.get("x")
y = kwargs.get("y")
kwargs["x"] = int(x) if x else x
kwargs["y"] = int(y) if y else y
super().DrawBitmap(**kwargs)
and then inside scripts/wxpyimgview/wxpyimgview_gui.py module import this wrapper class.
...
from gui_core.wrap import BitmapFromImage, PaintDC # noqa: E402
...
dc = PaintDC(self)
...
dc.DrawBitmap(
bitmap=BitmapFromImage(image),
x=x0,
y=y0,
useMask=False,
)
I'm not quite sure why that would be. AFAICT, the problem isn't changed (wxPython) API, but changed enforcement of types. It should always had been int, no? If that is the case, I don't see the benefit overcomplicating the code. The conversion could as well be done earlier on: x0 = int((size.GetWidth() - app.i_width) / 2)
y0 = int((size.GetHeight() - app.i_height) / 2) |
It would be an advantage if |
But even so, they will have to be manually changed, all eventual cases of use anyway. The chain of inheritance will not work automatically, or am I missing something obvious... I'm still not convinced :-) |
When you look at gui/wxpython/gui_core/wrap.py module, we use same wrapper class (and same conversion to int in the overridden method(s)) for e.g.
grass/gui/wxpython/gui_core/wrap.py Lines 172 to 182 in ffb0ce6
https://github.com/OSGeo/grass/blob/main/gui/wxpython/gui_core/wrap.py#L185
https://github.com/OSGeo/grass/blob/main/gui/wxpython/gui_core/wrap.py#L631
https://github.com/OSGeo/grass/blob/main/gui/wxpython/gui_core/wrap.py#L690 |
While I generally like the wrappers given the continued changes in wx (and Python), looking at this particular case, I agree with @nilason, doing the int conversion right there is a more pragmatic approach. There doesn't seem to be any other case in current code where we could take advantage of the wrapper (I may be wrong). There are DrawBitmap functions, but some of them are called on wx.MemoryDC, so we would have to wrap multiple DC classes (wx.PseudoDC is already wrapped). The integer conversion in the other existing wrapper classes made sense because the wrappers were already in place, so adding the integer conversion to the wrapper methods resulted in smaller changes in code. There are still places in GUI, which could potentially crash in Python 3.10, not sure how to consistently test that. |
Maybe this way?
|
Ok, You are right. |
Fixes
wxpyimgview
failure to run with Python 3.10:Using:
Python 3.10.7 (v3.10.7:6cc6b13308, Sep 5 2022, 14:02:52) [Clang 13.0.0 (clang-1300.0.29.30)]
wxPython 4.2.0 osx-cocoa (phoenix) wxWidgets 3.2.0