From: Kevin A. <ka...@us...> - 2004-05-01 19:10:42
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8860 Modified Files: fixdc.py Log Message: updated to the latest version Index: fixdc.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/fixdc.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** fixdc.py 1 May 2004 16:26:00 -0000 1.1 --- fixdc.py 1 May 2004 19:10:30 -0000 1.2 *************** *** 1,39 **** """ 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. 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 new names are: ! * FloodFillPoint ! * GetPixelPoint ! * DrawLinePoint * CrossHairPoint * DrawArcPoint * DrawCheckMarkRect * DrawEllipticArcPointSize * DrawPointPoint * DrawRectanglePointSize * DrawRoundedRectanglePointSize - * DrawCirclePoint - * DrawEllipsePointSize - * DrawIconPoint - * DrawBitmapPoint * DrawTextPoint ! * DrawRotatedTextPoint ! * BlitPointSize ! WARNING: If you import this module the 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. 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. --Robin --- 1,65 ---- """ 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. ! 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 *************** *** 43,65 **** _names = [ ! ("FloodFillXY", "FloodFill", "FloodFillPoint"), ! ("GetPixelXY", "GetPixel", "GetPixelPoint"), ! ("DrawLineXY", "DrawLine", "DrawLinePoint"), ("CrossHairXY", "CrossHair", "CrossHairPoint"), ("DrawArcXY", "DrawArc", "DrawArcPoint"), ("DrawCheckMarkXY", "DrawCheckMark", "DrawCheckMarkRect"), ("DrawEllipticArcXY", "DrawEllipticArc", "DrawEllipticArcPointSize"), ("DrawPointXY", "DrawPoint", "DrawPointPoint"), ("DrawRectangleXY", "DrawRectangle", "DrawRectanglePointSize"), ("DrawRoundedRectangleXY", "DrawRoundedRectangle", "DrawRoundedRectanglePointSize"), - ("DrawCircleXY", "DrawCircle", "DrawCirclePoint"), - ("DrawEllipseXY", "DrawEllipse", "DrawEllipsePointSize"), - ("DrawIconXY", "DrawIcon", "DrawIconPoint"), - ("DrawBitmapXY", "DrawBitmap", "DrawBitmapPoint"), ("DrawTextXY", "DrawText", "DrawTextPoint"), ! ("DrawRotatedTextXY", "DrawRotatedText", "DrawRotatedTextPoint"), ! ("BlitXY", "Blit", "BlitPointSize"), ] if wx.VERSION[:4] == (2,5,1,5): cls = wx.DC --- 69,114 ---- _names = [ ! ("BlitXY", "Blit", "BlitPointSize"), ("CrossHairXY", "CrossHair", "CrossHairPoint"), ("DrawArcXY", "DrawArc", "DrawArcPoint"), + ("DrawBitmapXY", "DrawBitmap", "DrawBitmapPoint"), ("DrawCheckMarkXY", "DrawCheckMark", "DrawCheckMarkRect"), + ("DrawCircleXY", "DrawCircle", "DrawCirclePoint"), + ("DrawEllipseXY", "DrawEllipse", "DrawEllipsePointSize"), ("DrawEllipticArcXY", "DrawEllipticArc", "DrawEllipticArcPointSize"), + ("DrawIconXY", "DrawIcon", "DrawIconPoint"), + ("DrawLineXY", "DrawLine", "DrawLinePoint"), ("DrawPointXY", "DrawPoint", "DrawPointPoint"), ("DrawRectangleXY", "DrawRectangle", "DrawRectanglePointSize"), + ("DrawRotatedTextXY", "DrawRotatedText", "DrawRotatedTextPoint"), ("DrawRoundedRectangleXY", "DrawRoundedRectangle", "DrawRoundedRectanglePointSize"), ("DrawTextXY", "DrawText", "DrawTextPoint"), ! ("FloodFillXY", "FloodFill", "FloodFillPoint"), ! ("GetPixelXY", "GetPixel", "GetPixelPoint"), ! ("SetClippingRegionXY", "SetClippingRegion", "SetClippingRegionPointSize"), ] + + # this is a bit of handy code from the Python Cookbook + def _renamefunction(function, name): + """ + This function returns a function identical to the given one, but + with the given name. + """ + from types import FunctionType, CodeType + + c = function.func_code + if c.co_name != name: + # rename the code object. + c = CodeType(c.co_argcount, c.co_nlocals, c.co_stacksize, + c.co_flags, c.co_code, c.co_consts, + c.co_names, c.co_varnames, c.co_filename, + name, c.co_firstlineno, c.co_lnotab) + if function.func_defaults != None: + return FunctionType(c, function.func_globals, name, + function.func_defaults) + return FunctionType(c, function.func_globals, name) + + if wx.VERSION[:4] == (2,5,1,5): cls = wx.DC *************** *** 67,72 **** m_old = getattr(cls, old) m_norm = getattr(cls, norm) ! setattr(cls, new, m_norm) ! setattr(cls, norm, m_old) delattr(cls, old) --- 116,121 ---- m_old = getattr(cls, old) m_norm = getattr(cls, norm) ! setattr(cls, new, _renamefunction(m_norm, new)) ! setattr(cls, norm, _renamefunction(m_old, norm)) delattr(cls, old) *************** *** 75,77 **** - --- 124,125 ---- |