[wxPython-users] Xml subclass howto?
Robin Dunn
robin at alldunn.com
Thu Aug 3 10:40:39 PDT 2006
Basil Shubin wrote:
> Hi folks,
>
> I post some time ago, but this message stay unanswered, so I post it again.
>
> I almost create working widget, but there exist two other problem (see
> screenshot and examine sources):
>
> 1. The Xml subclass I have insert into xrc resource file doesn't want
> center by vertical. How how to make so?
> 2. Left custom control overlap the text label. What is right solution
> for cases like this?
>
> Please, give explanation on the example code I have provide.
>
Since the subclassed panel's sizer is being set in the EVT_WINDOW_CREATE
handler, on GTK it will happen after the panel has been added to its
containing sizer, and so that sizer will not have current size info for
the panel and so it assumes that it stays the small default size. When
the EVT_WINDOW_CREATE handler runs and the TimeCtrl is created and the
panel is resized to fit, then it is essentially overriding what the
sizer told it to do. Since this new size (and nested sizer) is new
information then you should tell the sizers above it in the hierarchy to
redo their layout. One way to do that is like this:
class WorkoutTime(wx.Panel):
"""Masked control for workout start/finish time"""
def __init__(self):
p = wx.PrePanel()
# the Create step is done by XRC.
self.PostCreate(p)
self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)
def OnCreate(self, event):
"""Create masked control for time control"""
self.timeCtrl = wx.lib.masked.TimeCtrl(self, fmt24hr=True,
display_seconds=False)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.timeCtrl)
self.SetSizerAndFit(sizer)
self.GetParent().Layout()
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list