import wx
class circle():
def __init__(self, posX, posY, radius):
self.posX = posX
self.posY = posY
self.radius = radius
class Shapes(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(350, 300))
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_LEFT_DOWN, self.leftClickDown)
self.Bind(wx.EVT_LEFT_UP,self.leftClickUp)
self.eventInfo = {}
self.eventInfo['leftClickDown'] = False
self.cir = {}
self.count = 0
self.count+= 1
self.Centre()
self.Show(True)
def leftClickUp(self,event):
if( self.eventInfo['leftClickDown'] == False):
return
x, y = event.GetPosition()
if(x == self.eventInfo['xPos'] and y== self.eventInfo['yPos']):
del self.cir[self.eventInfo['key']]
else:
self.cir[self.eventInfo['key']].posX= x
self.cir[self.eventInfo['key']].posY = y
self.Refresh()
def leftClickDown(self, event):
self.eventInfo ={}
self.eventInfo['leftClickDown'] = False
x, y = event.GetPosition()
print "Pos: " + str(x) + ", " + str(y)
for key in self.cir:
theCir = self.cir[key]
print "\t" + str(theCir.posX) + " " + str(theCir.posY)
if(x >= theCir.posX and x <= theCir.posX + 60 and
y >= theCir.posY and y <= theCir.posY+ 60):
self.eventInfo['leftClickDown'] = True
self.eventInfo['key'] = key
self.eventInfo['xPos'] = x
self.eventInfo['yPos'] = y
return
self.cir[self.count] = circle(x-30, y-30, 60)
self.flaggedKey = False
self.count += 1
self.Refresh()
def OnPaint(self, event):
dc = wx.PaintDC(self)
for key in self.cir:
theCir = self.cir[key]
dc.DrawRectangle(theCir.posX, theCir.posY, theCir.radius, theCir.radius)app = wx.App()
Shapes(None, -1, 'Shapes')
app.MainLoop()