I'm using Python 2.6 with wxPython 2.8.12 to develop an application through BoaConstructor. I have an apply button programmed so that it will store some variables from TextCtrl's and then perform a self.Destroy() call on the dialog window to close it. When I click on this button, the GUI hangs and the application freezes. However, if I do not call self.Destroy(), I am able to store the variables without a problem until I try to close the window using the X button in the top right corner of the window (tested using print commands). If I do not try to store any variables but simply perform a self.Destroy() on the press of the button, everything is fine. It is only when I try to store variables and perform a self.Destroy() that the GUI hangs. Could any body lend a hand? Thanks in advance.
def OnApplyButton(self, event):
print self.IMSINumberDigitTextCtrl.GetValue()
if self.IMSINumberDigitCheckBox.GetValue() == True:
print self.IMSINumberDigit #Debugging purposes only. Returns expected value
print self.IMSINumberDigitTextCtrl.GetValue() #Debugging purposes only. Returns expected value
self.IMSINumberDigit = self.IMSINumberDigitTextCtrl.GetValue()
print self.IMSINumberDigit #Debugging purposes only. Returns expected value
self.Destroy()
Edit: this refers to Mike's suggestion. These are the two files for the smaller program I tested which worked flawlessly.
#!/usr/bin/env python
#Boa:App:BoaApp
import wx
import Frame1
modules = {'Frame1': [1, 'Main frame of Application', u'Frame1.py']}
class BoaApp(wx.App):
def OnInit(self):
self.main = Frame1.create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application = BoaApp(0)
application.MainLoop()
if __name__ == '__main__':
main()
And
#Boa:Frame:Frame1
import wx
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1APPLY, wxID_FRAME1CHECKBOX1, wxID_FRAME1CHECKBOX2,
wxID_FRAME1TEXTCTRL1,
] = [wx.NewId() for _init_ctrls in range(5)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(480, 245), size=wx.Size(279, 135),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(279, 135))
self.checkBox1 = wx.CheckBox(id=wxID_FRAME1CHECKBOX1, label='checkBox1',
name='checkBox1', parent=self, pos=wx.Point(24, 16),
size=wx.Size(95, 22), style=0)
self.checkBox1.Bind(wx.EVT_CHECKBOX, self.OnCheckBox1Checkbox,
id=wxID_FRAME1CHECKBOX1)
self.checkBox2 = wx.CheckBox(id=wxID_FRAME1CHECKBOX2, label='checkBox2',
name='checkBox2', parent=self, pos=wx.Point(48, 48),
size=wx.Size(95, 22), style=0)
self.checkBox2.Enable(False)
self.checkBox2.Bind(wx.EVT_CHECKBOX, self.OnCheckBox2Checkbox,
id=wxID_FRAME1CHECKBOX2)
self.Apply = wx.Button(id=wxID_FRAME1APPLY, label=u'Apply',
name=u'Apply', parent=self, pos=wx.Point(24, 88),
size=wx.Size(232, 29), style=0)
self.Apply.Bind(wx.EVT_BUTTON, self.OnApplyButton, id=wxID_FRAME1APPLY)
self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1',
parent=self, pos=wx.Point(160, 44), size=wx.Size(80, 27), style=0,
value='textCtrl1')
self.textCtrl1.SetEditable(True)
self.textCtrl1.Enable(False)
def __init__(self, parent):
self._init_ctrls(parent)
self.TextCtrlVariableHolder = None
def OnCheckBox1Checkbox(self, event):
value = self.checkBox1.GetValue()
if value == True:
self.checkBox2.Enable(True)
else:
self.checkBox2.Enable(False)
def OnCheckBox2Checkbox(self, event):
value = self.checkBox2.GetValue()
if value == True:
self.textCtrl1.Enable(True)
else:
self.textCtrl1.Enable(False)
def OnApplyButton(self, event):
print self.textCtrl1.GetValue()
if self.checkBox2.GetValue() == True:
print self.TextCtrlVariableHolder
print self.textCtrl1.GetValue()
self.TextCtrlVariableHolder = self.textCtrl1.GetValue()
print self.TextCtrlVariableHolder
self.Destroy()
Thanks!
Turns out the issue was my own coding, which I suspected all along but couldn't isolate. I had an infinite loop running due to the way in which I captured values. TextCtrls return strings, not ints. Who knew. So in the frame that the dialog was spawned from, i < "StringThatIThoughtWasAnINT" would never escape. Thanks for all your help though @MikeDriscoll!