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

Re: Notebook focus



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(...);
        }
}



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