Added a set of 2.4 compatibility classes for the wxDC classes that

replaces the normal Draw methods with those that have 2.4 compatible
parameter lists.  These classes are used by default only when
importing from wxPython.wx (the "old" namespace.)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25074 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-01-06 21:32:42 +00:00
parent 089142a562
commit 4942342c3e
4 changed files with 128 additions and 67 deletions

View File

@@ -281,13 +281,14 @@ that are affected are listed here::
SetClippingRegionAsRegion(region); SetClippingRegionAsRegion(region);
If you have code that draws on a DC you **will** get errors because of If you have code that draws on a DC and you are using the new wx
these changes, but it should be easy to fix the code. You can either namespace then you **will** get errors because of these changes, but
change the name of the *Type B* method called to the names shown it should be easy to fix the code. You can either change the name of
above, or just add parentheses around the parameters as needed to turn the *Type B* method called to the names shown above, or just add
them into tuples and let the SWIG typemaps turn them into the wx.Point parentheses around the parameters as needed to turn them into tuples
or wx.Size object that is expected. Then you will be calling the new and let the SWIG typemaps turn them into the wx.Point or wx.Size
*Type A* method. For example, if you had this code before:: object that is expected. Then you will be calling the new *Type A*
method. For example, if you had this code before::
dc.DrawRectangle(x, y, width, height) dc.DrawRectangle(x, y, width, height)
@@ -305,6 +306,14 @@ Then you can just simplify it like this::
dc.DrawRectangle(p, s) dc.DrawRectangle(p, s)
Now before you start yelling and screaming at me for breaking all your
code, take note that I said above "...using the new wx namespace..."
That's because if you are still importing from wxPython.wx then there
are some classes defined there with Draw and etc. methods that have
2.4 compatible signatures. However if/when the old wxPython.wx
namespace is removed then these classes will be removed too so you
should plam on migrating to the new namespace and new DC Draw methods
before that time.

View File

@@ -13,6 +13,7 @@
// Not a %module // Not a %module
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
%{ %{
@@ -52,7 +53,7 @@ public:
#if 0 // The old way #if defined(wxUSE_DC_OLD_METHODS)
bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE); bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE);
//bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const; //bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const;
@@ -486,8 +487,8 @@ public:
def DrawPolygonList(self, polygons, pens=None, brushes=None): def DrawPolygonList(self, polygons, pens=None, brushes=None):
## Note: This does not currently support fill style or offset %## Note: This does not currently support fill style or offset
## you can always use the non-List version if need be. %## you can always use the non-List version if need be.
if pens is None: if pens is None:
pens = [] pens = []
elif isinstance(pens, wx.Pen): elif isinstance(pens, wx.Pen):
@@ -504,9 +505,9 @@ public:
def DrawTextList(self, textList, coords, foregrounds = None, backgrounds = None, fonts = None): def DrawTextList(self, textList, coords, foregrounds = None, backgrounds = None, fonts = None):
## NOTE: this does not currently support changing the font %## NOTE: this does not currently support changing the font
## Make sure you set Background mode to wxSolid (DC.SetBackgroundMode) %## Make sure you set Background mode to wxSolid (DC.SetBackgroundMode)
## If you want backgounds to do anything. %## If you want backgounds to do anything.
if type(textList) == type(''): if type(textList) == type(''):
textList = [textList] textList = [textList]
elif len(textList) != len(coords): elif len(textList) != len(coords):
@@ -769,4 +770,49 @@ public:
}; };
#endif #endif
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Now define some Python classes that rename the Draw methods to be
// compatible with the DC Draw methods in 2.4. See also wxPython/_wx.py.
%define MAKE_OLD_DC_CLASS(classname)
%pythoncode {
class classname##_old(classname):
"""DC class that has methods with 2.4 compatible parameters."""
FloodFill = classname.FloodFillXY
GetPixel = classname.GetPixelXY
DrawLine = classname.DrawLineXY
CrossHair = classname.CrossHairXY
DrawArc = classname.DrawArcXY
DrawCheckMark = classname.DrawCheckMarkXY
DrawEllipticArc = classname.DrawEllipticArcXY
DrawPoint = classname.DrawPointXY
DrawRectangle = classname.DrawRectangleXY
DrawRoundedRectangle = classname.DrawRoundedRectangleXY
DrawCircle = classname.DrawCircleXY
DrawEllipse = classname.DrawEllipseXY
DrawIcon = classname.DrawIconXY
DrawBitmap = classname.DrawBitmapXY
DrawText = classname.DrawTextXY
DrawRotatedText = classname.DrawRotatedTextXY
Blit = classname.BlitXY
}
%enddef
MAKE_OLD_DC_CLASS(DC);
MAKE_OLD_DC_CLASS(MemoryDC);
MAKE_OLD_DC_CLASS(BufferedDC);
MAKE_OLD_DC_CLASS(BufferedPaintDC);
MAKE_OLD_DC_CLASS(ScreenDC);
MAKE_OLD_DC_CLASS(ClientDC);
MAKE_OLD_DC_CLASS(PaintDC);
MAKE_OLD_DC_CLASS(WindowDC);
MAKE_OLD_DC_CLASS(MirrorDC);
MAKE_OLD_DC_CLASS(PostScriptDC);
MAKE_OLD_DC_CLASS(MetaFileDC);
MAKE_OLD_DC_CLASS(PrinterDC);
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@@ -1,7 +1,18 @@
# Other names that need to be reverse-renamed for the old namespace # Other names that need to be reverse-renamed for the old namespace
#Color DC_old
#NamedColor MemoryDC_old
BufferedDC_old
BufferedPaintDC_old
ScreenDC_old
ClientDC_old
PaintDC_old
WindowDC_old
MirrorDC_old
PostScriptDC_old
MetaFileDC_old
PrinterDC_old

View File

@@ -35,28 +35,23 @@ def wxPyTypeCast(obj, typeStr):
wxPy_isinstance = isinstance wxPy_isinstance = isinstance
# To get wxDC methods compatible with the old 2.4 wxDC uncomment these
# lines. Note however that doing this will break any code that
# expects the new-style methods. (Is there a way to do this that does
# not have that problem? I suppose we could provide two versions of
# the DC classes and just rename them here...)
#wxDC.FloodFill = wxDC.FloodFillXY # The wx*DC_old classes have Draw* method signatures that are mostly
#wxDC.GetPixel = wxDC.GetPixelXY # compatible with 2.4, so assign the new classes to wx*DC_new and make
#wxDC.DrawLine = wxDC.DrawLineXY # the _old classes be the defaults with the normal names.
#wxDC.CrossHair = wxDC.CrossHairXY
#wxDC.DrawArc = wxDC.DrawArcXY # Too bad it doesn't currently work...
#wxDC.DrawCheckMark = wxDC.DrawCheckMarkXY
#wxDC.DrawEllipticArc = wxDC.DrawEllipticArcXY wxDC_new = wxDC; wxDC = wxDC_old
#wxDC.DrawPoint = wxDC.DrawPointXY wxMemoryDC_new = wxMemoryDC; wxMemoryDC = wxMemoryDC_old
#wxDC.DrawRectangle = wxDC.DrawRectangleXY wxBufferedDC_new = wxBufferedDC; wxBufferedDC = wxBufferedDC_old
#wxDC.DrawRoundedRectangle = wxDC.DrawRoundedRectangleXY wxBufferedPaintDC_new = wxBufferedPaintDC; wxBufferedPaintDC = wxBufferedPaintDC_old
#wxDC.DrawCircle = wxDC.DrawCircleXY wxScreenDC_new = wxScreenDC; wxScreenDC = wxScreenDC_old
#wxDC.DrawEllipse = wxDC.DrawEllipseXY wxClientDC_new = wxClientDC; wxClientDC = wxClientDC_old
#wxDC.DrawIcon = wxDC.DrawIconXY wxPaintDC_new = wxPaintDC; wxPaintDC = wxPaintDC_old
#wxDC.DrawBitmap = wxDC.DrawBitmapXY wxWindowDC_new = wxWindowDC; wxWindowDC = wxWindowDC_old
#wxDC.DrawText = wxDC.DrawTextXY wxMirrorDC_new = wxMirrorDC; wxMirrorDC = wxMirrorDC_old
#wxDC.DrawRotatedText = wxDC.DrawRotatedTextXY wxPostScriptDC_new = wxPostScriptDC; wxPostScriptDC = wxPostScriptDC_old
#wxDC.Blit = wxDC.BlitXY wxMetaFileDC_new = wxMetaFileDC; wxMetaFileDC = wxMetaFileDC_old
#wxDC.SetClippingRegion = wxDC.SetClippingRegionXY wxPrinterDC_new = wxPrinterDC; wxPrinterDC = wxPrinterDC_old