]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/compatdc.py
some methods missing wxPyBeginBlockThreads/wxPyEndBlockThreads
[wxWidgets.git] / wxPython / wx / lib / compatdc.py
1 #----------------------------------------------------------------------
2 # Name: compatdc.py
3 # Purpose: Make wxPython 2.4 DC classes compatible with the 2.5
4 # DC classes
5 #
6 # Author: Robin Dunn
7 #
8 # Created: 21-Apr-2004
9 # RCS-ID: $Id$
10 # Copyright: (c) 2004 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------
13
14 import wx
15
16
17 def MakeDCCompatible(klass, full=False):
18 """
19 Manipulate the DC class passed to this funciton such that it is
20 more compatible with the DC classes used in wxPython 2.5. This
21 should help with writing code that works with both versions. If
22 full is True then in addition to creating the 'XY' versions of the
23 methods, a 'point/size' version (which are the new defaults in
24 2.5) will also be created.
25 """
26 if wx.VERSION >= (2,5):
27 return # Nothing to do
28
29 # first create XY methods from the current ones.
30 klass.FloodFillXY = klass.FloodFill
31 klass.GetPixelXY = klass.GetPixel
32 klass.DrawLineXY = klass.DrawLine
33 klass.CrossHairXY = klass.CrossHair
34 klass.DrawArcXY = klass.DrawArc
35 klass.DrawEllipticArcXY = klass.DrawEllipticArc
36 klass.DrawPointXY = klass.DrawPoint
37 klass.DrawRectangleXY = klass.DrawRectangle
38 klass.DrawRoundedRectangleXY = klass.DrawRoundedRectangle
39 klass.DrawCircleXY = klass.DrawCircle
40 klass.DrawEllipseXY = klass.DrawEllipse
41 klass.DrawIconXY = klass.DrawIcon
42 klass.DrawBitmapXY = klass.DrawBitmap
43 klass.DrawTextXY = klass.DrawText
44 klass.DrawRotatedTextXY = klass.DrawRotatedText
45 klass.BlitXY = klass.Blit
46
47 # now, make some functions that we can use as new methods
48 if full:
49 def FloodFill(self, pt, col, style=wx.FLOOD_SURFACE):
50 pt = wx.Point(*pt)
51 return self.FloodFillXY(pt.x, pt.y, col, style)
52 klass.FloodFill = FloodFill
53
54 def GetPixel(self, pt):
55 pt = wx.Point(*pt)
56 return self.GetPixelXY(pt.x, pt.y)
57 klass.GetPixel = GetPixel
58
59 def DrawLine(self, pt1, pt2):
60 pt1 = wx.Point(*pt1)
61 pt2 = wx.Point(*pt2)
62 return self.DrawLineXY(pt1.x, pt1.y, pt2.x, pt2.y)
63 klass.DrawLine = DrawLine
64
65 def CrossHair(self, pt):
66 pt = wx.Point(*pt)
67 return self.CrossHairXY(pt.x, pt.y)
68 klass.CrossHair = CrossHair
69
70 def DrawArc(self, pt1, pt2, centre):
71 pt1 = wx.Point(*pt1)
72 pt2 = wx.Point(*pt2)
73 return self.DrawArcXY(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y)
74 klass.DrawArc = DrawArc
75
76 def DrawEllipticArc(self, pt, sz, sa, ea):
77 pt = wx.Point(*pt)
78 sz = wx.Size(*sz)
79 return self.DrawEllipticArcXY(pt.x, pt.y, sz.width, sz.height, sa, ea)
80 klass.DrawEllipticArc = DrawEllipticArc
81
82 def DrawPoint(self, pt):
83 pt = wx.Point(*pt)
84 return self.DrawPointXY(pt.x, pt.y)
85 klass.DrawPoint = DrawPoint
86
87 def DrawRectangle(self, pt, sz):
88 pt = wx.Point(*pt)
89 sz = wx.Size(*sz)
90 return self.DrawRectangleXY(pt.x, pt.y, sz.width, sz.height)
91 klass.DrawRectangle = DrawRectangle
92
93 def DrawRoundedRectangle(self, pt, sz, radius):
94 pt = wx.Point(*pt)
95 sz = wx.Size(*sz)
96 return self.DrawRoundedRectangleXY(pt.x, pt.y, sz.width, sz.height, radius)
97 klass.DrawRoundedRectangle = DrawRoundedRectangle
98
99 def DrawCircle(self, pt, radius):
100 pt = wx.Point(*pt)
101 return self.DrawCircleXY(pt.x, pt.y, radius)
102 klass.DrawCircle = DrawCircle
103
104 def DrawEllipse(self, pt, sz):
105 pt = wx.Point(*pt)
106 sz = wx.Size(*sz)
107 return self.DrawEllipseXY(pt.x, pt.y, sz.width, sz.height)
108 klass.DrawEllipse = DrawEllipse
109
110 def DrawIcon(self, icon, pt):
111 pt = wx.Point(*pt)
112 return self.DrawIconXY(icon, pt.x, pt.y )
113 klass.DrawIcon = DrawIcon
114
115 def DrawBitmap(self, bmp, pt):
116 pt = wx.Point(*pt)
117 return self.DrawBitmapXY(bmp, pt.x, pt.y)
118 klass.DrawBitmap = DrawBitmap
119
120 def DrawText(self, text, pt):
121 pt = wx.Point(*pt)
122 return self.DrawTextXY(text, pt.x, pt.y)
123 klass.DrawText = DrawText
124
125 def DrawRotatedText(self, text, pt, angle):
126 pt = wx.Point(*pt)
127 return self.DrawRotatedTextXY(text, pt.x, pt.y, angle)
128 klass.DrawRotatedText = DrawRotatedText
129
130 def Blit(self, destPt, sz, source, srcPt,
131 rop=wx.COPY, useMask=False, srcPtMask=wx.DefaultPosition):
132 return self.BlitXY(destPt.x, destPt.y, sz.width, sz.height,
133 source, srcPt.x, srcPt.y, rop, useMask,
134 srcPtMask.x, srcPtMask.y)
135 klass.Blit = Blit
136
137
138 def MakeAllDCsCompatible(full=False):
139 """
140 Run MakeDCCompatible on all DC classes in wx.
141 """
142 MakeDCCompatible(wx.BufferedPaintDC, full)
143 MakeDCCompatible(wx.BufferedDC, full)
144 MakeDCCompatible(wx.MemoryDC, full)
145 MakeDCCompatible(wx.ScreenDC, full)
146 MakeDCCompatible(wx.ClientDC, full)
147 MakeDCCompatible(wx.PaintDC, full)
148 MakeDCCompatible(wx.WindowDC, full)
149 MakeDCCompatible(wx.PostScriptDC, full)
150 if hasattr(wx, "MetaFileDC"):
151 MakeDCCompatible(wx.MetaFileDC, full)
152 if hasattr(wx, "PrinterDC"):
153 MakeDCCompatible(wx.PrinterDC, full)
154 MakeDCCompatible(wx.DC, full)
155