deadpickle has asked for the wisdom of the Perl Monks concerning the following question:

The user needs to change the config setting. After the config settings are changed the global variable needs to change as well. I was wondering if there is a way for these global settings to get updated when the user clicks the tabs in the notebook or when they click somewhere else. Here is a tester code for this.
#!/usr/bin/perl -w use strict; use Gtk2 '-init'; use Glib qw/TRUE FALSE/; my $username = 'Whats the Server?'; my $server = 'Whats the Username?'; my $entry_sftp_username; my $entry_sftp_server; #create main window my $window = Gtk2::Window->new('toplevel'); $window->signal_connect(delete_event=> sub {Gtk2->main_quit}); $window->set_title("Config Load Notebook Test"); $window->set_default_size(400, 300); #create notebook my $notebook = Gtk2::Notebook->new; $notebook->set_tab_pos('top'); #build the correct interfaces &user_interface; #add widgets $window->add($notebook); $window->show_all; Gtk2->main; #-------------------Config Grabber------------------- #Grab the current config settings sub current { $username = $entry_sftp_username->get_text; $server = $entry_sftp_server->get_text; } #-------------------User Interface------------------- sub user_interface { #build the new notebook my $config_notebook = Gtk2::Notebook->new; $config_notebook->set_tab_pos('right'); #create tables my $table = Gtk2::Table->new(5, 2, FALSE); #Current settings display my $dis_table = Gtk2::Table->new(2, 1, FALSE); my $label1 = Gtk2::Label->new($server); my $label2 = Gtk2::Label->new($username); $dis_table->attach_defaults($label1, 0, 1, 0, 1); $dis_table->attach_defaults($label2, 0, 1, 1, 2); #Connection Group (all users) my $config_table = Gtk2::Table->new(2, 2, FALSE); my $label_sftp_username = Gtk2::Label->new( 'Username'); my $label_sftp_server = Gtk2::Label->new( 'Server'); $entry_sftp_username = Gtk2::Entry->new(); $entry_sftp_username->set_text($username); $entry_sftp_server = Gtk2::Entry->new(); $entry_sftp_server->set_text( $server); $config_table->attach_defaults($label_sftp_username, 0, 1, 0, 1); $config_table->attach_defaults($label_sftp_server, 0, 1, 1, 2); $config_table->attach_defaults($entry_sftp_username, 1, 2, 0, 1); $config_table->attach_defaults($entry_sftp_server, 1, 2, 1, 2); $config_notebook->append_page($config_table, "Connection"); $table->attach_defaults($config_notebook, 0, 2, 0, 1); $notebook->append_page($dis_table, "GPS"); $notebook->append_page($table, "Configure"); }

Replies are listed 'Best First'.
Re: Grab Config Setting When clicking on Notebook Tab
by starX (Chaplain) on Jan 28, 2008 at 00:55 UTC
    I would think it should be possible to do this. In Tk, you can define a callback for on_click(), so if GTK2 works similarly, you could wrap that in a subroutine call that also sets your global variable. I'm afraid you're not being specific enough (which variable? set it to what?) for me to answer beyond that.
Re: Grab Config Setting When clicking on Notebook Tab
by zentara (Cardinal) on Jan 28, 2008 at 17:42 UTC
    when the user clicks the tabs in the notebook or when they click somewhere else.

    That's pretty vague. In Gtk2, you need to connect to events or signals for the widgets. Read "perldoc Gtk2::Notebook" and look for the SIGNALS section. Then you do a $notebook->signal_connect( switch_page=> \&your_callback, $your_data);


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum