Exception when Generating Code from wxGlade – and how to fix it

This morning I started getting the following exception when generating code from wxGlade:

Traceback (most recent call last):
  File "c:\temp\wxGlade\application.py", line 394, in generate_code
  File "c:\temp\wxGlade\xml_parse.py", line 503, in __init__
  File "c:\temp\wxGlade\xml_parse.py", line 593, in endElement
  File "c:\temp\wxGlade\codegen\py_codegen.py", line 640, in add_class
    indentation = prev_src.spaces[code_obj.klass]
KeyError: 'FancyListControl'

There was only one mention of a similar problem on the wxGlade mailing list. The solution posted there was to start a new project – not really an option at this stage of development.

So after a little digging, I found a different solution.

The item causing the problem is a fancy subclass of ListControl defined in another module. I had placed a wx.Panel in the sizer slot, and had then changed the class to my fancy ListControl. Is the problem now obvious? This fancy list control is not equivalent to a wx.Panel from wxGlade’s perspective. Removing the panel and instead adding a ListControl with my fancy control as the class name fixed everything up.

So, in summary, use the closest matching wxGlade class (ListControl instead of Panel) when using your own classes.


This entry was posted in wxPython. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *