Re: PHP-GTK Dialog Windows
| From: | Steph | Date: | Thu, 14 Mar 2002 00:02:20 +0000 |
| Subject: | Re: PHP-GTK Dialog Windows | ||
| References: | 1 2 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-1514@lists.php.net to get a copy of this message | ||
- must learn to read mail backwards, sorry :) -
----- Original Message -----
From: "Markus Fischer" <mfischer@guru.josefine.at>
To: "Miles" <miles@sag411.com>
Cc: <php-gtk-general@lists.php.net>
Sent: Wednesday, March 13, 2002 9:18 PM
Subject: Re: [PHP-GTK] PHP-GTK Dialog Windows
>
> Here's a small code snipplet from my current project.
> Basically it works this way:
>
> .) call the function with the message to display and the
> responses the user can give
>
> .) create a dialog window which is modal set_modal(true), put
> the message and the necessary buttons into it and conncet the
> required signal to the buttons
>
> .) show the dialog and call Gtk::main(). At this point we've
> a new mainloop; the dialog window is modal and all other
> windows do not react to input (though the still can get
> focus); only code which is connected to this window or the
> buttons in it will be executing during this phase.
>
> .) Only after the dialog has been closed or one of the
> buttons has been click Gtk::main_quit() is called which
> leaves the newly created inner loop, destroys the window and
> returns the index of the button which was pressed (so you can
> easily catch it in a switch statement for example).
>
>
> function prompt_dialog($message, $prompts) {
> if (strlen($message) == '' || count($prompts) == 0)
> return;
>
> $dialog = &new GtkWindow(GTK_WINDOW_DIALOG);
> $dialog->set_title($message);
> $dialog->set_policy(false, false, true);
> $dialog->set_position(GTK_WIN_POS_CENTER);
> $dialog->connect_object('delete_event', create_function('',
> 'Gtk::main_quit();'));
> $dialog->set_modal(true);
>
> $vbox = &new GtkVBox;
> $vbox->show();
> $dialog->add(&$vbox);
>
> $label = &new GtkLabel($message);
> $label->set_padding(50, 50);
> $label->show();
> $vbox->pack_start($label);
>
> $action_area = &new GtkHbox(true, 0);
> $action_area->show();
> $vbox->pack_start($action_area, false, false, 10);
> $return_value = false;
>
> foreach ($prompts as $i => $prompt) {
> $button = &new GtkButton($prompt);
> $button->connect_object('clicked', create_function('$retval,$value',
> '$retval = $value; Gtk::main_quit();'), &$return_value, $i);
> $button->show();
> $action_area->pack_start(&$button, true, true, 5);
> }
>
> $dialog->show();
> Gtk::main();
> $dialog->destroy();
> return $return_value;
> }
>
> switch (prompt_dialog(_("Save changes ?"), array(1 => _("Yes"),2
> => _("No"),3 => _("Cancel")))) {
> case 1:
> $this->do_save_changes();
> return true;
> case 2:
> return true;
> case 3:
> default:
> return false;
> }
>
> On Wed, Mar 13, 2002 at 03:40:08PM -0500, Miles wrote :
> > I've seen a bit of discussion on this issue, but it still is not very clear
> > to me so I would like a bit of clarification if possible. When you pull up
> > dialog windows, if defined mid function the code keeps going on. Could
> > someone explain the nested gtk::main calls I've seen referenced that I'm
> > assuming freeze the code until one of the input buttons is clicked.
> >
> > Any help would be greatly appreciated!
> > --
> > Miles Phillips
> >
> > --
> > PHP-GTK General Mailing List (http://gtk.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> Please always Cc to me when replying to me on the lists.
> GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
>
> --
> PHP-GTK General Mailing List (http://gtk.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>