Nathan smith wrote:
>
>
> Second off, this one is to do with panels. I'm a little stuck as to
> how I should be showing my panels, and to be honest I think I'm
> overdoing it a lot.
It is key that you understand that all of the windowing systems are
event based. With very few exceptions, when you make a call changing
the state of a window, the screen pixels will not have changed by the
time the call returns. Instead, the change will queue up a message.
The next time your app returns to its message loop, that message will be
popped off the queue and handled. That's where the pixels change.
You don't have to call Show on your individual panels and controls. You
just have to Show your frame. As long as a control isn't hidden, it
will get drawn when the frame refreshes.
Nothing gets drawn during your "create" call. This is just setting up
data structures. When you call self.Show() on the frame, that will
start the process of sending paint messages to all of the subwindows.
That's where the pixels actually get drawn When create_window returns,
nothing is yet visible. That happens later.
Refresh queues up a repaint message, asking the window to repaint itself
the next time it gets to its message loop. Update demands that the
window repaint itself immediately, but that's not meaningful during
initialization, because nothing has been painted. Basically, you never
need to call Update or Refresh during initialization. A refresh will
be done as soon as the window creation is finished.
The Layout/Fit stuff is mostly superstition. Layout gets called during
"size" message handling. Fit is useful for your Frame, so it can resize
itself to fit the panel, but you generally don't need it for lower
windows. Layout doesn't actually draw anything. It just forces all
of the sizers to recompute the size of their contained components. If
the sizes change, repaint requests will be queued up and the components
will redraw themselves later.
So, where you have this:
> hbox1.Add(browse1,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
> vbox.Add(hbox1)
> panel.SetSizer(vbox)
> panel.Show()
> panel.Fit() # assuming it fits it to the screen
> panel.Layout() # not sure entirely, but figure it draws everything
> on screen
> panel.Update() # don't know if I actually need this, I'm a bit
> confused between self.Refresh, and self.upadte
> self.Show() # for the frame
> self.Fit()
> self.Update()
> self.Refresh()
> self.Center()
I'd replace those last 10 lines with this:
panel.SetSizer(vbox)
self.Center()
self.Fit()
self.Show()
You might need to experiment with adding panel.Layout after the
SetSizer. Even after 20 years with wx, I'm still unclear on that
interaction, so I end up experimenting.
--
Tim Roberts,
ti...@probo.com
Providenza & Boekelheide, Inc.