From c3d5fdef81833b80cd99ef2a36c333291cb1df70 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 13 Jun 2013 06:18:51 +0000 Subject: [PATCH] - The keepReference hack is no longer needed for factory functions - Add some missing DC methods - minor fix in the GraphicsGradient demo git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@74205 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- demo/GraphicsGradient.py | 8 ++++---- etg/graphics.py | 43 ++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/demo/GraphicsGradient.py b/demo/GraphicsGradient.py index f452de34..a31d28da 100644 --- a/demo/GraphicsGradient.py +++ b/demo/GraphicsGradient.py @@ -15,14 +15,14 @@ class GradientPanel(wx.Panel): """ def __init__(self, parent): wx.Panel.__init__(self, parent, -1) + # Create a simple default brush we can use until a gradient + # brush is given to us + self.brush = wx.WHITE_BRUSH + self.SetBackgroundStyle(wx.BG_STYLE_PAINT) self.Bind(wx.EVT_PAINT, self.OnPaint) self.SetInitialSize((600,100)) - # create a simple default brush we can use until a gradient - # brush is given to us - ctx = g.GraphicsContext.Create() - self.brush = wx.WHITE_BRUSH def DrawWithBrush(self, brush): self.brush = brush diff --git a/etg/graphics.py b/etg/graphics.py index 98d2b9d4..b18acd84 100644 --- a/etg/graphics.py +++ b/etg/graphics.py @@ -66,34 +66,23 @@ def run(): tools.removeVirtuals(c) c.abstract = True - # Ensure that the target DC lives as long as the GC does. - # NOTE: Since the Creates are static methods there is no self to - # associate the extra reference with, so we can't use SIP's KeepReference - # without leaking the ref's. Instead we'll rename the Creates and then - # wrap a little Python code around it to deal with holding the ref to the - # target. + # Ensure that the target DC or image lives as long as the GC does. NOTE: + # Since the Creates are static methods there is no self to associate the + # extra reference with, but since they are factories then that extra + # reference will be held by the return value of the factory instead. for m in c.find('Create').all(): - m.pyName = '_Create' - #for p in m.items: - # if 'DC' in p.name or p.name == 'image': - # p.keepReference = True - c.addPyMethod('Create', '(target)', - isStatic=True, - doc="""\ - Create(target) -> GraphicsContext\n - Create a GraphicsContext with a :class:`Window`, :class:`WindowDC`, - :class:`MemoryDC`, :class:`PrinterDC` or :class:`Image` as the target - of the drawing operations. - """, - body="""\ - gc = GraphicsContext._Create(target) - gc._target = target - return gc - """) + for p in m.items: + if 'DC' in p.name or p.name == 'image': + p.keepReference = True # FIXME: Handle wxEnhMetaFileDC? c.find('Create').findOverload('wxEnhMetaFileDC').ignore() + + c.find('GetSize.width').out = True + c.find('GetSize.height').out = True + c.find('GetDPI.dpiX').out = True + c.find('GetDPI.dpiY').out = True m = c.find('GetPartialTextExtents') m.find('widths').ignore() @@ -110,7 +99,7 @@ def run(): m.find('width').out = True m.find('height').out = True m.find('descent').out = True - m.find('externalLeading').out = True + m.find('externalLeading').out = True c.addCppMethod('PyObject*', 'GetTextExtent', '(const wxString& text)', pyArgsString="(text) -> (width, height)", @@ -189,6 +178,12 @@ def run(): markFactories(c) c.abstract = True + for m in c.find('CreateContext').all(): + for p in m.items: + if 'DC' in p.name or p.name == 'image': + p.keepReference = True + c.find('CreateContextFromImage.image').keepReference = True + # FIXME: Handle wxEnhMetaFileDC? c.find('CreateContext').findOverload('wxEnhMetaFileDC').ignore()