]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-06/example1.py
   4 class SketchWindow(wx
.Window
): 
   5     def __init__(self
, parent
, ID
): 
   6         wx
.Window
.__init
__(self
, parent
, ID
) 
   7         self
.SetBackgroundColour("White") 
  10         self
.pen 
= wx
.Pen(self
.color
, self
.thickness
, wx
.SOLID
) 
  16         self
.Bind(wx
.EVT_LEFT_DOWN
, self
.OnLeftDown
) 
  17         self
.Bind(wx
.EVT_LEFT_UP
, self
.OnLeftUp
) 
  18         self
.Bind(wx
.EVT_MOTION
, self
.OnMotion
) 
  19         self
.Bind(wx
.EVT_SIZE
, self
.OnSize
) 
  20         self
.Bind(wx
.EVT_IDLE
, self
.OnIdle
) 
  21         self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
) 
  24         size 
= self
.GetClientSize() 
  25         #self.buffer = wx.EmptyBitmap(max(1, size.width), max(1, size.height)) 
  26         self
.buffer = wx
.EmptyBitmap(size
.width
, size
.height
) 
  28             dc 
= wx
.BufferedDC(None, self
.buffer) 
  29             dc
.SetBackground(wx
.Brush(self
.GetBackgroundColour())) 
  32             self
.reInitBuffer 
= False 
  34     def GetLinesData(self
): 
  37     def SetLinesData(self
, lines
): 
  42     def OnLeftDown(self
, event
): 
  44         self
.pos 
= event
.GetPositionTuple() 
  47     def OnLeftUp(self
, event
): 
  49             self
.lines
.append((self
.color
, 
  55     def OnMotion(self
, event
): 
  56         if event
.Dragging() and event
.LeftIsDown(): 
  57             dc 
= wx
.BufferedDC(wx
.ClientDC(self
), self
.buffer) 
  58             self
.drawMotion(dc
, event
) 
  61     def drawMotion(self
, dc
, event
): 
  63         newPos 
= event
.GetPositionTuple() 
  64         coords 
= self
.pos 
+ newPos
 
  65         self
.curLine
.append(coords
) 
  69     def OnSize(self
, event
): 
  70         self
.reInitBuffer 
= True 
  72     def OnIdle(self
, event
): 
  77     def OnPaint(self
, event
): 
  78         dc 
= wx
.BufferedPaintDC(self
, self
.buffer) 
  80     def DrawLines(self
, dc
): 
  81         for colour
, thickness
, line 
in self
.lines
: 
  82             pen 
= wx
.Pen(colour
, thickness
, wx
.SOLID
) 
  87     def SetColor(self
, color
): 
  89         self
.pen 
= wx
.Pen(self
.color
, self
.thickness
, wx
.SOLID
) 
  91     def SetThickness(self
, num
): 
  93         self
.pen 
= wx
.Pen(self
.color
, self
.thickness
, wx
.SOLID
) 
  96 class SketchFrame(wx
.Frame
): 
  97     def __init__(self
, parent
): 
  98         wx
.Frame
.__init
__(self
, parent
, -1, "Sketch Frame", 
 100         self
.sketch 
= SketchWindow(self
, -1) 
 102 if __name__ 
== '__main__': 
 103     app 
= wx
.PySimpleApp() 
 104     frame 
= SketchFrame(None)