Subclassing ComboTreeBox + XRC suggestion

Hello,

in order to make the ComboTreeBox class work with xrc I try to create a subclass of ComboTreeBox in my module. I do this with this code:

import wx.lib.combotreebox
class ComboTreeBox(wx.lib.combotreebox.ComboTreeBox):
     pass

However, this fails with

   File "D:\kerama\Client\Sources\GUI\Presenters\DefaultPresenter.py", line 138, in ?
     class ComboTreeBox(wx.lib.combotreebox.ComboTreeBox):
exceptions.TypeError: Error when calling the metaclass bases
     function() argument 1 must be code, not str

I have no idea what's happening here. Any clue?

I also suggest a little patch for the xrc module:

def _my_import(name):
     try:
         mod = __import__(name)
     except ImportError:
         import traceback
         print traceback.format_exc()

     components = name.split('.')

This gives much better feedback what exactly went wrong. The current message only says that the subclassing did not work. The print could be substituted with a message box of course.

-Matthias

def _my_import(name):
     try:
         mod = __import__(name)
     except ImportError:
         import traceback
         print traceback.format_exc()

forgot to add a 'raise' here.

···

     components = name.split('.')

Nitro:

Hello,

in order to make the ComboTreeBox class work with xrc I try to create a subclass of ComboTreeBox in my module. I do this with this code:

import wx.lib.combotreebox
class ComboTreeBox(wx.lib.combotreebox.ComboTreeBox):
    pass

The problem is that wx.lib.combotreebox.ComboTreebox is not a class, but a factory function that creates the right ComboTreeBox depending on platform. Depending on what you want to achieve there are different options I can think of, the easiest of which is probably to not subclass, but use delegation. For example:

class MyComboTreeBox(wx.Panel):
     def __init__(self, *args, **kwargs):
         self._box = wx.lib.combotreebox.ComboTreeBox(self)
         ...

If you feel bold, you may even want to use __getattr__ to delegate stuff to the ComboTreeBox automatically, e.g;

     def __getattr__(self, attr):
         return getattr(self._box, attr)

Cheers, Frank