1414import random
1515
1616
17- class DrawWindow (wx .Panel ):
17+ class DrawWindow (wx .Window ):
1818 def __init__ (self , parent , id = - 1 ):
1919 ## Any data the Draw() function needs must be initialized before
2020 ## calling BufferedWindow.__init__, as it will call the Draw
2121 ## function.
22- wx .Panel .__init__ (self , parent , id )
22+ wx .Window .__init__ (self , parent , id )
2323
2424 self .Bind (wx .EVT_LEFT_DOWN , self .OnLeftDown )
2525 self .Bind (wx .EVT_LEFT_UP , self .OnLeftUp )
@@ -43,7 +43,6 @@ def OnPaint(self, event):
4343 dc .SetPen (wx .Pen ('WHITE' , 2 , wx .SHORT_DASH ))
4444 dc .DrawLinePoint ( * self .mouse_line )
4545
46-
4746 def OnSize (self ,event ):
4847 # The Buffer init is done here, to make sure the buffer is always
4948 # the same size as the Window
@@ -89,37 +88,15 @@ def OnMove(self, event):
8988 if event .Dragging () and event .LeftIsDown () and (self .mouse_line is not None ):
9089 self .mouse_line [1 ] = event .GetPosition ()
9190 self .Refresh ()
92- self .Update ()
93-
94-
95- class TestFrame (wx .Frame ):
96- def __init__ (self ):
97- wx .Frame .__init__ (self , None , - 1 , "ClientDC Test" ,
98- wx .DefaultPosition ,
99- size = (500 ,500 ),
100- style = wx .DEFAULT_FRAME_STYLE | wx .NO_FULL_REPAINT_ON_RESIZE )
101-
102- self .Window = DrawWindow (self )
103-
104- class DemoApp (wx .App ):
105- def OnInit (self ):
106- wx .InitAllImageHandlers () # called so a PNG can be saved
107- frame = TestFrame ()
108- frame .Show (True )
109-
110- ## initialize a drawing
111- ## It doesn't seem like this should be here, but the Frame does
112- ## not get sized untill Show() is called, so it doesn't work if
113- ## it is put in the __init__ method.
114-
115- #frame.NewDrawing(None)
116-
117- self .SetTopWindow (frame )
91+ ## note: "Update() is not recommended on wxMac -- but response is slower without it... "
92+ #self.Update()
11893
119- return True
12094
12195if __name__ == "__main__" :
122- app = DemoApp (0 )
96+ app = wx .App (False )
97+ frame = wx .Frame (None , size = (400 ,500 ), title = "Mouse Move Drawing Test" )
98+ draw_window = DrawWindow (frame )
99+ frame .Show (True )
123100 app .MainLoop ()
124101
125102
0 commit comments