Search code examples
pythonwxpythonwxformbuilder

wxformbuilder python generated code throws NameError


Not sure if the background is relevant, but I'll include it in the eventuality

I'm moving from wxglade, so I generated a XRC from wxglade and imported in wxformbuilder

I have a grid that I subclass to add some functionality, in wxformbuilder it shows the grid correctly and the subclass propriety is also correct (mygrid.MyGrid)

but the generated code of course doesn't import mygrid as it should, so when running it it throws:

NameError: global name 'mygrid' is not defined

is this a bug or am I doing something wrong? any workarounds?


Solution

  • ok, found an ugly workaround that seems to work

    basically I manually add the reference to the module global dictionay:
    in the example the code is generated in the file gui.py and my class is inside the file mygrid.py

    import mygrid
    import gui
    import sys
    setattr(sys.modules["gui"], "mygrid", mygrid)