0

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!

ballade4op52
  • 2,142
  • 5
  • 27
  • 42
  • Can you provide a small runnable example of this behavior? And what wxPython version and OS are you using? – Mike Driscoll Aug 28 '12 at 19:18
  • Hey @MikeDriscoll thanks for your reply. I just tried your suggestion and it worked no problem. The issue in my real program still stands however. I am using wxPython 2.8.12 on CentOS 6.2. This program in question which fails has 62 GUI components. Could the shear amount of components be causing wxPython to fail when it tries to close the frame? The code below replicates the bigger App on a smaller scale. – Stanley Switalski Aug 28 '12 at 19:55
  • Not likely. I've had GUIs with more widgets than that. Are you using threads? Are you leaving file handles open? Do you need to close database connections? Why are you Destroying instead of Closing? – Mike Driscoll Aug 28 '12 at 21:03
  • @MikeDriscoll I am using threads but not in this case. This window was launched from the main thread. I'm not sure what file handles are actually but I don't think so? No database connections to close and I'm destroying because I didn't know there was a way to close. Not necessarily a programmer by trade but I was assigned a task which required programming so I apologize if I don't really seem to know what I'm talking about. – Stanley Switalski Aug 29 '12 at 12:06
  • File handles are when you open a file and manipulate the data but you don't close them. How can you use threads and not use them? If you are using threads in your application and not calling join() in the close method, then your threads are probably hanging. – Mike Driscoll Aug 29 '12 at 13:26
  • @MikeDriscoll Ah ok then yes in that case I am using File Handles and I am not leaving them open. At this point in the program when the GUI Hangs, I do not have any threads running. The action I am trying to perform, I would like to think, is identical to the action in my full program. If I do not read the value from a TextCtrl, I can call self.Destroy() no problem. Once I read the value from a TextCtrl, it is only then that self.Destroy() will cause the app to freeze. What's funny is that I've used this same method for other windows without issues. Greatly appreciate your help nonetheless. – Stanley Switalski Aug 29 '12 at 14:47
  • @MikeDriscoll I found something interesting after taking a look at the system logs. Once the GUI hangs, it start's to eat memory until it runs out of memory. Also, interestingly enough the program will hang regardless of whether or not I capture data from the GUI now. I'm going to still look into this issue but it was something to add to the case. – Stanley Switalski Aug 29 '12 at 16:22

1 Answers1

0

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!