Home > other >  Error AttributeError: 'MouseEvent object has no attribute' GetPositionTuple '
Error AttributeError: 'MouseEvent object has no attribute' GetPositionTuple '

Time:09-27

 
The class PaintWindow (wx. Windows) :
Def __init__ (self, parent, id) :
Wx. Window. __init__ (self, parent, id)
Self. SetBackgroundColour (" White ")
The self. The color="Black"
The self. The thickness=10

Create a brush #
The self. The pen=wx. Pen (self. The color, the self. The thickness, wx. SOLID)
Self. Lines=[]
Self. CurLine=[]
Self. Pos=(0, 0)
Self. InitBuffer ()

# connect events
The self. The Bind (wx. EVT_LEFT_DOWN, self. OnLeftDown)
The self. The Bind (wx. EVT_LEFT_UP, self. OnLeftUp)
The self. The Bind (wx. EVT_MOTION, self. OnMotion)
The self. The Bind (wx. EVT_SIZE, self. OnSize)
The self. The Bind (wx. EVT_IDLE, self. OnIdle)
The self. The Bind (wx. EVT_PAINT, self. OnPaint)

Def InitBuffer (self) :
Size=self. GetClientSize ()

# to create the cache of the device context
Self. Buffer=wx. Bitmap (size, width, the size height)
Dc wx. BufferedDC (None, the self. The buffer)

# use device context
Dc. SetBackground (wx. Brush (self GetBackgroundColour ()))
Dc. The Clear ()
Self. DrawLines (dc)
Self. ReInitBuffer=False

Def GetLinesData (self) :
Return the self. Lines [:]

Def SetLinesData (self, lines) :
Self. Lines=lines [:]
Self. InitBuffer ()
The self. The Refresh ()

Def OnLeftDown (self, event) :
Self. CurLine=[]
The self. The pos=event. GetPositionTuple ()
Self. CaptureMouse ()

Def OnLeftUp (self, event) :
If self. HasCapture () :
Self. Lines. Append ((self color,
The self. The thickness,
Self. CurLine))
Self. CurLine=[]
Self. ReleaseMouse ()

Def OnMotion (self, event) :
If the event. Dragging () and event. LeftIsDown () :
Dc wx. BufferedDC (wx. ClientDC (self), the self. The buffer)
Self. DrawMotion (dc, event)
Event. The Skip ()

Def drawMotion (self, dc, the event) :
Dc. SetPen (self. The pen)
NewPos=event. GetPositionTuple ()
Print (newPos)
Coords=self. Pos + newPos
Self. CurLine. Append (coords)
Dc. DrawLine (* coords)
The self. The pos=newPos

Def OnSize (self, event) :
Self. ReInitBuffer=True

Def OnIdle (self, event) :
If self. ReInitBuffer:
Self. InitBuffer ()
Self. Refresh (False)

Def OnPaint (self, event) :
Dc wx. BufferedPaintDC (self, self. Buffer)

Def DrawLines (self, dc) :
For see, thickness, the line in the self. The lines:
Pen=wx. Pen (see colour, thickness, wx. SOLID)
Dc. SetPen (pen)
For coords in line:
Dc. DrawLine (* coords)

Def SetColor (self, color) :
The self. The color=color
The self. The pen=wx. Pen (self. The color, the self. The thickness, wx. SOLID)

Def SetThickness (self, num) :
The self. The thickness=num
The self. The pen=wx. Pen (self. The color, the self. The thickness, wx. SOLID)

Want to use the wxpython drawing functions, but hint for less than the location of the mouse array, but GetPosition is still can call, how to solve this situation?
  • Related