Dear Perl Monks,

I'm having problems with a Gtk2-Perl application I'm trying to write.

Specifically, 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_st +rings{id_empty_error_title}, text => $gui_stri +ngs{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?

In reply to Gtk2::Assistant page flow by kikuchiyo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.