Re: Notebook focus



i would venture a guess that you're probably getting the last widget b/c
you're using the same var when creating all of the pages and that's just the
last thing it pointed to.

you'd probably be better off passing the text widget in as a parameter to the
signal handler you set up for each of the buttons. that way each button gets
associated with the corresponding button i.e.

# create a page, add a text and button then
$this_pages_btn->signal_connect( 'clicked' => sub {
        shift; # get button off the stack, ignored
        my $text = shift;  # get the text widget off the stack
        $test->do_whatever # you should be dealing with the corresponding
                           # text for each button (per-page if you set it up
                           # that way)
    }, $this_pages_text );

you can re-use the this_pages_x stuff all you want and the handler should get
the corresponding text when a given button is clicked.

that should accomplish what you're wanting if i'm understanding your
description of the problem.

-rm

Quoting Philippe Camus <philippe camus in-fusio com>:

Hi all,

This is certainly a newbie question, but a "notebook and focus" search in
the mailing list archive didn't give me an interesting answer!

I've appended a bunch of pages to a notebook, and I've created a text
widget with a button on each page.

It's the simplest thing, and here with the button do:

sub ButtonStartClicked
{
    $text_log->insert( undef, undef, undef, "foo bar" );
    $text_log->thaw();
}

My problem is that whatever button I press (page 1, 2 or 3), the text is
appended to the latest page created.

How can I tell notebook to change the focus to the text widget of a
specific page? I'm looking for something like:

$current_page->$text_log->insert...


If the Gtk::Text widget is the only thing in the page then
$notebook->get_current_page->child->insert(...)

else if there is a Gtk::VBox or Gtk::HBox that holds only one Gtk::Text for
my $child ($notebook->get_current_page->child->children) {
        if (ref $child eq 'Gtk::Text') {
                $child->insert(...);
        }
}

else if there is a Gtk::VBox or Gtk::HBox that holds more than one Gtk::Text
then you need to attach data to the widget so you can find it again

my $text1 = Gtk::Text->new;
my $text2 = Gtk::Text->new;

$text1->{name} = "first"; #perlish way
$text2->{name} = "second"; #perlish way

$text1->set_name("first"); #Gtk way
$text2->set_name("second"); #Gtk way
.
.
.
#perlish way
for my $child ($notebook->get_current_page->child->children) {
        if (ref $child->{name} eq "second") {
                $child->insert(...);
        }
}

#gtk way
for my $child ($notebook->get_current_page->child->children) {
        if (ref $child->get_name eq "second") {
                $child->insert(...);
        }
}
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list






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