Custom tag handler for HTMLListBox?

I'm trying to use a custom tag handler along with a wx.HtmlListBox
in a way that I can put some wx.BitmapButtons right on the item
in the list box... heck, why not?

The code does not work if I un-comment the (near the bottom)
            #self.GetParser().GetContainer().InsertCell(
            # wx.html.HtmlWidgetCell(button, 0))

class MyTagHandler(wx.html.HtmlWinTagHandler):
    def __init__(self):
        wx.html.HtmlWinTagHandler.__init__(self)

    def GetSupportedTags(self):
        return "MARBLE"

···

#

    def HandleTag(self, tag):
        bmp = wx.EmptyBitmap(16,16)
        container = self.GetParser().GetContainer()
        parent = self.GetParser().GetWindowInterface().GetHTMLWindow()
        if parent:
            button = wx.BitmapButton(parent, -1, bmp, size=(18, 18),
                 style = wx.NO_BORDER)
            # add it to the HtmlWindow
            #self.GetParser().GetContainer().InsertCell(
            # wx.html.HtmlWidgetCell(button, 0))
            button.Show(True)
        return True
    #
#
wx.html.HtmlWinParser_AddTagHandler(MyTagHandler)

The HTML list box itself is inserting the appropriate HTML for each
item in the list...

When I do uncomment the InsertCell call... the Application quits as soon as it
starts. I think it's crashing.

I do know that the TagHandler is being called when the htmlListBox
__init__ does a self.SetItemCount(len(self.marbles))

Any ideas? Is this even remotely possible?
Thanks,
Jim

I'm trying to use a custom tag handler along with a wx.HtmlListBox
in a way that I can put some wx.BitmapButtons right on the item
in the list box... heck, why not?

Here's the simplest example that shows the problem:
commenting out the import wx.lib.wxpTag, or any of the
html snippets that returns a <wxp tag makes it work again.

import wx
import wx.html

import wx.lib.wxpTag

class LogList(wx.HtmlListBox):
    def __init__(self, *args, **kwargs):
        wx.HtmlListBox.__init__(self, *args, **kwargs)
        
        self.logs = ['One', 'Two', 'Three', 'Four', 'Five']
        
        self.SetItemCount(len(self.logs))

        self.SetMarginsXY(4, 4)
        self.Bind(wx.EVT_LISTBOX, self.OnListbox)

···

#

    def OnListbox(self, event):
        wx.MessageBox("we got the listbox select event %s " % event)
    #
    
    def OnGetItem(self, item):
        """ Create HTML for this list item """
        b = ''' <wxp module="wx" class="Button" width="50%">
                <param name="label" value="It works!">
                <param name="id" value="ID_OK">
                </wxp>'''
        #return b
        return '%s <WXP module="wx" class="Button"> </WXP>' % item
        #return '%s' % item
    #
#

def test_ctrl():
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, "Testing html List")
    
    ll = LogList(frame)
    
    vert = wx.BoxSizer(wx.VERTICAL)
    vert.Add(ll, 1, wx.EXPAND|wx.ALL, 10)
    frame.SetSizer(vert)
    
    frame.Show()
    app.MainLoop()
#

if __name__ == "__main__":
    test_ctrl()
#

Jim Carroll wrote:

I'm trying to use a custom tag handler along with a wx.HtmlListBox
in a way that I can put some wx.BitmapButtons right on the item
in the list box... heck, why not?

Here's the simplest example that shows the problem:
commenting out the import wx.lib.wxpTag, or any of the
html snippets that returns a <wxp tag makes it work again.

The wxHtmlWidgetCell has some code that requires that the widget be placed on a wxScrolledWindow (which is the base class of wxHtmlWindow.) See the wxHtmlWidgetCell::Draw method at http://svn.wxwidgets.org/viewvc/wx/wxWidgets/branches/WX_2_8_BRANCH/src/html/htmlcell.cpp?view=markup

···

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