]> git.saurik.com Git - wxWidgets.git/blob - wxPython/misc/fixdc.py
Changed type of bitmaps. RC of DMC reported 'is not a valid Windows 3.0 or OS/2 1...
[wxWidgets.git] / wxPython / misc / fixdc.py
1 """
2 This module will do surgery on the wx.DC class in wxPython 2.5.1.5 to
3 make it act like the wx.DC class in later versions will. To use this
4 module simply import it in one of your program's modules before you
5 use any DC's. It does its work upon import and then is done.
6
7 This module will *only* do something if it is imported in an app
8 running on wxPython 2.5.1.5, for all other versions it will do
9 nothing. This means that you can include it with your application and
10 then if your user is on 2.5.1.5 the DC methods will be updated, but if
11 they are on a newer version (or an older one for that matter) then
12 nothing will be done and your code using DCs will still be compatible.
13
14 So what does it do? In a nutshell, the old 2.4.x style of method
15 names, where the 'normal' name takes separate parameters for x, y,
16 width and height will be restored, and the new methods that take
17 wx.Point and/or wx.Size (which can also be converted from 2-element
18 sequences) will be given new non-default method names. The 2.5.1.5
19 'XY' style names will be removed. The new names for the 'Point/Size'
20 methods are:
21
22 * BlitPointSize
23 * CrossHairPoint
24 * DrawArcPoint
25 * DrawBitmapPoint
26 * DrawCheckMarkRect
27 * DrawCirclePoint
28 * DrawEllipsePointSize
29 * DrawEllipticArcPointSize
30 * DrawIconPoint
31 * DrawLinePoint
32 * DrawPointPoint
33 * DrawRectanglePointSize
34 * DrawRotatedTextPoint
35 * DrawRoundedRectanglePointSize
36 * DrawTextPoint
37 * FloodFillPoint
38 * GetPixelPoint
39 * SetClippingRegionPointSize
40
41 Please note that only the names that you access the methods by will be
42 changed. The names used in docstrings as well as the names used to
43 call the extenaion functions and the names used when raising
44 exceptions will still use the old names. (Of course once a new
45 version of wxPython has been built with this new style then this will
46 no longer apply. The new names will be the real names.) For
47 example::
48
49 Traceback (most recent call last):
50 File "/usr/lib/python2.3/site-packages/wx/lib/buttons.py", line 272, in OnPaint
51 self.DrawBezel(dc, x1, y1, x2, y2)
52 File "/usr/lib/python2.3/site-packages/wx/lib/buttons.py", line 220, in DrawBezel
53 dc.DrawLine((x1+i, y1), (x1+i, y2-i))
54 File "/usr/lib/python2.3/site-packages/wx/gdi.py", line 2293, in DrawLine
55 return _gdi.DC_DrawLineXY(*args, **kwargs)
56 TypeError: DC_DrawLineXY() takes exactly 5 arguments (3 given)
57
58
59 WARNING: If you import this module then the wx.DC class will be
60 changed for the entire application, so if you use code from
61 the wx.lib package (or 3rd party modules that have already
62 been converted to the doomed 2.5.1.5 implementaion of the DC
63 Draw methods) then that code will break as shown above. This
64 is an all-or-nothing fix, (just like the next version of
65 wxPython will be,) so you *will* need to do something to
66 resolve this situation if you run into it. The best thing to
67 do of course is to correct the library module to work with
68 the corrected DC semantics and then send me a patch, although
69 it probably won't be too long before the library modules are
70 updated in CVS so you could get a copy of them there.
71
72 --Robin
73 """
74
75 import wx
76
77 _names = [
78 ("BlitXY", "Blit", "BlitPointSize"),
79 ("CrossHairXY", "CrossHair", "CrossHairPoint"),
80 ("DrawArcXY", "DrawArc", "DrawArcPoint"),
81 ("DrawBitmapXY", "DrawBitmap", "DrawBitmapPoint"),
82 ("DrawCheckMarkXY", "DrawCheckMark", "DrawCheckMarkRect"),
83 ("DrawCircleXY", "DrawCircle", "DrawCirclePoint"),
84 ("DrawEllipseXY", "DrawEllipse", "DrawEllipsePointSize"),
85 ("DrawEllipticArcXY", "DrawEllipticArc", "DrawEllipticArcPointSize"),
86 ("DrawIconXY", "DrawIcon", "DrawIconPoint"),
87 ("DrawLineXY", "DrawLine", "DrawLinePoint"),
88 ("DrawPointXY", "DrawPoint", "DrawPointPoint"),
89 ("DrawRectangleXY", "DrawRectangle", "DrawRectanglePointSize"),
90 ("DrawRotatedTextXY", "DrawRotatedText", "DrawRotatedTextPoint"),
91 ("DrawRoundedRectangleXY", "DrawRoundedRectangle", "DrawRoundedRectanglePointSize"),
92 ("DrawTextXY", "DrawText", "DrawTextPoint"),
93 ("FloodFillXY", "FloodFill", "FloodFillPoint"),
94 ("GetPixelXY", "GetPixel", "GetPixelPoint"),
95 ("SetClippingRegionXY", "SetClippingRegion", "SetClippingRegionPointSize"),
96 ]
97
98
99 # this is a bit of handy code from the Python Cookbook
100 def _renamefunction(function, name):
101 """
102 This function returns a function identical to the given one, but
103 with the given name.
104 """
105 from types import FunctionType, CodeType
106
107 c = function.func_code
108 if c.co_name != name:
109 # rename the code object.
110 c = CodeType(c.co_argcount, c.co_nlocals, c.co_stacksize,
111 c.co_flags, c.co_code, c.co_consts,
112 c.co_names, c.co_varnames, c.co_filename,
113 name, c.co_firstlineno, c.co_lnotab)
114 if function.func_defaults != None:
115 return FunctionType(c, function.func_globals, name,
116 function.func_defaults)
117 return FunctionType(c, function.func_globals, name)
118
119
120 if wx.VERSION[:4] == (2,5,1,5):
121 for old, norm, new in _names:
122 m_old = getattr(wx.DC, old)
123 m_norm = getattr(wx.DC, norm)
124 setattr(wx.DC, new, _renamefunction(m_norm, new))
125 setattr(wx.DC, norm, _renamefunction(m_old, norm))
126 delattr(wx.DC, old)
127
128 del old, norm, new, m_old, m_norm
129
130