I am working on something that uses Perl Gtk and Glade. Everything works fine except that when I want to get the currently selected page on the notebook using $notebook->get_current_page the currently selected page is not returned but the previous selected page.
My code looks like this:
#Get widget and assign to variable
$notebookMain = $gladexml->get_widget(‘notebookMain’);
#Bind signal to a subroutine in this case the switch-page signal of Notebook
on_notebookMain_switch_page=>\&on_notebookMain_switch_page
#The sub getting executed when user changes to another page
sub on_notebookMain_switch_page
{
$curr_page = $notebookMain->get_current_page;
}
From that I should get the current page of $notebookMain when the user clicks on a different page but like I said before this doesn’t work.
The big hint when searching Google for a answer came with this post. So I tried what Torsten suggested and changed my sub on_notebookMain_switch_page like this:
#The sub getting executed when user changes to another page
sub on_notebookMain_switch_page
{
$curr_page = $notebookMain->get_current_page;
warn join(“, “, @_);
}
This gave the following output when I changed pages:
Gtk2::Notebook=HASH(0x85ffff0), 141979504, 1, at /home/fredre/Desktop/WargenInterface/WIP.pl line 93.
Gtk2::Notebook=HASH(0x85ffff0), 141773512, 0, at /home/fredre/Desktop/WargenInterface/WIP.pl line 93.
Gtk2::Notebook=HASH(0x85ffff0), 141982680, 2, at /home/fredre/Desktop/WargenInterface/WIP.pl line 93.
Gtk2::Notebook=HASH(0x85ffff0), 141989048, 3, at /home/fredre/Desktop/WargenInterface/WIP.pl line 93.
From this I could gather that the correct current page is located in @_ and it is not the number get_current_page is returning.
So to get the correct currently selected page the subroutine should look like this:
#The sub getting executed when user changes to another page
sub on_notebookMain_switch_page
{
$curr_page = $_[2];
}
I don’t know if the problem occurs because I was using Glade or if I just missed something along the way.
I was using:
libGtk2-Perl 1:1.161-1
libGtk2-gladexml-perl 1.006-1
Glade 3.4.2
perl 5.8.8
all from the Ubuntu repositories .
Happy Hacking !!!!





