Appreciate the time you've taken to respond.

Yes, I'm new to all of this. Had toyed with the thread idea but wanted learned 
thoughts from people the time BEFORE I committed the time to studying the 
various options.

I'll certainly read what you referenced.

Your response made good sense.

Thanks so much.

Brian Rowlands

-----Original Message-----
From: A.T.Hofkamp [mailto:a.t.hofk...@tue.nl] 
Sent: Wednesday, 23 June 2010 9:19 p.m.
To: Brian Rowlands (Greymouth High School)
Cc: Michael Urman; pygtk@daa.com.au
Subject: Re: [pygtk] Updating a window

Brian Rowlands (Greymouth High School) wrote:
> Thought I'd put together a small example to show what I mean:
> 
> import pygtk
> pygtk.require("2.0")
> import gtk
> import sys
> import time
> 
> def do_stuff():
>     time.sleep(5)
>     print 'brian'    
> ####################################
> # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> handles
> ####################################
> class handles:
>     def on_login_window_destroy(event):
>         sys.exit(1)
>         
> ####################################
> # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> define main
> ####################################
> class LoginApp: 
>     def __init__(self):
>         # set the glade file
>         self.builder = gtk.Builder()
>         self.builder.add_from_file("login.glade")
>         self.window = self.builder.get_object("login_window") 
>         self.builder.connect_signals(handles.__dict__)
>         self.server = self.builder.get_object("server")
>         self.info = self.builder.get_object("info")
>         self.window.show()
>         
>         
>     def __getitem__(self,key):
>         # provide link to widgets
>         return self.builder.get_object(key)
> 
> ####################################
> # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> run application
> ####################################
> if __name__ == '__main__':
>     ghs = LoginApp() 
>     do_stuff()
>     gtk.main()

There is only one thread of control, so after constructing the LoginApp() 
object, you block the 
*whole* program for 5 seconds by sleeping, print your name, and *then* start 
event handling of the 
window.
The latter does drawing, and rereshing.

That is why the program behaves as it does.

> 
> The window outline appears but no inside until after 5 sec when the full 
> window takes shape my name then appears.
> 
> What I want is the full window appearing at the beginning and then 5 sec 
> later my name appears.
> 
> Make sense?

What you want is clear to all, but the way you want it, is not going to fly.

You cannot block in the thread of control that does 'gtk.main()' (well, you 
can, but it does not do 
what you want).


There are 2 solutions to this:

1. start another thread to do your processing, and have it coummunicate with 
the gtk.main() thread 
to update the window.

2. do everything event-based.
Instead of sleeping, start a timer, and attach 'print name' to the handler that 
gets called when it 
times out.


I would recommend that you look at the tutorial 
(http://pygtk.org/pygtk2tutorial/index.html), in 
particular chappters 19, 20, and 24. The latter is an example.
To understand those chapters you may want to do the entire tutorial. Since you 
seem new to 
event-based programming, it won't be wasted time, I think.

Albert



_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to