6
6
"""
7
7
8
8
import wx
9
- print wx .__version__
10
- import random
9
+ print ( wx .__version__ )
10
+
11
11
12
12
class BufferedWindow (wx .Window ):
13
13
@@ -27,11 +27,10 @@ class BufferedWindow(wx.Window):
27
27
28
28
"""
29
29
30
-
31
30
def __init__ (self , parent , id ,
32
- pos = wx .DefaultPosition ,
33
- size = wx .DefaultSize ,
34
- style = wx .NO_FULL_REPAINT_ON_RESIZE ):
31
+ pos = wx .DefaultPosition ,
32
+ size = wx .DefaultSize ,
33
+ style = wx .NO_FULL_REPAINT_ON_RESIZE ):
35
34
wx .Window .__init__ (self , parent , id , pos , size , style )
36
35
37
36
wx .EVT_PAINT (self , self .OnPaint )
@@ -42,9 +41,9 @@ def __init__(self, parent, id,
42
41
# platforms at initialization, but little harm done.
43
42
self .OnSize (None )
44
43
45
- def Draw (self ,dc ):
46
- ## just here as a place holder.
47
- ## This method should be over-ridden when subclassed
44
+ def Draw (self , dc ):
45
+ # just here as a place holder.
46
+ # This method should be over-ridden when subclassed
48
47
pass
49
48
50
49
def TempDraw (self , dc ):
@@ -53,29 +52,29 @@ def TempDraw(self, dc):
53
52
of the buffer, like during Mouse actions, etc.
54
53
"""
55
54
pass
56
-
55
+
57
56
def OnPaint (self , event ):
58
- print "In OnPaint"
57
+ print ( "In OnPaint" )
59
58
# All that is needed here is to draw the buffer to screen
60
59
dc = wx .PaintDC (self )
61
- dc .DrawBitmap (self ._Buffer ,0 , 0 )
60
+ dc .DrawBitmap (self ._Buffer , 0 , 0 )
62
61
self .TempDraw (dc )
63
62
64
- def OnSize (self ,event ):
63
+ def OnSize (self , event ):
65
64
# The Buffer init is done here, to make sure the buffer is always
66
65
# the same size as the Window
67
- Size = self .GetClientSizeTuple ()
66
+ Size = self .GetClientSize ()
68
67
69
68
# Make sure we don't try to create a 0 size bitmap
70
69
Size = (max (Size [0 ], 1 ), max (Size [1 ], 1 ))
71
- self ._Buffer = wx .EmptyBitmap (Size [0 ],Size [1 ])
70
+ self ._Buffer = wx .Bitmap (Size [0 ], Size [1 ])
72
71
self .UpdateDrawing ()
73
72
74
- def SaveToFile (self ,FileName ,FileType ):
75
- ## This will save the contents of the buffer
76
- ## to the specified file. See the wxWindows docs for
77
- ## wx.Bitmap::SaveFile for the details
78
- self ._Buffer .SaveFile (FileName ,FileType )
73
+ def SaveToFile (self , FileName , FileType ):
74
+ # This will save the contents of the buffer
75
+ # to the specified file. See the wxWindows docs for
76
+ # wx.Bitmap::SaveFile for the details
77
+ self ._Buffer .SaveFile (FileName , FileType )
79
78
80
79
def UpdateDrawing (self ):
81
80
"""
@@ -84,30 +83,31 @@ def UpdateDrawing(self):
84
83
The idea here is that the drawing is based on some data generated
85
84
elsewhere in the system. IF that data changes, the drawing needs to
86
85
be updated.
87
-
88
86
"""
89
87
90
88
# update the buffer
91
89
dc = wx .MemoryDC ()
92
90
dc .SelectObject (self ._Buffer )
93
91
self .Draw (dc )
94
92
# update the screen
95
- wx .ClientDC (self ).DrawBitmap (self ._Buffer ,0 ,0 )
93
+ wx .ClientDC (self ).DrawBitmap (self ._Buffer , 0 , 0 )
94
+
96
95
97
96
class DrawWindow (BufferedWindow ):
97
+
98
98
def __init__ (self , parent , id = - 1 ):
99
- ## Any data the Draw() function needs must be initialized before
100
- ## calling BufferedWindow.__init__, as it will call the Draw
101
- ## function.
99
+ # Any data the Draw() function needs must be initialized before
100
+ # calling BufferedWindow.__init__, as it will call the Draw
101
+ # function.
102
102
BufferedWindow .__init__ (self , parent , id )
103
-
103
+
104
104
105
105
self .Bind (wx .EVT_LEFT_DOWN , self .OnLeftDown )
106
106
self .Bind (wx .EVT_LEFT_UP , self .OnLeftUp )
107
107
self .Bind (wx .EVT_MOTION , self .OnMove )
108
108
109
109
self .StartMove = None
110
-
110
+
111
111
self .overlay = wx .Overlay ()
112
112
113
113
def OnLeftDown (self , event ):
@@ -118,37 +118,37 @@ def OnLeftUp(self, event):
118
118
if self .HasCapture ():
119
119
self .ReleaseMouse ()
120
120
self .StartMove = None
121
- #self.Refresh()
122
- # When the mouse is released we reset the overlay and it
123
- # restores the former content to the window.
124
- #dc = wx.ClientDC(self)
125
- #odc = wx.DCOverlay(self.overlay, dc)
126
- #odc.Clear()
127
- #del odc
121
+ # self.Refresh()
122
+ # # When the mouse is released we reset the overlay and it
123
+ # # restores the former content to the window.
124
+ # dc = wx.ClientDC(self)
125
+ # odc = wx.DCOverlay(self.overlay, dc)
126
+ # odc.Clear()
127
+ # del odc
128
128
self .overlay .Reset ()
129
129
130
-
131
130
def OnMove (self , event ):
132
- if event .Dragging () and event .LeftIsDown () and self .StartMove is not None :
131
+ if (event .Dragging () and
132
+ event .LeftIsDown () and
133
+ self .StartMove is not None ):
133
134
pos = event .GetPosition ()
134
- #self.Refresh()
135
+ # self.Refresh()
135
136
dc = wx .ClientDC (self )
136
- odc = wx .DCOverlay ( self .overlay , dc )
137
+ odc = wx .DCOverlay (self .overlay , dc )
137
138
odc .Clear ()
138
- ## a black and white line so you can see it over any color.
139
+ # a black and white line so you can see it over any color.
139
140
dc .SetPen (wx .Pen ('WHITE' , 2 ))
140
141
dc .SetBrush (wx .TRANSPARENT_BRUSH )
141
- dc .DrawLinePoint (self .StartMove , pos )
142
+ dc .DrawLine (self .StartMove , pos )
142
143
dc .SetPen (wx .Pen ('BLACK' , 2 , wx .SHORT_DASH ))
143
- dc .DrawLinePoint (self .StartMove , pos )
144
+ dc .DrawLine (self .StartMove , pos )
145
+
146
+ del odc # to ensure it gets delted before the Client
144
147
145
- del odc # to ensure it gets delted before the Client
146
-
147
148
def Draw (self , dc ):
148
- coords = ((40 ,40 ),(200 ,220 ),(210 ,120 ),(120 ,300 ))
149
- dc .BeginDrawing ()
150
- dc .SetBackground ( wx .Brush ("Blue" ) )
151
- dc .Clear () # make sure you clear the bitmap!
149
+ coords = ((40 , 40 ), (200 , 220 ), (210 , 120 ), (120 , 300 ))
150
+ dc .SetBackground (wx .Brush ("Blue" ))
151
+ dc .Clear () # make sure you clear the bitmap!
152
152
153
153
dc .SetPen (wx .RED_PEN )
154
154
dc .SetBrush (wx .CYAN_BRUSH )
@@ -161,10 +161,10 @@ def __init__(self, *args, **kwargs):
161
161
wx .Frame .__init__ (self , * args , ** kwargs )
162
162
self .Window = DrawWindow (self )
163
163
164
+
164
165
class DemoApp (wx .App ):
165
166
def OnInit (self ):
166
- wx .InitAllImageHandlers () # called so a PNG can be saved
167
- frame = TestFrame (None , title = "OverlayTest" , size = (500 ,500 ))
167
+ frame = TestFrame (None , title = "OverlayTest" , size = (500 , 500 ))
168
168
frame .Show (True )
169
169
170
170
self .SetTopWindow (frame )
0 commit comments