Can't override OnCreateStatusBar for wxFrame

I wanted to create a custom status for my frame but I couldn't get it to work. I've stripped it down to the code below. Docs say if you override OnCreateStatusBar method of wx.Frame it will get called and you can return your custom status bar instance. Am I doing something wrong, or is this a bug?

Thanks in advance.
Larry

import wx
import time

class CustomStatusBar(wx.StatusBar):
     def __init__(self, parent):
         wx.StatusBar.__init__(self, parent, -1)
         self.SetFieldsCount(2)
         print "CustomStatusBar, setting StatusWidths"
         self.SetStatusWidths([570, 70])

class TestFrame(wx.Frame):
     def __init__(self):
         wx.Frame.__init__(self, None, -1)
         self.SetSize((640, 480))
         self.CreateStatusBar(1)
         b = wx.Button(self, -1, "Start demo", (50,50))
         self.Bind(wx.EVT_BUTTON, self.demo, b)

     def demo(self, event):
         CSB=self.GetStatusBar()
         for i in xrange(20):
             print "setting value=%i" % (i+1)
             CSB.SetStatusText("%i" % (i+1), 1)
             time.sleep(.2)

     def OnCreateStatusBar(self, *args, **kwds):
         print "OnCreateStatusBar-Entering"
         return CustomStatusBar(self)

if __name__ == "__main__":
     app = wx.App(0)
     f = TestFrame()
     f.Show()
     app.MainLoop()

Larry Bates <larry.bates <at> websafe.com> writes:

I wanted to create a custom status for my frame but I couldn't
get it to work.
I've stripped it down to the code below. Docs say if you override
OnCreateStatusBar method of wx.Frame it will get called and you
can return your custom status bar instance. Am I doing something
wrong, or is this a bug?

I might be wrong, but I believe that the technology that wraps
wxwidgets into wxpython doesn't cope with C++ virtual functions
(like OnCreateStatusBar).

Instead, in your frame's __init__ you could create an instance of your
custom status bar and then use the frame's SetStatusBar() method to
do the needful.

Thanks in advance.
Larry

Regards,
-- Colin

Colin McPhail wrote:

Larry Bates <larry.bates <at> websafe.com> writes:

I wanted to create a custom status for my frame but I couldn't get it to work. I've stripped it down to the code below. Docs say if you override OnCreateStatusBar method of wx.Frame it will get called and you can return your custom status bar instance. Am I doing something wrong, or is this a bug?

I might be wrong, but I believe that the technology that wraps wxwidgets into wxpython doesn't cope with C++ virtual functions (like OnCreateStatusBar).

Instead, in your frame's __init__ you could create an instance of your
custom status bar and then use the frame's SetStatusBar() method to
do the needful.

Thanks in advance.
Larry

Regards,
-- Colin

That was my "workaround" that I found after Googling for quite some time to find an answer. T think it is "odd" that virtual methods like OnGetChildrenCount of and OnGetItemCount (virtual TreeCtrl mixin) work just fine but this one doesn't.

-Larry

Larry Bates wrote:

That was my "workaround" that I found after Googling for quite some time to find an answer. T think it is "odd" that virtual methods like OnGetChildrenCount of and OnGetItemCount (virtual TreeCtrl mixin) work just fine but this one doesn't.

http://wiki.wxpython.org/OverridingMethods

···

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

Robin Dunn wrote:

Larry Bates wrote:

That was my "workaround" that I found after Googling for quite some time to find an answer. T think it is "odd" that virtual methods like OnGetChildrenCount of and OnGetItemCount (virtual TreeCtrl mixin) work just fine but this one doesn't.

OverridingMethods - wxPyWiki

That helped. IMHO the wxPython docs should reflect that this virtual method can't be overriden by Python method. Only requires one sentence (or maybe two).

Thanks
Larry