[wxPython-users] Subclass XRC & Two stage creation
甜瓜
littlesweetmelon at gmail.com
Tue Jan 1 18:43:00 PST 2008
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? In my opinion, XRC loader setup
control settings in Pre...Post section or even after __init__, but
there should be nothing after OnCreate.
My workaround is binding EVT_PAINT instead of EVT_WINDOW_CREATE:
def OnCreate(self, evt):
self.Unbind(wx.EVT_PAINT)
self.NormalColour = wx.Color(0, 90, 255)
self.HoverColour = wx.Color(0, 90, 255)
self.VisitedColour = wx.Color(0, 90, 255)
evt.Skip()
#Ok, no problem now.
^_^ Well, my question is why previous solution does not work.
Regards,
---
ShenLei
More information about the wxpython-users
mailing list