Skip to content
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

DrawRoundedRectangle casting to int #2648

Closed
lorenzonebolosi opened this issue Nov 19, 2024 · 3 comments
Closed

DrawRoundedRectangle casting to int #2648

lorenzonebolosi opened this issue Nov 19, 2024 · 3 comments

Comments

@lorenzonebolosi
Copy link
Contributor

lorenzonebolosi commented Nov 19, 2024

Operating system: Windows 10
wxPython version & source: wxPython 4.2.2 from pip, wxPython 4.2.3 from Snapshot builds
Python version & source: Python 3.7 (wxPython 4.2.2) Python 3.10 (wxPython 4.2.3)

Description of the problem:
I am opening a rectangle that I had previously saved in a pickle and trying to draw it, however It was saved in python 2.7 and height and width are floats, so are x and y cordinates. However in

dc.DrawRoundedRectangle(int(x1), int(y1), self._width, self._height, self._cornerRadius)
the casting of the x and y cordinates is done, but not of height and width, which results in an error when drawing it. Can this be solved with a casting also on height and width? This problem was not present with python 3.7, in fact the simple script that I attach run perfectly in 3.7 but not in 3.10 with wxPython 4.2.3, probably due to a change in the implementation of the DrawRoundedRectangle method.

Code Example (click to expand)
    import wx
    
    class RoundedRectangleFrame(wx.Frame):
        def __init__(self, *args, **kw):
            super(RoundedRectangleFrame, self).__init__(*args, **kw)
    
            # Set up the size and position for the rounded rectangle
            self._x1, self._y1 = 400.0, 112.42         # Top-left corner coordinates
            self._width, self._height = 80.0, 55.14 # Rectangle width and height
            self._cornerRadius = 15              # Corner radius
    
            # Bind the paint event
            self.Bind(wx.EVT_PAINT, self.OnPaint)
    
            # Set frame properties
            self.SetSize((700, 500))
            self.SetTitle("Rounded Rectangle with wxPython")
            self.Centre()
            
        def OnPaint(self, event):
            # Create a device context for drawing
            dc = wx.PaintDC(self)
    
            # Set the background color
            dc.SetBackground(wx.Brush("white"))
            dc.Clear()
    
            # Set pen and brush for the rectangle
            dc.SetPen(wx.Pen("black", width=2))
            dc.SetBrush(wx.Brush("sky blue"))
    
            # Draw the rounded rectangle with specified parameters
            dc.DrawRoundedRectangle(int(self._x1), int(self._y1), self._width, self._height, self._cornerRadius)
    
      if __name__ == "__main__":
          app = wx.App(False)
          frame = RoundedRectangleFrame(None)
          frame.Show()
          app.MainLoop()
@swt2c
Copy link
Collaborator

swt2c commented Nov 19, 2024

Yes, you are seeing a breaking change that was introduced in Python 3.10, see:
python/cpython#82180

Yes, the correct fix would be to add the int() casts for the width and height as well.

@lorenzonebolosi
Copy link
Contributor Author

Okay, do you mean in

dc.DrawRoundedRectangle(int(x1), int(y1), self._width, self._height, self._cornerRadius)
? Can you do it or tag who should do that?

@swt2c
Copy link
Collaborator

swt2c commented Nov 19, 2024

Pull requests are welcome.

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

No branches or pull requests

2 participants