Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
def free(self):
self.mdc.SelectObject(wx.NullBitmap)
del self.mdc
You can't subclass the wx.GraphicsContext class in Python because of the way that the classes are designed. The actual context instance you are using is a hidden platform-specifc class that is instantiated and returned by the Create "factory" methods. In other words, wx.GraphicsContext just provides the interface, and the implementation is provided by another class that we can't see from Python, and which is a different class for every platform. The same is true for the Path, Matrix and other wxGC classes.
How do I solve this?
You could do it by making your own Facade class that has a wx.GraphicsContext attribute, sets up the buffer bitmap as needed, and then just delegates all the GC methods to this attribute. In other words, it uses the "has-a" OOP relationship instead of the "is-a" relationship.
Similarly I would like to create two more classes:
class BitmapMemoryContext(wx.MemoryDC)
How is that different than the wx.BufferedDC class that already exists?
The code below doesn't work because there is no __init__ for
wx.GraphicsContext.
Yes there is.
Yes, but really No.
>>> gc = wx.GraphicsContext()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "//usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/_gdi.py", line 5492, in __init__
def __init__(self): raise AttributeError, "No constructor defined"
AttributeError: No constructor defined
That's a trick that SWIG uses when there is no C++ constructor and it wants to ensure that the base class's __init__ is not invoked instead.