rendered paste bodyimport wx, random
APP_SIZE_X = 300
APP_SIZE_Y = 200
class MyButtons(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, size=(APP_SIZE_X, APP_SIZE_Y))
#wx.Button(self, 1, 'Close', (200, 130))
#wx.Button(self, 2, 'Random Move', (150, 130), (110, -1))
sizer = wx.BoxSizer(wx.VERTICAL)
self.display = wx.TextCtrl(self, -1, '', style=wx.TE_RIGHT)
sizer.Add(self.display, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 4)
row = 0
x = 0
for i in range(0,9):
if i % 3 == 0:
row += 1
x = 0
x += 30
print "%i, %i" % (i, row)
wx.Button(self, i, str(i), (x, 30*row), (30,30))
wx.Button(self, 11, "+", (30*4, 30*row), (30,30))
wx.Button(self, 12, "-", (30*4, (30*row)-30), (30,30))
wx.Button(self, 13, "=", (30*4, (30*row)-30*2), (30,30))
self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
#self.Bind(wx.EVT_BUTTON, self.OnRandomMove, id=2)
for i in range(0,9):
self.Bind(wx.EVT_BUTTON, self.ButtonPressed, id=i)
self.Bind(wx.EVT_BUTTON, self.ButtonPressed, id=11)
self.Bind(wx.EVT_BUTTON, self.ButtonPressed, id=12)
self.Bind(wx.EVT_BUTTON, self.ButtonPressed, id=13)
self.Centre()
self.ShowModal()
self.Destroy()
def ButtonPressed(self, event):
txt = event.GetId() # id = number of button :\
if txt == 13:
# equals
eq = self.display.GetValue()
self.display.Clear()
self.display.AppendText( str(eval(eq)) )
return
if txt == 11: txt = "+"
if txt == 12: txt = "-"
self.display.AppendText( str(txt) )
#print "txt:", txt
def OnClose(self, event):
for e in dir(event):
print "dir:", e
print "e:", event.GetClientData()
#self.Close(True)
def OnRandomMove(self, event):
screensize = wx.GetDisplaySize()
randx = random.randrange(0, screensize.x - APP_SIZE_X)
randy = random.randrange(0, screensize.y - APP_SIZE_Y)
self.Move((randx, randy))
app = wx.App(0)
MyButtons(None, -1, 'calc, faith ;)')
app.MainLoop()