gnope php gtk gui gnope.org  

Explanation of present() vs. run()?

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
beidlerj



Joined: 10 Feb 2006
Posts: 55
Location: Oregon, USA

PostPosted: Thu Feb 16, 2006 7:34 pm    Post subject: Explanation of present() vs. run()? Reply with quote

Hello again -

I'm still confused about the difference between the present() and run() functions (from GtkWindow and GtkDialog, respectively). As near as I can tell, they're pretty much the same... but I've seen examples where they're called one right after the other on the same object.

In my own case, I have been trying to follow along with the file dialog example from the Php-Gtk2 blog on www.writingup.com and tailoring it to my own program. I have a GtkDialog set up, and after I'm done packing widgets and such into it, I have:

Code:
$fileListDialog->present();
$fileListDialog->run();


This is what the example shows in the blog... however, when I go to close the window, I have to click the 'X' button twice... I assume this is because after present() finishes, run() shows the dialog all over again and waits for it to be closed. Why are both functions needed, and what's different between them?

Confusedly, Confused

Jeff
Back to top
scott



Joined: 16 Feb 2006
Posts: 35

PostPosted: Thu Feb 16, 2006 8:42 pm    Post subject: Reply with quote

present() is a GtkWindow method. It used to make a window visible regardless of its state. If the window hasn't been shown yet present() will show it. If the window has been minimized, present() will unminimize it. If the window is on another desktop, present() will bring it to the current desktop. If the window is behind another application's window, present() will bring it to the front of the screen.

run() is a GtkDialog method (GtkDialog extends GtkWindow). run() is used hold up execution until the user either closes the dialog or clicks on one of the dialog buttons. It also returns the response id that was generated when the user clicked one of the dialog buttons or closed the dialog. It does NOT show the window. That is why you need to call present() (or show_all()).

The reason you have to click the X twice is because you are not closing the window after run() finishes executing. When you get a response id, you should do something with the dialog information (grab the file path, etc) and then destroy the dialog. Alternatively, you can connect to the dialog's response or close signal. close is emitted when the user clicks on the X and response is emitted when the user clicks a button. Example:
Code:
$dialog->connect_simple('close', array($dialog, 'destroy'));
$dialog->connect('response', 'functionToDoSomething');
dialog->connect_simple_after('response', array($dialog, 'destroy'));

$dialog->show_all()


Note the use of connect_simple_after for the second signal handler for response. This makes sure that the dialog is not destroyed until after you have done something with the response.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.