python.exe crashs when accesing combobox

Hi there,

I'm using:

Windows 7 32bit
Python3.3
wxPython_Phoenix-2.9.5.81-r73815-win32-py3.3.tar.gz

I've written a GUI program and have a strange behaviour, after I started and
finished a thread that performs the program tasks, python will crash if I
try to choose another value of a combobox. By choosing I mean clicking on
the drop-down arrow of the box, then selecting an item by clicking on it,
python will then crash immediately.
From the Windows event viewer I get:

Name der fehlerhaften Anwendung: python.exe, Version: 0.0.0.0, Zeitstempel:
0x5066b7a2
Name des fehlerhaften Moduls: USER32.dll, Version: 6.1.7601.17514,
Zeitstempel: 0x4ce7ba26
Ausnahmecode: 0xc0000005
Fehleroffset: 0x000360a9
ID des fehlerhaften Prozesses: 0x7c
Startzeit der fehlerhaften Anwendung: 0x01ce39cefea94087
Pfad der fehlerhaften Anwendung: C:\Python33\python.exe
Pfad des fehlerhaften Moduls: C:\Windows\system32\USER32.dll
Berichtskennung: 353efd5c-a5c4-11e2-8799-88ae1dacdfc1

Is this a known issue? Any ideas how to fix this?

I had the same issue with Python 2.7 and wxpython before :frowning:

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/python-exe-crashs-when-accesing-combobox-tp5716977.html
Sent from the wxPython-users mailing list archive at Nabble.com.

marco.hi wrote:

I've written a GUI program and have a strange behaviour, after I started and
finished a thread that performs the program tasks, python will crash if I
try to choose another value of a combobox. By choosing I mean clicking on
the drop-down arrow of the box, then selecting an item by clicking on it,
python will then crash immediately.
From the Windows event viewer I get:

[...]

Are you saying that Python crashes and produces an error message, or
your program crashes and Python prints a traceback?

Either way, it might be useful if we could look at your code, or if you
could produce an example app which replicates the same behaviour.

···

--
James Scholes
http://twitter.com/JamesScholes

No there's no Traceback, Python crashes and there pops up a windows error
message saying "python.exe has stopped working..."

Is there a way to get a traceback from windows for the crash?

I'll try to break the program down in a smaller piece but it may take a few
days as it's only a side project at work and I can't really invest a lot of
time at the moment :frowning:

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/python-exe-crashs-when-accessing-combobox-tp5716977p5716995.html
Sent from the wxPython-users mailing list archive at Nabble.com.

So I broke down the program to it's very essentials, looks a bit messy, but I
hope it will do it.

What you have to do to provoke the error, is tho click on the run test
button, then change the value in the combobox and python will crash,
sometimes you have to repeat it two or three times, till you get the error.
What I also found is that if you don't bind the EVT_KILL_FOCUS event to the
combobox the crash won't happen.

Any glue what's wrong here??

-----run.py start------
import init_functions as iFunc
import wx
import inspect
import sys

class Testautomatisierung_HDD_Update(wx.Frame):
  
    def __init__(self, parent, label, pos, size, frameno):
        iFunc.InitWidgetLists(self, frameno)
        wx.Frame.__init__(self, parent = parent, title = label, pos = pos,
size = size,
                         
style=wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX|wx.CLIP_CHILDREN)
        
        if frameno==0:
     
            self.Bind(wx.EVT_CLOSE, sys.exit)
            iFunc.OnInit(self, frameno)
  
    def OnButton(self, event):
        pass

    def OnCombo(self, event):
        pass
        
    def OnKillFocus(self, event):
        pass

def main():
    app = wx.App()
    frame = Testautomatisierung_HDD_Update(None, 'Test Tool', (100, 30),
(860, 531), 0)
    frame.Show()
    frame.SetFocus()
    app.MainLoop()

if __name__ == '__main__':
    main()

-----run.py end------
-----init_functions.py start------
import wx
        
def InitWidgetLists(self, frameno):
        
    if frameno == 0:
        self.panels = []
        self.buttons = []
        self.comboboxes = []
        self.notebooks = []
        
        for i in range(0, 100):
            self.panels.append(None)
            self.buttons.append(None)
            self.comboboxes.append(None)
            self.notebooks.append(None)
         
        self.aktstatus = None
    
def OnInit(self, frameno):
    if frameno == 0:
        PlaceTabInit(self, 0, 0, 'Main Menu')
        PlaceButton(self, 0, 20, 'Run Test', (30, 390),(100, 25),
'BTN_20_Run_Test')
        PlaceComboBox(self, 0, 1, choices = ['random', 'a', 'b'],
initvalue='random', pos=(175, 50), size=(140,20), name = 'CB_40_chose_map')
  
        self.SetFocus()

def PlaceComboBox(self, panelno, comboboxno, choices, initvalue, pos, size,
name):
    self.comboboxes[comboboxno] = wx.ComboBox(parent=self.panels[panelno],
choices=choices, pos = pos, size = size, name = name)
    self.comboboxes[comboboxno].SetSelection
    self.comboboxes[comboboxno].Value = initvalue
    self.comboboxes[comboboxno].Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus,
self.comboboxes[comboboxno])
    
def PlaceTabInit(self, frameno, notebookno, tabName):
    self.notebooks[notebookno] = wx.Notebook(parent = self)
    self.panels[0]= wx.Panel(self.notebooks[notebookno])
    self.panels[0].SetBackgroundColour('standard')
    self.notebooks[notebookno].AddPage(self.panels[0], tabName)

def PlaceButton(self, panelno, buttonno, label, pos, size, name):
    self.buttons[buttonno] = wx.Button(parent = self.panels[panelno], label
= label, pos = pos, size = size, name = name)
    self.buttons[buttonno].Bind(wx.EVT_BUTTON, self.OnButton,
self.buttons[buttonno])
-----init_functions.py end------

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/python-exe-crashs-when-accessing-combobox-tp5716977p5716996.html
Sent from the wxPython-users mailing list archive at Nabble.com.

marco.hi wrote:

So I broke down the program to it's very essentials, looks a bit messy, but I
hope it will do it.

What you have to do to provoke the error, is tho click on the run test
button, then change the value in the combobox and python will crash,
sometimes you have to repeat it two or three times, till you get the error.
What I also found is that if you don't bind the EVT_KILL_FOCUS event to the
combobox the crash won't happen.

Any glue what's wrong here??

Try calling event.Skip() in your EVT_KILL_FOCUS handler.

···

--
Robin Dunn
Software Craftsman

marco.hi wrote:

So I broke down the program to it's very essentials, looks a bit messy, but I
hope it will do it.

What you have to do to provoke the error, is tho click on the run test
button, then change the value in the combobox and python will crash,
sometimes you have to repeat it two or three times, till you get the error.
What I also found is that if you don't bind the EVT_KILL_FOCUS event to the
combobox the crash won't happen.

Any glue what's wrong here??

The problem is that you are aborting the event flow. Contrary to
intuition, if you want the normal event handling to continue after your
handler runs, you must call "event.Skip()" somewhere in your event
handler. Because you are not calling that, the processing of
EVT_KILL_FOCUS is terminated immediately, after doing nothing. That
means the standard event handling never runs, so the system can't
complete the change of focus. That is apparently causing the UI state
information to get trashed.

Now, I'm not saying you should have expected this result, but that's
what is triggering it. Add event.Skip() to all of your event handlers,
and all will be well.

If I had been designing wxWidgets, I would have inverted the sense of
that call, because you usually DO want the ancestor handlers to do their
thing, but I wasn't around then.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Okay normally my Code
def OnKillFocus(self, event):
        pass

looks like this:

def OnKillFocus(self, event):
        if event.name=='x':
            do this
        elif event.name=='y':
            do that

do I have to add the event.Skip() after each do... or only as final

else:
   event.Skip()

?

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/python-exe-crashs-when-accessing-combobox-tp5716977p5717006.html
Sent from the wxPython-users mailing list archive at Nabble.com.

marco.hi wrote:

Okay normally my Code
def OnKillFocus(self, event):
         pass

looks like this:

def OnKillFocus(self, event):
         if event.name=='x':
             do this
         elif event.name=='y':
             do that

do I have to add the event.Skip() after each do... or only as final

else:
    event.Skip()

It doesn't matter, as long as it is called at least once. It just sets a flag that is checked upon return from the event handler, so you could even call it before doing anything else.

···

--
Robin Dunn
Software Craftsman