Created
June 21, 2020 14:03
-
-
Save tatarize/6eb8cac6a5ecddb0630b146fc0251f3c to your computer and use it in GitHub Desktop.
Test App For Post Close Crash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import wx | |
class RectFrame(wx.Frame): | |
def __init__(self, *args, **kwds): | |
# begin wxGlade: RectFrame.__init__ | |
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE | |
wx.Frame.__init__(self, *args, **kwds) | |
self.draw_panel = wx.Panel(self, wx.ID_ANY) | |
self._Buffer = None | |
self.path = None | |
self.on_size(None) | |
self.draw_panel.Bind(wx.EVT_SIZE, self.on_size, self) | |
self.draw_panel.Bind(wx.EVT_PAINT, self.on_paint) | |
self.draw_panel.Bind(wx.EVT_ERASE_BACKGROUND, self.on_erase) | |
self.Bind(wx.EVT_CLOSE, self.on_close, self) | |
self.on_update_buffer() | |
def on_close(self, event=None): | |
if self.path is not None: | |
print("Without del self.path it crashes on PC.") | |
del self.path | |
print("Even with it, crashes on Mac.") | |
event.Skip() # Calls Destroy. | |
def on_size(self, event): | |
width, height = self.ClientSize | |
self._Buffer = wx.Bitmap(width, height) | |
def on_erase(self, event): | |
pass | |
def on_paint(self, event): | |
wx.BufferedPaintDC(self.draw_panel, self._Buffer) | |
def on_update_buffer(self, event=None): | |
dc = wx.MemoryDC() | |
dc.SelectObject(self._Buffer) | |
dc.Clear() | |
dc.SetBackground(wx.WHITE_BRUSH) | |
gc = wx.GraphicsContext.Create(dc) | |
if self.path is None: | |
self.path = wx.GraphicsContext.CreatePath(gc) | |
self.path.MoveToPoint(0,0) | |
self.path.AddLineToPoint(0,50) | |
self.path.AddLineToPoint(50,50) | |
self.path.AddLineToPoint(50,0) | |
gc.SetPen(wx.BLACK_PEN) | |
gc.DrawPath(self.path) | |
gc.Destroy() | |
del dc | |
class MyRectApp(wx.App): | |
def OnInit(self): | |
self.frame = RectFrame(None, wx.ID_ANY, "") | |
self.SetTopWindow(self.frame) | |
self.frame.Show() | |
return True | |
if __name__ == "__main__": | |
example = MyRectApp(0) | |
example.MainLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment