DC methods in next release, and a workaround

Hi all,

As I've mentioned, the incompatible changes to the DC methods in 2.5.1.5 are going to be reverted in the next release. Until that release is ready I've made a fixdc.py module that you can import in your apps that will surgically extract the badly named methods, rename them and implant them back into the wx.DC class. It will also rename the newer Point/Size methods and implant them as well. So this module will let you use the wx.DC classes in 2.5.1.5 as they will be in the next and future releases.

The fixdc.py file is available via SourceForge at: http://prdownloads.sourceforge.net/wxpython/fixdc.py?download

I've copied the docstring below. Please read it carefully.

I expect to have checked in updated wx.lib modules by the end of today so if your app needs to use any of those modules that use the affected DC methods in conjunciton with fixdc.py, then you can get the updates directly from CVS. They will have been tested with the new CVS version of wxPython but I expect that most of them (if not all) will still work with 2.5.1.5 and fixdc.py.

http://cvs.wxwidgets.org/viewcvs.cgi/wxWidgets/wxPython/wx/lib/

-- Dr. Robin

"""
This module will do surgery on the wx.DC class in wxPython 2.5.1.5 to
make it act like the wx.DC class in later versions will. To use this
module simply import it in one of your program's modules before you
use any DC's. It does its work upon import and then is done.

This module will *only* do something if it is imported in an app
running on wxPython 2.5.1.5, for all other versions it will do
nothing. This means that you can include it with your application and
then if your user is on 2.5.1.5 the DC methods will be updated, but if
they are on a newer version (or an older one for that matter) then
nothing will be done and your code using DCs will still be compatible.

So what does it do? In a nutshell, the old 2.4.x style of method
names, where the 'normal' name takes separate parameters for x, y,
width and height will be restored, and the new methods that take
wx.Point and/or wx.Size (which can also be converted from 2-element
sequences) will be given new non-default method names. The 2.5.1.5
'XY' style names will be removed. The new names for the 'Point/Size'
methods are:

     * BlitPointSize
     * CrossHairPoint
     * DrawArcPoint
     * DrawBitmapPoint
     * DrawCheckMarkRect
     * DrawCirclePoint
     * DrawEllipsePointSize
     * DrawEllipticArcPointSize
     * DrawIconPoint
     * DrawLinePoint
     * DrawPointPoint
     * DrawRectanglePointSize
     * DrawRotatedTextPoint
     * DrawRoundedRectanglePointSize
     * DrawTextPoint
     * FloodFillPoint
     * GetPixelPoint
     * SetClippingRegionPointSize

Please note that only the names that you access the methods by will be
changed. The names used in docstrings as well as the names used to
call the extenaion functions and the names used when raising
exceptions will still use the old names. (Of course once a new
version of wxPython has been built with this new style then this will
no longer apply. The new names will be the real names.) For
example::

   Traceback (most recent call last):
     File "/usr/lib/python2.3/site-packages/wx/lib/buttons.py", line 272, in OnPaint
       self.DrawBezel(dc, x1, y1, x2, y2)
     File "/usr/lib/python2.3/site-packages/wx/lib/buttons.py", line 220, in DrawBezel
       dc.DrawLine((x1+i, y1), (x1+i, y2-i))
     File "/usr/lib/python2.3/site-packages/wx/gdi.py", line 2293, in DrawLine
       return _gdi.DC_DrawLineXY(*args, **kwargs)
   TypeError: DC_DrawLineXY() takes exactly 5 arguments (3 given)

WARNING: If you import this module then the wx.DC class will be
          changed for the entire application, so if you use code from
          the wx.lib package (or 3rd party modules that have already
          been converted to the doomed 2.5.1.5 implementaion of the DC
          Draw methods) then that code will break as shown above. This
          is an all-or-nothing fix, (just like the next version of
          wxPython will be,) so you *will* need to do something to
          resolve this situation if you run into it. The best thing to
          do of course is to correct the library module to work with
          the corrected DC semantics and then send me a patch, although
          it probably won't be too long before the library modules are
          updated in CVS so you could get a copy of them there.

--Robin
"""

Robin Dunn wrote:

this module will let
you use the wx.DC classes in 2.5.1.5 as they will be in the next and future releases.

FWIW, this fix is working fine for me, though I DID like the alternative approach! It's clear from the discussion that it's probably for the best to revert to the old way. I doubt I'll get around to updating the wxWidgets docs now, however....

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov