Deriving from ListBox and ComboPopup

I want to create a comboctrl with a listbox as the popup widget. The
problem is with the class MyPopup that derives from wx.ListBox and
wx.combo.ComboPopup. When running the code I get the following
exception :

TypeError: in method 'ComboPopup__setCallbackInfo', expected argument
1 of type 'wxPyComboPopup *'

the problem seems to be this line in the class MyPopup:
self.PostCreate(wx.PreListBox())

I'm pretty new to wxPython and python (but loving it!) so it is
probably something obvious that I am missing.

Here is the sample code :

### Sample code demonstrating the problem
# -*- coding: latin-1 -*-

import wx
import wx.combo

class TestApp(wx.App):
    def OnInit(self):
        frmConsultation = wx.Frame(None, size=(200, -1))
        cb = wx.combo.ComboCtrl(frmConsultation, -1)
        cb.SetPopupMaxHeight(150)
# popup = ListBoxComboPopup() # This line works
        popup = MyPopup() # This one causes the problem
        cb.SetPopupControl(popup)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(cb, 0, wx.EXPAND)
        frmConsultation.SetSizer(sizer)
        frmConsultation.SetAutoLayout(True)
        sizer.Fit(frmConsultation)
        frmConsultation.Show(True)
        self.SetTopWindow(frmConsultation)
        return True

class ListBoxComboPopup(wx.combo.ComboPopup):

    def Create(self, parent):
        print 'create'
        self.list = wx.ListBox(parent)
        return True

    def GetControl(self):
        return self.list

class MyPopup(wx.ListBox, wx.combo.ComboPopup):
    def __init__(self, *args, **kwargs):
        self.PostCreate(wx.PreListBox())
        wx.combo.ComboPopup.__init__(self)

    def Create(self, parent):
        wx.ListBox.Create(self, parent)
        return True

    def GetControl(self):
        return self

app = TestApp(0)
app.MainLoop()

### End of sample code

Fred

The current wxPython Demo has a working sample for what you want to do.
Look for "ListCtrl"; one of the ListCtrl samples uses wxComboPopup, wxListCtrl and
wxComboCtrl.

hannes

Fred Mark schrieb:

···

I want to create a comboctrl with a listbox as the popup widget. The
problem is with the class MyPopup that derives from wx.ListBox and
wx.combo.ComboPopup. When running the code I get the following
exception :

TypeError: in method 'ComboPopup__setCallbackInfo', expected argument
1 of type 'wxPyComboPopup *'

the problem seems to be this line in the class MyPopup:
self.PostCreate(wx.PreListBox())

I'm pretty new to wxPython and python (but loving it!) so it is
probably something obvious that I am missing.

Here is the sample code :

### Sample code demonstrating the problem
# -*- coding: latin-1 -*-

import wx
import wx.combo

class TestApp(wx.App):
   def OnInit(self):
       frmConsultation = wx.Frame(None, size=(200, -1))
       cb = wx.combo.ComboCtrl(frmConsultation, -1)
       cb.SetPopupMaxHeight(150)
# popup = ListBoxComboPopup() # This line works
       popup = MyPopup() # This one causes the problem
       cb.SetPopupControl(popup)

       sizer = wx.BoxSizer(wx.VERTICAL)
       sizer.Add(cb, 0, wx.EXPAND)
       frmConsultation.SetSizer(sizer)
       frmConsultation.SetAutoLayout(True)
       sizer.Fit(frmConsultation)
       frmConsultation.Show(True)
       self.SetTopWindow(frmConsultation)
       return True

class ListBoxComboPopup(wx.combo.ComboPopup):

   def Create(self, parent):
       print 'create'
       self.list = wx.ListBox(parent)
       return True

   def GetControl(self):
       return self.list

class MyPopup(wx.ListBox, wx.combo.ComboPopup):
   def __init__(self, *args, **kwargs):
       self.PostCreate(wx.PreListBox())
       wx.combo.ComboPopup.__init__(self)

   def Create(self, parent):
       wx.ListBox.Create(self, parent)
       return True

   def GetControl(self):
       return self

app = TestApp(0)
app.MainLoop()

### End of sample code

Fred

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Fred Mark wrote:

I want to create a comboctrl with a listbox as the popup widget. The
problem is with the class MyPopup that derives from wx.ListBox and
wx.combo.ComboPopup. When running the code I get the following
exception :

TypeError: in method 'ComboPopup__setCallbackInfo', expected argument
1 of type 'wxPyComboPopup *'

the problem seems to be this line in the class MyPopup:
self.PostCreate(wx.PreListBox())

I'm pretty new to wxPython and python (but loving it!) so it is
probably something obvious that I am missing.

Nope it's a bug. (If you don't want the gory details then skip to the next paragraph...) Basically it's because of the multiple inheritance. The instance has a _setCallbackInfo method from ComboPopup, but the wx.ListBox doesn't have one, so when it is checked for and called on the listbox part of the instance it is calling the one for wx.ComboPopup and resulting in this error. It doesn't have this problem in the demo because wx.ListCtrl does have a _setCallbackInfo method.

I'll get this fixed, but for now you'll want to just use the has-a relationship instead of is-a (multiple inheritance.) Or you can try catching and ignoring this exception.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!