Re: [pygtk] invalidating gui

2002-07-08 Thread Evan Hughes

On Mon, 8 Jul 2002, Malcolm Tredinnick wrote:
> On Sun, Jul 07, 2002 at 06:29:37PM -0700, icewind wrote:
...
> > In that while loop I put the code you suggested. When
> > I run the application, I get the following message
> > output (many times):
> > 
> > GLib-WARNING **: g_main_iterate(): main loop already
> > active in another thread
> 
> Urrgh. Don't do that. :-(
> 
> The "traditional" method to accomplish what you are trying to do here is
> to have one thread which is solely respnosible for updating the gui and
> calling gtk_main_iteration(), etc. The other threads will set shared
> variables which will be read by the "gui" thread and used to update the
> visual portions of the output.

 Yucky. Polling is so second millenium:
  - It introduces unnecessary complexity (another thread to manage and
control, as well as managing the deltas between polls)
  - It slows runtime (due to some lame-o thread that periodically thwacks
a bunch of variables, only to discover that their value hasn't changed
since the last poll)
  - It is difficult to implement in an extensible and useful way (either 
the polling thread must explicitly know of each variable to probe, or 
there has to be some horrible "listener" concept)


 Would other solutions, such as threads_enter() and threads_leave() solve
your problems more cleanly? 

 see http://www.daa.com.au/pipermail/pygtk/2000-October/000442.html


e

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



Re: [pygtk] invalidating gui

2002-07-07 Thread icewind


--- Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sun, Jul 07, 2002 at 06:29:37PM -0700, icewind
> wrote:
> [...]
> > Thanks. I tried that and it doesnt work. It may
> have
> > to  do with the fact that I am trying to insert
> that
> > code in a seperate thread. I have a thread that
> sits
> > waiting for network connections and when one is
> > detected, it updates the gui. I have the thread
> wait
> > in a while loop for something to read from the
> socket.
> > In that while loop I put the code you suggested.
> When
> > I run the application, I get the following message
> > output (many times):
> > 
> > GLib-WARNING **: g_main_iterate(): main loop
> already
> > active in another thread
> 
> Urrgh. Don't do that. :-(
> 
> The "traditional" method to accomplish what you are
> trying to do here is
> to have one thread which is solely respnosible for
> updating the gui and
> calling gtk_main_iteration(), etc. The other threads
> will set shared
> variables which will be read by the "gui" thread and
> used to update the
> visual portions of the output.
> 
> So, for example, your network reading thread could
> update a "bytes read"
> variable and periodically your gui thread would read
> that variable and
> use it to update a progress bar or whatever.
> 
> Cheers,
> Malcolm


Malcom,


Thanks for the info. That makes sense.

Since I havent done much gui programming at all, I
really don't know what I'm doing. Could you or anyone
else on the list point me in the direction of any
resources that discuss best practices for doing guis?
Espicially with threading. Not really UI suggestions,
but more of design issues like your raised. I have
heard of MVC (Model-View-Controller) architecture, but
I dont really know what it is...

Thanks again!


__
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



Re: [pygtk] invalidating gui

2002-07-07 Thread Malcolm Tredinnick

On Sun, Jul 07, 2002 at 06:29:37PM -0700, icewind wrote:
[...]
> Thanks. I tried that and it doesnt work. It may have
> to  do with the fact that I am trying to insert that
> code in a seperate thread. I have a thread that sits
> waiting for network connections and when one is
> detected, it updates the gui. I have the thread wait
> in a while loop for something to read from the socket.
> In that while loop I put the code you suggested. When
> I run the application, I get the following message
> output (many times):
> 
> GLib-WARNING **: g_main_iterate(): main loop already
> active in another thread

Urrgh. Don't do that. :-(

The "traditional" method to accomplish what you are trying to do here is
to have one thread which is solely respnosible for updating the gui and
calling gtk_main_iteration(), etc. The other threads will set shared
variables which will be read by the "gui" thread and used to update the
visual portions of the output.

So, for example, your network reading thread could update a "bytes read"
variable and periodically your gui thread would read that variable and
use it to update a progress bar or whatever.

Cheers,
Malcolm
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



Re: [pygtk] invalidating gui

2002-07-07 Thread icewind


--- Collins <[EMAIL PROTECTED]> wrote:
> On Sat, 6 Jul 2002 22:02:27 -0700 (PDT) icewind
> <[EMAIL PROTECTED]>
> wrote:
> > I have a couple of threads updating the gui
> (adding
> > lines to a CList, changing text in a textentry
> area,
> > etc.) The problem is, the widget that was changed
> > doesnt show its updates until some event occurs
> such
> > as me moving or clicking the mouse into the
> > applications window. I would like the gui updated
> > continuously as the threads actually manipulate
> the
> > widgets.
> > 
> > So, I assume this could be done by calling an
> > "invalidate" function that will tell gtk that some
> > widget needs to be redrawn. If this is how to do
> what
> > I want, what is the name of the function/method I
> have
> > to call, and is it something I have to apply to
> just
> > the widget that was changed or to the window the
> > widget is in or something else?
> 
>
> 
> I got this little nugget from someone on the list a
> month or two back.
> 
>  while events_pending():# suggested by pygtk
> users
> mainiteration(FALSE)
> 



Thanks. I tried that and it doesnt work. It may have
to  do with the fact that I am trying to insert that
code in a seperate thread. I have a thread that sits
waiting for network connections and when one is
detected, it updates the gui. I have the thread wait
in a while loop for something to read from the socket.
In that while loop I put the code you suggested. When
I run the application, I get the following message
output (many times):

GLib-WARNING **: g_main_iterate(): main loop already
active in another thread

What is the best way to update the gui from another
thread?



__
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



Re: [pygtk] invalidating gui

2002-07-07 Thread James Henstridge

Collins wrote:

>On Sat, 6 Jul 2002 22:02:27 -0700 (PDT) icewind <[EMAIL PROTECTED]>
>wrote:
>  
>
>>I have a couple of threads updating the gui (adding
>>lines to a CList, changing text in a textentry area,
>>etc.) The problem is, the widget that was changed
>>doesnt show its updates until some event occurs such
>>as me moving or clicking the mouse into the
>>applications window. I would like the gui updated
>>continuously as the threads actually manipulate the
>>widgets.
>>
>>So, I assume this could be done by calling an
>>"invalidate" function that will tell gtk that some
>>widget needs to be redrawn. If this is how to do what
>>I want, what is the name of the function/method I have
>>to call, and is it something I have to apply to just
>>the widget that was changed or to the window the
>>widget is in or something else?
>>
>>
>
>  
>
>>pygtk mailing list   [EMAIL PROTECTED]
>>http://www.daa.com.au/mailman/listinfo/pygtk
>>Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>>
>>
>
>I got this little nugget from someone on the list a month or two back.
>
> while events_pending():# suggested by pygtk users
>mainiteration(FALSE)
>  
>
If you don't mind requiring Python 2.2 (which you would need to if you 
are using the 2.0 bindings), you can also use the following pattern:

from __future__ import generators
import gtk

def worker_function():
# do some work
yield gtk.TRUE
# do some more work
yield gtk.TRUE
# even more work
yield gtk.TRUE
# ... (til we are finished)
yield gtk.FALSE

gtk.idle_add(worker_function().next)
gtk.main()

this puts the main loop in control, which will continue your subroutine 
when it is not busy, rather than your code having control (when you may 
starve the GUI more).

James.

-- 
Email: [EMAIL PROTECTED]  | Linux.conf.au 2003 Call for Papers out
WWW:   http://www.daa.com.au/~james/ |   http://conf.linux.org.au/cfp.html




___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



Re: [pygtk] invalidating gui

2002-07-07 Thread Collins

On Sat, 6 Jul 2002 22:02:27 -0700 (PDT) icewind <[EMAIL PROTECTED]>
wrote:
> I have a couple of threads updating the gui (adding
> lines to a CList, changing text in a textentry area,
> etc.) The problem is, the widget that was changed
> doesnt show its updates until some event occurs such
> as me moving or clicking the mouse into the
> applications window. I would like the gui updated
> continuously as the threads actually manipulate the
> widgets.
> 
> So, I assume this could be done by calling an
> "invalidate" function that will tell gtk that some
> widget needs to be redrawn. If this is how to do what
> I want, what is the name of the function/method I have
> to call, and is it something I have to apply to just
> the widget that was changed or to the window the
> widget is in or something else?

> pygtk mailing list   [EMAIL PROTECTED]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

I got this little nugget from someone on the list a month or two back.

 while events_pending():# suggested by pygtk users
mainiteration(FALSE)



-- 
Collins Richey - Denver Area - WWTLRD?
gentoo(since 01/01/01) 2.4.18+(ext3) xfce-sylpheed-galeon
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



[pygtk] invalidating gui

2002-07-06 Thread icewind

I have a couple of threads updating the gui (adding
lines to a CList, changing text in a textentry area,
etc.) The problem is, the widget that was changed
doesnt show its updates until some event occurs such
as me moving or clicking the mouse into the
applications window. I would like the gui updated
continuously as the threads actually manipulate the
widgets.

So, I assume this could be done by calling an
"invalidate" function that will tell gtk that some
widget needs to be redrawn. If this is how to do what
I want, what is the name of the function/method I have
to call, and is it something I have to apply to just
the widget that was changed or to the window the
widget is in or something else?

Thanks.




__
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/