[wxPython-users] Subclass XRC & Two stage creation
Robin Dunn
robin at alldunn.com
Wed Jan 2 16:56:58 PST 2008
甜瓜 wrote:
> Howdy,
> I'm using wxPython 2.8.7.1 and trying to subclass wx.Hyperlink in
> XRCed. As the guide in wxpywiki, I write the code below which simply
> sets colors:
>
> class MyHyperlinkCtrl(wx.HyperlinkCtrl):
> def __init__(self):
> p = wx.PreHyperlinkCtrl()
> self.PostCreate(p)
> self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)
>
> def OnCreate(self, evt):
> self.Unbind(wx.EVT_WINDOW_CREATE)
> self.NormalColour = wx.Color(0, 90, 255)
> self.HoverColour = wx.Color(0, 90, 255)
> self.VisitedColour = wx.Color(0, 90, 255)
>
> But, it is strage that the HyperlinkCtrl still shows up with default
> color. Therefore I am sure something has been done after OnCreate and
> overwrite my color setting. Why?
More likely the OnCreate is not getting called. There are some widget
types where the create event will be sent before you have a chance to
bind the handler.
> My workaround is binding EVT_PAINT instead of EVT_WINDOW_CREATE:
That is fine, and something like this is usually used as the workaround,
although EVT_SIZE might be a better choice since that will likely happen
before the first paint event and before the widget is actually visible.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list