Try the following:
- Start the demo.
- Select "Non-managed windows/wxStatusBar".
- Make the window smaller (in order to make the effect more obvious).
- Maximize the window.
On my system the position of the ToggleButton not recalculated correctly.
(I'm using wxPython 2.2 with windows.) I examined this and noticed that
the
scrollbar
gets (as usual) two resize-events, but they report a wrong size to the
application.
Actually the wxStatusBar is getting the right size for itself, but
GetFieldRect doesn't have the right value during an EVT_SIZE resulting from
a maximise. It has the right value immediately after the resize so an easy
workaround is to move the relocation of the control to idle time. Demo
attached.
ยทยทยท
--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!
class CustomStatusBar(wxStatusBar):
def __init__(self, parent, log):
wxStatusBar.__init__(self, parent, -1)
self.SetFieldsCount(3)
self.log = log
self.sizeChanged = false
EVT_SIZE(self, self.OnSize)
EVT_IDLE(self, self.OnIdle)
self.SetStatusText("A Custom StatusBar...", 0)
self.cb = wxCheckBox(self, 1001, "toggle clock")
EVT_CHECKBOX(self, 1001, self.OnToggleClock)
self.cb.SetValue(true)
# set the initial position of the checkbox
self.Reposition()
# start our timer
self.timer = wxPyTimer(self.Notify)
self.timer.Start(1000)
self.Notify()
# Time-out handler
def Notify(self):
t = time.localtime(time.time())
st = time.strftime("%d-%b-%Y %I:%M:%S", t)
self.SetStatusText(st, 2)
self.log.WriteText("tick...\n")
# the checkbox was clicked
def OnToggleClock(self, event):
if self.cb.GetValue():
self.timer.Start(1000)
self.Notify()
else:
self.timer.Stop()
def OnSize(self, evt):
self.Reposition() # for normal size events
# Set a flag so the idle time handler will also do the
repositioning.
# It is done this way to get around a buglet where GetFieldRect is
not
# accurate during the EVT_SIZE resulting from a frame maximize.
self.sizeChanged = true
def OnIdle(self, evt):
if self.sizeChanged:
self.Reposition()
# reposition the checkbox
def Reposition(self):
rect = self.GetFieldRect(1)
self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2))
self.cb.SetSize(wxSize(rect.width-4, rect.height-4))
self.sizeChanged = false