def response(widget, response_id):
                                if response_id != gtk.RESPONSE_APPLY:
#                                       gtk.main_quit()
                                        pass
                                else:
#               i=0
#               n=1000
                                        progress =
dialog.get_data("progress")
                                        progress.set_text("Calculating....")
                                        progress.grab_add()
                                        while not os.path.exists(temp_file):
#my task will generate a file after finished
        
whereami_win.display_location() #that long time task
        
fra=progress.get_fraction()+0.01
                                                if fra>1.0:
                                                        fra=0.0
                                                progress.set_fraction(fra)
#               while i < n:
#                   sleep(0.005)
#                   progress.set_fraction(i/(n - 1.0))
#                   i += 1
#       
                                        while gtk.events_pending():
                                                gtk.main_iteration_do(False)
                                        progress.set_fraction(0.0)
                                        progress.set_text("")
                                        progress.grab_remove()

                        
                        dialog = gtk.Dialog("Modal Trick", self, 0,
(gtk.STOCK_EXECUTE,  gtk.RESPONSE_APPLY, gtk.STOCK_CLOSE,
gtk.RESPONSE_CLOSE))
                        dialog.connect("response", response)
                        widget = gtk.ProgressBar()
                        box = dialog.get_child()
                        box.pack_start(widget, False, False, 0)
                        dialog.set_data("progress", widget)
                        dialog.show_all()

hi Gian,
really thanks for help, i hacked that example very ugly, as you see, that my
time consuming task is an atomic operation, it's an encapsulated method,
what I got is that after clicked some button, this model trick dialog
appears with two buttons, then execute button, for god sake, the progress
bar is staying frozen.. sigh I must do sth badly wrong, really have no idea 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
Gian Mario Tagliaretti
Sent: 01 March 2007 14:26
To: [EMAIL PROTECTED]
Subject: Re: [pygtk] (no subject)

2007/3/1, Xi Chen <[EMAIL PROTECTED]>:
> Hi Gian,
> Yes, i've seen that article, but I'm new to python and gtk, really don't
> know where to put my time consuming task..

In that example in the big process (a simple sleep in this case) you
tell the main loop to go on with redrawing the GUI:

while gtk.events_pending():
                 gtk.main_iteration_do(False)

In the main time you don't want your users to interact with the
controls, so you do a grab_add to the progressbar which will became
the only widget on which you can do something.

It's a bit tricky but if you get the philosophy is quite simple, you
can also use a different approach using idle_add() which tells the
main loop to execute some work when it is in idle state.

btw without seeing some code is difficult to help.

cheers
-- 
Gian Mario Tagliaretti
http://www.parafernalia.org/pygtk/

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to