Gtk2::Assistant page flow



There is one more thing (for now, anyway) I'd like to ask your help about.

I want to set up a Gtk2::Assistant. On the first page of the assistant
there is an Entry field. What I'm trying to achieve is that if the
value entered into this field is invalid (empty or already present in
the database), then an error message would pop up and the assistant
would reset to the first page, to let the user correct their mistake.

Here is a minimal example of what I tried:

#############################################
#!/usr/bin/perl

use strict;
use warnings;
use utf8;
use Gtk2 -init;
use Gtk2::Ex::Dialogs;
use Glib ':constants';

my %gui_strings = (
        id_empty_error_title => "Error: empty id",
        id_empty_error_text => "You did not give a valid identifier.",
        assistant1_title => "Id",
        assistant2_title => "Confirm",
        assistant2_label => "Well done!",
);


my $id;

my $assistant = Gtk2::Assistant->new;
Gtk2::Ex::Dialogs->set_parent_window( $assistant );
$assistant->signal_connect (delete_event => sub { Gtk2->main_quit; });

my $page = Gtk2::Entry->new();
$assistant->append_page ($page);
$assistant->set_page_title ($page, $gui_strings{assistant1_title});
$assistant->set_page_complete ($page, TRUE);
$assistant->set_page_type ($page, 'intro');
$page->show_all;        

my $page2 = Gtk2::Label->new($gui_strings{assistant2_label});
$page2->show;
$assistant->append_page ($page2);
$assistant->set_page_title ($page2, $gui_strings{assistant2_title});
$assistant->set_page_complete ($page2, TRUE);
$assistant->set_page_type ($page2, 'confirm');

$assistant->signal_connect (cancel => \&cancel_callback);
$assistant->signal_connect (close => \&cancel_callback);
$assistant->signal_connect (apply => sub {
                # do whatever we have to do with the id, here we just print it
                print $id."\n";
        });
$assistant->signal_connect (prepare => sub {
        my $page_num = $assistant->get_current_page();
        $id = $page->get_text();
        if ($page_num == 1 and $id eq "") {
                new_and_run Gtk2::Ex::Dialogs::ErrorMsg ( title =>
$gui_strings{id_empty_error_title},
                                                                  text =>
$gui_strings{id_empty_error_text} );
                        $assistant->set_current_page(0);
                        return;
        }
    });

$assistant->show_all;
Gtk2->main;


sub cancel_callback {
  my $widget = shift;

  $widget->destroy;
  Gtk2->main_quit;
}
#############################################


However, there is a problem. When I leave the entry field empty, the
dialog pops up as expected. But what I get after pressing OK on the
dialog is a blank assistant page! Only after pressing Forward again do
I get back my original first page of the assistant.

What am I doing wrong? The problem is consistent on both Linux and
Windows by the way.

(This one is also reposted from Perlmonks)

Thanks:

Péter Juhász



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]