I have a frame that has a tree control, text ctrl and two buttons (ok, cancel). On the tree control I'm using virtual mixin that builds the tree from a folder structure on WebDAV server. First implementation built the entire form before showing anything. Depending on Internet connection it can take 10-20 seconds.
I wanted to show the form and THEN populate the tree. I replaced the overloaded OnGetChildreCount and OnGetItemText methods with dummy methods and the form now loads much more quickly. After .Show() I then called method on tree control that set OnGetChildCount and OnGetItemText to the real methods and called self.RefreshItems(). This populates the tree as I would like with one problem. The text control and the buttons haven't been drawn on the form yet and information from the window that is behind my frame shows through until the RefreshItems() method returns, then they paint properly. Is there some way to make sure that .Show() is completely done drawing form's contents? Everything works, but the "garbage" that shows through is disconcerting.
Since this is difficult to explain, I've attached two window screenshots showing what I'm talking about.
I have a frame that has a tree control, text ctrl and two buttons (ok, cancel). On the tree control I'm using virtual mixin that builds the tree from a folder structure on WebDAV server. First implementation built the entire form before showing anything. Depending on Internet connection it can take 10-20 seconds.
I wanted to show the form and THEN populate the tree. I replaced the overloaded OnGetChildreCount and OnGetItemText methods with dummy methods and the form now loads much more quickly. After .Show() I then called method on tree control that set OnGetChildCount and OnGetItemText to the real methods and called self.RefreshItems(). This populates the tree as I would like with one problem. The text control and the buttons haven't been drawn on the form yet and information from the window that is behind my frame shows through until the RefreshItems() method returns, then they paint properly. Is there some way to make sure that .Show() is completely done drawing form's contents? Everything works, but the "garbage" that shows through is disconcerting.
Since this is difficult to explain, I've attached two window screenshots showing what I'm talking about.
Thanks in advance for your help.
Larry Bates
While I know it's bad form to answer myself the answer was that I had to follow the call to self.Show() with self.Update(). Not entirely sure why .Show() doesn't complete fully before returning but this fixes the "issue".
From: Larry Bates [mailto:larry.bates@websafe.com]
Sent: Saturday, October 13, 2007 2:03 PM
To: wxpython-users@lists.wxwidgets.org
Subject: Re: Underlying window contents showing in frame while loading
Larry Bates wrote:
> I have a frame that has a tree control, text ctrl and two
buttons (ok,
> cancel). On the tree control I'm using virtual mixin that
builds the
> tree from a folder structure on WebDAV server. First
implementation
> built the entire form before showing anything. Depending
on Internet
> connection it can take 10-20 seconds.
> I wanted to show the form and THEN populate the tree. I
replaced the
> overloaded OnGetChildreCount and OnGetItemText methods with dummy
> methods and the form now loads much more quickly. After .Show() I
> then called method on tree control that set OnGetChildCount and
> OnGetItemText to the real methods and called self.RefreshItems().
> This populates the tree as I would like with one problem. The text
> control and the buttons haven't been drawn on the form yet and
> information from the window that is behind my frame shows through
> until the RefreshItems() method returns, then they paint
properly. Is
> there some way to make sure that
> .Show() is completely done drawing form's contents?
Everything works,
> but the "garbage" that shows through is disconcerting.
>
> Since this is difficult to explain, I've attached two window
> screenshots showing what I'm talking about.
>
> Thanks in advance for your help.
>
> Larry Bates
>
>
While I know it's bad form to answer myself the answer was
that I had to follow the call to self.Show() with
self.Update(). Not entirely sure why .Show() doesn't
complete fully before returning but this fixes the "issue".
-Larry
Without seeing the code, I'm not sure what's happening. But if you show
the form and THEN populate the tree, then you would need to call Refresh()
or Update() to make it show correctly. Normally you create all the widgets
and then show the frame. If you show the frame and then add a widget or
edit a complicated widget, like the tree control or a grid control, then
you'll need to call Refresh() or Update() to see your update to the GUI.
At least, that's been my experience.
I have a frame that has a tree control, text ctrl and two buttons (ok, cancel). On the tree control I'm using virtual mixin that builds the tree from a folder structure on WebDAV server. First implementation built the entire form before showing anything. Depending on Internet connection it can take 10-20 seconds.
I wanted to show the form and THEN populate the tree. I replaced the overloaded OnGetChildreCount and OnGetItemText methods with dummy methods and the form now loads much more quickly. After .Show() I then called method on tree control that set OnGetChildCount and OnGetItemText to the real methods and called self.RefreshItems(). This populates the tree as I would like with one problem. The text control and the buttons haven't been drawn on the form yet and information from the window that is behind my frame shows through until the RefreshItems() method returns, then they paint properly. Is there some way to make sure that .Show() is completely done drawing form's contents? Everything works, but the "garbage" that shows through is disconcerting.
Since this is difficult to explain, I've attached two window screenshots showing what I'm talking about.
Thanks in advance for your help.
Larry Bates
While I know it's bad form to answer myself the answer was that I had to follow the call to self.Show() with self.Update(). Not entirely sure why .Show() doesn't complete fully before returning but this fixes the "issue".
Show just tells the system to show the window. Depending on platform it may or may not actually do it right away. Even then, the actual painting of a window comes later when the system sends a EVT_PAINT event, which is a low priority event so it usually happens after everything else. Calling Update causes the paint event to happen "right now" instead of waiting until it would normally be done, so that is why adding the call to Update makes it look better for you.
However calling Update is just a band-aid that covers the real problem, not a true fix. You may notice that if you drag another window across your app while it is accessing the WebDAV server that your app's windows are damaged and not repainted until the request is finished. This is because you are blocking the sending of events by not returning to the MainLoop from the event handler that is accessing the server. You'll be much better off if you reorganize your application such that the time-consuming things (accessing the server, or anything else that can block) are either done on an alternate thread, or are broken up such that little non-blocking things are done via EVT_IDLE or EVT_TIMER events. Then the main thread is always free to quickly return to the MainLoop and continue processing events. See LongRunningTasks - wxPyWiki
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!