66"""
77
88import wx
9- print wx .__version__
10- import random
9+ print ( wx .__version__ )
10+
1111
1212class BufferedWindow (wx .Window ):
1313
@@ -27,11 +27,10 @@ class BufferedWindow(wx.Window):
2727
2828 """
2929
30-
3130 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 ):
3534 wx .Window .__init__ (self , parent , id , pos , size , style )
3635
3736 wx .EVT_PAINT (self , self .OnPaint )
@@ -42,9 +41,9 @@ def __init__(self, parent, id,
4241 # platforms at initialization, but little harm done.
4342 self .OnSize (None )
4443
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
4847 pass
4948
5049 def TempDraw (self , dc ):
@@ -53,29 +52,29 @@ def TempDraw(self, dc):
5352 of the buffer, like during Mouse actions, etc.
5453 """
5554 pass
56-
55+
5756 def OnPaint (self , event ):
58- print "In OnPaint"
57+ print ( "In OnPaint" )
5958 # All that is needed here is to draw the buffer to screen
6059 dc = wx .PaintDC (self )
61- dc .DrawBitmap (self ._Buffer ,0 , 0 )
60+ dc .DrawBitmap (self ._Buffer , 0 , 0 )
6261 self .TempDraw (dc )
6362
64- def OnSize (self ,event ):
63+ def OnSize (self , event ):
6564 # The Buffer init is done here, to make sure the buffer is always
6665 # the same size as the Window
67- Size = self .GetClientSizeTuple ()
66+ Size = self .GetClientSize ()
6867
6968 # Make sure we don't try to create a 0 size bitmap
7069 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 ])
7271 self .UpdateDrawing ()
7372
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 )
7978
8079 def UpdateDrawing (self ):
8180 """
@@ -84,30 +83,31 @@ def UpdateDrawing(self):
8483 The idea here is that the drawing is based on some data generated
8584 elsewhere in the system. IF that data changes, the drawing needs to
8685 be updated.
87-
8886 """
8987
9088 # update the buffer
9189 dc = wx .MemoryDC ()
9290 dc .SelectObject (self ._Buffer )
9391 self .Draw (dc )
9492 # update the screen
95- wx .ClientDC (self ).DrawBitmap (self ._Buffer ,0 ,0 )
93+ wx .ClientDC (self ).DrawBitmap (self ._Buffer , 0 , 0 )
94+
9695
9796class DrawWindow (BufferedWindow ):
97+
9898 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.
102102 BufferedWindow .__init__ (self , parent , id )
103-
103+
104104
105105 self .Bind (wx .EVT_LEFT_DOWN , self .OnLeftDown )
106106 self .Bind (wx .EVT_LEFT_UP , self .OnLeftUp )
107107 self .Bind (wx .EVT_MOTION , self .OnMove )
108108
109109 self .StartMove = None
110-
110+
111111 self .overlay = wx .Overlay ()
112112
113113 def OnLeftDown (self , event ):
@@ -118,37 +118,37 @@ def OnLeftUp(self, event):
118118 if self .HasCapture ():
119119 self .ReleaseMouse ()
120120 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
128128 self .overlay .Reset ()
129129
130-
131130 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 ):
133134 pos = event .GetPosition ()
134- #self.Refresh()
135+ # self.Refresh()
135136 dc = wx .ClientDC (self )
136- odc = wx .DCOverlay ( self .overlay , dc )
137+ odc = wx .DCOverlay (self .overlay , dc )
137138 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.
139140 dc .SetPen (wx .Pen ('WHITE' , 2 ))
140141 dc .SetBrush (wx .TRANSPARENT_BRUSH )
141- dc .DrawLinePoint (self .StartMove , pos )
142+ dc .DrawLine (self .StartMove , pos )
142143 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
144147
145- del odc # to ensure it gets delted before the Client
146-
147148 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!
152152
153153 dc .SetPen (wx .RED_PEN )
154154 dc .SetBrush (wx .CYAN_BRUSH )
@@ -161,10 +161,10 @@ def __init__(self, *args, **kwargs):
161161 wx .Frame .__init__ (self , * args , ** kwargs )
162162 self .Window = DrawWindow (self )
163163
164+
164165class DemoApp (wx .App ):
165166 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 ))
168168 frame .Show (True )
169169
170170 self .SetTopWindow (frame )
0 commit comments