Re: [pygtk] Updating a window

2010-06-23 Thread Brian Rowlands (Greymouth High School)
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/


Re: [pygtk] Updating a window

2010-06-23 Thread A.T.Hofkamp
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/


Re: [pygtk] Updating a window

2010-06-23 Thread Brian Rowlands (Greymouth High School)
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()

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?

Brian

-Original Message-
From: Michael Urman [mailto:mur...@gmail.com] 
Sent: Wednesday, 23 June 2010 12:46 p.m.
To: Brian Rowlands (Greymouth High School)
Cc: pygtk@daa.com.au
Subject: Re: [pygtk] Updating a window

On Tue, Jun 22, 2010 at 18:33, Brian Rowlands (Greymouth High School)
 wrote:
> The issue I have is that the outline of the window appears with the inside
> blank until do_stuff() completes when the window is fully defined.
>
> If I have:
>
> gtk.main()
> do_stuff()
>
> then the window appears fine but nothing gets done.
>
> Don’t know if there is a command to update a window.
>
> Probably simple. If not, a reference/pointer would be appreciated.

The right answer really depends on what sort of things you are doing
inside do_stuff. If it's work that makes sense to move piecewise to
signal handlers, then do that. If it's a batch of work with convenient
locations to do event processing (say every time through a loop), call
gtk.main_iteration() from time to time, possibly within a while
gtk.events_pending().

Welcome to event-based programming!
-- 
Michael Urman
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Re: [pygtk] Updating a window

2010-06-22 Thread Tim Evans
On 2010-06-23 11:33, Brian Rowlands (Greymouth High School) wrote:
> Novice but eager to learn. I'm writing a login script which displays a
> GUI window and which I want to update with comments as the script runs.

My preferred pattern for this, especially on Windows, is to use threads. 
The main thread must run the GTK main loop, while background threads do 
the processing.

First thing to note, is that you have to enable threading in pygtk 
before starting. Use this pattern:

   import gtk, gobject, threading

   window = load_my_window() # or whatever
   thread = threading.Thread(target=my_processing_function)
   thread.start()
   gtk.gdk.threads_init()
   with gtk.gdk.lock():
   gtk.main()

The next thing is that background threads must not make calls directly 
to GTK, or your app will lock up. Instead, use gobject.idle_add to tell 
GTK to run a function in the UI thread, and do your GTK calls in that 
function:

   def ui_thread_append_message(message):
   with gtk.gdk.lock:
   XXX add code here to display your message
   return False

   def ui_thread_complete():
   with gtk.gdk.lock:
   window.destroy()
   gtk.main_quit()

   def my_processing_function():
   XXX do some stuff
   gobject.idle_add(ui_thread_append_message, 'Hello World!')
   XXX do some more stuff
   gobject.idle_add(ui_thread_complete)

Post your code, or the important parts of it at least, if you can't get 
this working and I'll have a look at it.

-- 
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


Re: [pygtk] Updating a window

2010-06-22 Thread Brian Rowlands (Greymouth High School)
Thanks for the suggestion but it doesn't make any difference.

 

Thanks for replying.

 

Window only appears after the contents of do_stuff() have completed
their tasks

 

 Do_stuff completes tasks like:

* copy DB to c: drive from server

* read DB

* check user is allowed to log in

* impersonate [ using Active Directory in a Win32 environment ]

* etc

Sorry.

 

Brian

 

From: cmni...@gmail.com [mailto:cmni...@gmail.com] On Behalf Of muhamed
niyas
Sent: Wednesday, 23 June 2010 4:11 p.m.
To: Brian Rowlands (Greymouth High School)
Subject: Updating a window

 

Hi...

Can u re-arrange the statement 
  ghs.window.show()  below the do_stuff()


I mean the code like this



if __name__ == '__main__':
   ghs = LoginApp()
   ghs['user'].set_text(user)
   ghs['pc'].set_text(pc_name)

   set_up_login_window()

   
   do_stuff()
   ghs.window.show()


gtk.main()



Pls try this and let me know the status...

-- 
Thanks & Best Regards,

Muhamed Niyas C
(NuCore Software Solutions Pvt Ltd)
Mobile: +91 9447 468825
URL: www.nucoreindia.com
Email: ni...@nucoreindia.com

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

Re: [pygtk] Updating a window

2010-06-22 Thread Stephen George
Have a look at pygtk faq
http://faq.pygtk.org/index.py?req=show&file=faq03.007.htp


On 23/06/2010 11:19 AM, Brian Rowlands (Greymouth High School) wrote:
> Thanks for that.
>
> Do_stuff consists of things like:
>
>   Impersonate a user
>   Copy Db to c: drive
>   Read sql DB and obtain PC settings
>   Log-off certain types of users
>   Change the registry
>   Set printers inc default printer
>   Write to a log file
>
>   Etc
>
> So event handlers doesn't seem to fix the bill in my mind.
>
> Roughly speaking, the GUI window displays a message to the user. 
> Periodically, this changes as the login script runs through it's tasks. Even 
> displays a goodbye message on the occasions the user shouldn't be allowed to 
> log in.
>
> When I used Perl, there was a window update function. Alas, I'm unsure of 
> where to go now.
>
> BTW, wrote GUI window in Glade if that makes any difference.
>
> Would appreciate feedback
>
> Thanks
>
>
>
> -Original Message-
> From: Michael Urman [mailto:mur...@gmail.com]
> Sent: Wednesday, 23 June 2010 12:46 p.m.
> To: Brian Rowlands (Greymouth High School)
> Cc: pygtk@daa.com.au
> Subject: Re: [pygtk] Updating a window
>
> On Tue, Jun 22, 2010 at 18:33, Brian Rowlands (Greymouth High School)
>   wrote:
>
>> The issue I have is that the outline of the window appears with the inside
>> blank until do_stuff() completes when the window is fully defined.
>>
>> If I have:
>>
>> gtk.main()
>> do_stuff()
>>
>> then the window appears fine but nothing gets done.
>>
>> Don’t know if there is a command to update a window.
>>
>> Probably simple. If not, a reference/pointer would be appreciated.
>>  
> The right answer really depends on what sort of things you are doing
> inside do_stuff. If it's work that makes sense to move piecewise to
> signal handlers, then do that. If it's a batch of work with convenient
> locations to do event processing (say every time through a loop), call
> gtk.main_iteration() from time to time, possibly within a while
> gtk.events_pending().
>
> Welcome to event-based programming!
>


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

Re: [pygtk] Updating a window

2010-06-22 Thread Brian Rowlands (Greymouth High School)
Thanks for that.

Do_stuff consists of things like:

Impersonate a user
Copy Db to c: drive
Read sql DB and obtain PC settings
Log-off certain types of users
Change the registry
Set printers inc default printer
Write to a log file

Etc

So event handlers doesn't seem to fix the bill in my mind. 

Roughly speaking, the GUI window displays a message to the user. Periodically, 
this changes as the login script runs through it's tasks. Even displays a 
goodbye message on the occasions the user shouldn't be allowed to log in.

When I used Perl, there was a window update function. Alas, I'm unsure of where 
to go now.

BTW, wrote GUI window in Glade if that makes any difference.

Would appreciate feedback

Thanks



-Original Message-
From: Michael Urman [mailto:mur...@gmail.com] 
Sent: Wednesday, 23 June 2010 12:46 p.m.
To: Brian Rowlands (Greymouth High School)
Cc: pygtk@daa.com.au
Subject: Re: [pygtk] Updating a window

On Tue, Jun 22, 2010 at 18:33, Brian Rowlands (Greymouth High School)
 wrote:
> The issue I have is that the outline of the window appears with the inside
> blank until do_stuff() completes when the window is fully defined.
>
> If I have:
>
> gtk.main()
> do_stuff()
>
> then the window appears fine but nothing gets done.
>
> Don’t know if there is a command to update a window.
>
> Probably simple. If not, a reference/pointer would be appreciated.

The right answer really depends on what sort of things you are doing
inside do_stuff. If it's work that makes sense to move piecewise to
signal handlers, then do that. If it's a batch of work with convenient
locations to do event processing (say every time through a loop), call
gtk.main_iteration() from time to time, possibly within a while
gtk.events_pending().

Welcome to event-based programming!
-- 
Michael Urman
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Re: [pygtk] Updating a window

2010-06-22 Thread Michael Urman
On Tue, Jun 22, 2010 at 18:33, Brian Rowlands (Greymouth High School)
 wrote:
> The issue I have is that the outline of the window appears with the inside
> blank until do_stuff() completes when the window is fully defined.
>
> If I have:
>
> gtk.main()
> do_stuff()
>
> then the window appears fine but nothing gets done.
>
> Don’t know if there is a command to update a window.
>
> Probably simple. If not, a reference/pointer would be appreciated.

The right answer really depends on what sort of things you are doing
inside do_stuff. If it's work that makes sense to move piecewise to
signal handlers, then do that. If it's a batch of work with convenient
locations to do event processing (say every time through a loop), call
gtk.main_iteration() from time to time, possibly within a while
gtk.events_pending().

Welcome to event-based programming!
-- 
Michael Urman
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

[pygtk] Updating a window

2010-06-22 Thread Brian Rowlands (Greymouth High School)
Novice but eager to learn. I'm writing a login script which displays a
GUI window and which I want to update with comments as the script runs.

My script finishes with:

if __name__ == '__main__':
ghs = LoginApp()
ghs['user'].set_text(user)
ghs['pc'].set_text(pc_name)

set_up_login_window()

ghs.window.show()

do_stuff()  

gtk.main()

The issue I have is that the outline of the window appears with the
inside blank until do_stuff() completes when the window is fully
defined.

If I have:
..
gtk.main()
do_stuff() 

then the window appears fine but nothing gets done.

Don't know if there is a command to update a window.

Probably simple. If not, a reference/pointer would be appreciated. 

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