#Boa:Frame:MainFrame
"""
Python GUI Calculator
by Jia-Yang Chen (JAYA)
email: jia.yang.chen@gmail.com
school: TTU
date: 2006/10/09
"""
import wx
def create(parent):
return MainFrame(parent)
[wxID_MAINFRAME, wxID_MAINFRAMEADD, wxID_MAINFRAMEANS, wxID_MAINFRAMEDIV,
wxID_MAINFRAMEEIGHT, wxID_MAINFRAMEEQU, wxID_MAINFRAMEFINISH,
wxID_MAINFRAMEFIVE, wxID_MAINFRAMEFOUR, wxID_MAINFRAMEMUL,
wxID_MAINFRAMENINE, wxID_MAINFRAMEONE, wxID_MAINFRAMERESET,
wxID_MAINFRAMESEVEN, wxID_MAINFRAMESIX, wxID_MAINFRAMESTATUS,
wxID_MAINFRAMESUB, wxID_MAINFRAMETHREE, wxID_MAINFRAMETWO,
wxID_MAINFRAMEZERO,
] = [wx.NewId() for _init_ctrls in range(20)]
class MainFrame(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_MAINFRAME, name=u'MainFrame',
parent=prnt, pos=wx.Point(381, 128), size=wx.Size(288, 281),
style=wx.SYSTEM_MENU | wx.CAPTION, title=u'\u8a08\u7b97\u6a5f')
self.SetClientSize(wx.Size(280, 254))
self.SetToolTipString(u'\u8a08\u7b97\u6a5f')
self.one = wx.Button(id=wxID_MAINFRAMEONE, label=u'1', name=u'one',
parent=self, pos=wx.Point(16, 56), size=wx.Size(75, 24), style=0)
self.one.Bind(wx.EVT_BUTTON, self.OnOneButton, id=wxID_MAINFRAMEONE)
self.two = wx.Button(id=wxID_MAINFRAMETWO, label=u'2', name=u'two',
parent=self, pos=wx.Point(104, 56), size=wx.Size(75, 24),
style=0)
self.two.Bind(wx.EVT_BUTTON, self.OnTwoButton, id=wxID_MAINFRAMETWO)
self.three = wx.Button(id=wxID_MAINFRAMETHREE, label=u'3',
name=u'three', parent=self, pos=wx.Point(192, 56),
size=wx.Size(75, 24), style=0)
self.three.Bind(wx.EVT_BUTTON, self.OnThreeButton,
id=wxID_MAINFRAMETHREE)
self.four = wx.Button(id=wxID_MAINFRAMEFOUR, label=u'4', name=u'four',
parent=self, pos=wx.Point(16, 96), size=wx.Size(75, 24), style=0)
self.four.Bind(wx.EVT_BUTTON, self.OnFourButton, id=wxID_MAINFRAMEFOUR)
self.five = wx.Button(id=wxID_MAINFRAMEFIVE, label=u'5', name=u'five',
parent=self, pos=wx.Point(104, 96), size=wx.Size(75, 24),
style=0)
self.five.Bind(wx.EVT_BUTTON, self.OnFiveButton, id=wxID_MAINFRAMEFIVE)
self.six = wx.Button(id=wxID_MAINFRAMESIX, label=u'6', name=u'six',
parent=self, pos=wx.Point(192, 96), size=wx.Size(75, 24),
style=0)
self.six.Bind(wx.EVT_BUTTON, self.OnSixButton, id=wxID_MAINFRAMESIX)
self.seven = wx.Button(id=wxID_MAINFRAMESEVEN, label=u'7',
name=u'seven', parent=self, pos=wx.Point(16, 136),
size=wx.Size(75, 24), style=0)
self.seven.Bind(wx.EVT_BUTTON, self.OnSevenButton,
id=wxID_MAINFRAMESEVEN)
self.eight = wx.Button(id=wxID_MAINFRAMEEIGHT, label=u'8',
name=u'eight', parent=self, pos=wx.Point(104, 136),
size=wx.Size(75, 24), style=0)
self.eight.Bind(wx.EVT_BUTTON, self.OnEightButton,
id=wxID_MAINFRAMEEIGHT)
self.nine = wx.Button(id=wxID_MAINFRAMENINE, label=u'9', name=u'nine',
parent=self, pos=wx.Point(192, 136), size=wx.Size(75, 24),
style=0)
self.nine.Bind(wx.EVT_BUTTON, self.OnNineButton, id=wxID_MAINFRAMENINE)
self.zero = wx.Button(id=wxID_MAINFRAMEZERO, label=u'0', name=u'zero',
parent=self, pos=wx.Point(16, 176), size=wx.Size(75, 24),
style=0)
self.zero.Bind(wx.EVT_BUTTON, self.OnZeroButton, id=wxID_MAINFRAMEZERO)
self.ans = wx.TextCtrl(id=wxID_MAINFRAMEANS, name=u'ans', parent=self,
pos=wx.Point(48, 16), size=wx.Size(216, 22),
style=wx.TE_RIGHT | wx.TE_READONLY, value=u'0.0')
self.ans.SetToolTipString(u'')
self.ans.SetInsertionPoint(0)
self.add = wx.Button(id=wxID_MAINFRAMEADD, label=u'+', name=u'add',
parent=self, pos=wx.Point(16, 216), size=wx.Size(40, 24),
style=0)
self.add.Bind(wx.EVT_BUTTON, self.OnAddButton, id=wxID_MAINFRAMEADD)
self.sub = wx.Button(id=wxID_MAINFRAMESUB, label=u'-', name=u'sub',
parent=self, pos=wx.Point(64, 216), size=wx.Size(40, 24),
style=0)
self.sub.Bind(wx.EVT_BUTTON, self.OnSubButton, id=wxID_MAINFRAMESUB)
self.mul = wx.Button(id=wxID_MAINFRAMEMUL, label=u'*', name=u'mul',
parent=self, pos=wx.Point(120, 216), size=wx.Size(40, 24),
style=0)
self.mul.Bind(wx.EVT_BUTTON, self.OnMulButton, id=wxID_MAINFRAMEMUL)
self.div = wx.Button(id=wxID_MAINFRAMEDIV, label=u'/', name=u'div',
parent=self, pos=wx.Point(176, 216), size=wx.Size(40, 24),
style=0)
self.div.Bind(wx.EVT_BUTTON, self.OnDivButton, id=wxID_MAINFRAMEDIV)
self.equ = wx.Button(id=wxID_MAINFRAMEEQU, label=u'=', name=u'equ',
parent=self, pos=wx.Point(224, 216), size=wx.Size(40, 24),
style=0)
self.equ.Bind(wx.EVT_BUTTON, self.OnEquButton, id=wxID_MAINFRAMEEQU)
self.reset = wx.Button(id=wxID_MAINFRAMERESET, label=u'CLS',
name=u'reset', parent=self, pos=wx.Point(104, 176),
size=wx.Size(75, 24), style=0)
self.reset.Bind(wx.EVT_BUTTON, self.OnResetButton,
id=wxID_MAINFRAMERESET)
self.finish = wx.Button(id=wxID_MAINFRAMEFINISH, label=u'Exit',
name=u'finish', parent=self, pos=wx.Point(192, 176),
size=wx.Size(75, 24), style=0)
self.finish.Bind(wx.EVT_BUTTON, self.OnFinishButton,
id=wxID_MAINFRAMEFINISH)
self.status = wx.StaticText(id=wxID_MAINFRAMESTATUS, label=u'CLS',
name=u'status', parent=self, pos=wx.Point(16, 16),
size=wx.Size(20, 14), style=0)
self.status.SetToolTipString(u'')
def __init__(self, parent):
self.num = 0.0
self.answer = 0.0
self.input = 0
self._init_ctrls(parent)
def OnOneButton(self, event):
if self.input == 0:
self.num = 0.0
self.input = 1
self.num = 10 * self.num + 1.0
self.ans.SetValue(str(self.num))
def OnTwoButton(self, event):
if self.input == 0:
self.num = 0.0
self.input = 1
self.num = 10 * self.num + 2.0
self.ans.SetValue(str(self.num))
def OnFinishButton(self, event):
self.Close()
def OnThreeButton(self, event):
if self.input == 0:
self.num = 0.0
self.input = 1
self.num = 10 * self.num + 3.0
self.ans.SetValue(str(self.num))
def OnFourButton(self, event):
if self.input == 0:
self.num = 0.0
self.input = 1
self.num = 10 * self.num + 4.0
self.ans.SetValue(str(self.num))
def OnFiveButton(self, event):
if self.input == 0:
self.num = 0.0
self.input = 1
self.num = 10 * self.num + 5.0
self.ans.SetValue(str(self.num))
def OnSixButton(self, event):
if self.input == 0:
self.num = 0.0
self.input = 1
self.num = 10 * self.num + 6.0
self.ans.SetValue(str(self.num))
def OnSevenButton(self, event):
if self.input == 0:
self.num = 0.0
self.input = 1
self.num = 10 * self.num + 7.0
self.ans.SetValue(str(self.num))
def OnEightButton(self, event):
if self.input == 0:
self.num = 0.0
self.i