⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example-2.pl

📁 Developing with Gnome一书examples例子代码
💻 PL
字号:
#!/usr/bin/perl -w# This program monitors the# /apps/nautilus/preferences/always_use_browser,# /apps/nautilus/preferences/show_image_thumbnails, and# /apps/nautilus/preferences/thumbnail_limit gconf keys, and allows# the user to change them as well.use Glib qw(TRUE FALSE);use Gtk2 '-init';use Gtk2::GladeXML;use Gnome2::GConf;# Just to be pedantic...use strict;use vars qw($all_da_widgets);sub gconf_browser_key_callback{  my ($check_button, $new_browser_setting, $old_browser_setting) = @_;  # Try to handle asynchronous-ness of GConf and prevent calling  # checkbutton_toggled_callback again if this function was called  # as a result of the $client->set_bool function call.  if ($new_browser_setting != $$old_browser_setting) {    $$old_browser_setting = $new_browser_setting;    $check_button->set_active($new_browser_setting);  }}sub browser_key_toggled_callback{  my ($check_button, $client, $old_browser_setting) = @_;  # Determine whether the checkbutton is already set or not  my $is_set = $check_button->get_active;   # Try to handle asynchronous-ness of GConf and prevent calling  # gconf_browser_key_callback again if this function was called as a  # result of the $check_button->set_active function call.  if ($is_set != $$old_browser_setting) {    $$old_browser_setting = $is_set;    $client->set("/apps/nautilus/preferences/always_use_browser",                 { type => 'bool', value => $is_set }                );  }}sub gconf_show_thumbnails_callback{  my ($show_entry, $new_setting, $old_show_thumbnails_setting) = @_;  # Check if the new_setting seems valid, give a warning if it doesn't  if (($new_setting ne "always") &&      ($new_setting ne "local_only") &&      ($new_setting ne "never"))  {    warn "Unrecognized value specified by external program...\n";  }  # Use the new value if it's different than the old   if ($new_setting ne $$old_show_thumbnails_setting) {    $$old_show_thumbnails_setting = $new_setting;    $show_entry->set_text($new_setting);  }}sub show_thumbnails_changed_callback{  my ($show_entry, $client, $old_show_thumbnails_setting) = @_;  # Get the current value  my $cur_value = $show_entry->get_text;  if (($cur_value eq "always")     ||      ($cur_value eq "local_only") ||      ($cur_value eq "never"))  {    if ($cur_value ne $$old_show_thumbnails_setting) {      $$old_show_thumbnails_setting = $cur_value;      $client->set("/apps/nautilus/preferences/show_image_thumbnails",                   {type => 'string', value => $cur_value }                  );    }  } else {    warn "This program needs an error window to warn you" .         " that you typed an invalid value.\n";    $show_entry->set_text($$old_show_thumbnails_setting);  }}sub gconf_thumbnail_limit_callback{  my ($limit_entry, $new_value, $old_thumbnail_limit) = @_;  # Warn if the value seems invalid   if ($new_value < 0) {    warn "Bad value seems to have been set by external program.\n";  }  if ($new_value != $$old_thumbnail_limit) {    $$old_thumbnail_limit = $new_value;    $limit_entry->set_text($new_value);  }}sub thumbnail_limit_changed_callback{  my ($limit_entry, $client, $old_thumbnail_limit) = @_;  # Get the current value  my $new_value = $limit_entry->get_text;  if ( $new_value =~ /^\d+$/ ) {    if ($new_value != $$old_thumbnail_limit) {      $$old_thumbnail_limit = $new_value;      $client->set("/apps/nautilus/preferences/thumbnail_limit",                   {type => 'int', value => $new_value }                  );    }  } else {    warn "This program needs an error window to warn you" .         " that you typed an invalid value.\n";    $limit_entry->set_text($$old_thumbnail_limit);  }}sub hook_up_callbacks_and_set_defaults{  my ($the_widgets) = @_;  my ($old_browser_setting, $old_show_thumbnails_setting, $old_thumbnail_limit);  # Get the GconfClient, tell it we want to monitor /apps/nautilus/preferences  my $client = Gnome2::GConf::Client->get_default;  $client->add_dir("/apps/nautilus/preferences", 'preload-none');  # FIRST, setup the checkbutton for the always_use_browser key  # Get the check_button  my $check_button = $the_widgets->get_widget('BrowserMode');  # Determine whether button should start activated or not  $old_browser_setting =     $client->get_bool("/apps/nautilus/preferences/always_use_browser");  $check_button->set_active($old_browser_setting);  # Connect the check_button to a callback that can toggle it when the option  # is changed by some outside program.  $client->notify_add("/apps/nautilus/preferences/always_use_browser",                      sub {                        my ($client, $cnxn_id, $entry) = @_;                        # Make sure the preference has a valid value                        return unless $entry->{value} &&                                      $entry->{value}->{type} eq 'bool';                        &gconf_browser_key_callback($check_button,                                                     $entry->{value}->{value},                                                    \$old_browser_setting);                      }                     );  # Connect the check_button's clicked callback up so that it can  # change the gconf setting.  $check_button->signal_connect( clicked =>                                  sub {                                    &browser_key_toggled_callback(                                     $check_button,                                     $client,                                     \$old_browser_setting);                                 }                               );  # SECOND, setup the text entry for the show_image_thumbnails key  # Get the Entry  my $show_entry = $the_widgets->get_widget('ShowThumbnailsEntry');  # Determine the intial string for the show thumbnail entry  $old_show_thumbnails_setting =    $client->get_string("/apps/nautilus/preferences/show_image_thumbnails");  $show_entry->set_text($old_show_thumbnails_setting);  # Connect the show thumbnail entry to a callback that can toggle it  # when the option is changed by some outside program.  $client->notify_add("/apps/nautilus/preferences/show_image_thumbnails",                      sub {                        my ($client, $cnxn_id, $entry) = @_;                        # Make sure the preference has a valid value                        return unless $entry->{value} &&                                      $entry->{value}->{type} eq 'string';                        &gconf_show_thumbnails_callback(                          $show_entry,                           $entry->{value}->{value},                          \$old_show_thumbnails_setting);                      }                     );  # Connect the show thumbnail entry's activated callback up so that  # it can change the gconf setting.  $show_entry->signal_connect( activate =>                                sub {                                  &show_thumbnails_changed_callback(                                   $show_entry,                                   $client,                                   \$old_show_thumbnails_setting);                                 }                               );  # THIRD, setup the text entry for the thumbnail_limit key  # Get the Entry  my $limit_entry = $the_widgets->get_widget('ThumbnailLimitEntry');  # Determine the starting value of the limit  $old_thumbnail_limit =    $client->get_int ("/apps/nautilus/preferences/thumbnail_limit");  $limit_entry->set_text($old_thumbnail_limit);  # Connect the thumbnail limit entry to a callback that can toggle it  # when the option is changed by some outside program.  $client->notify_add("/apps/nautilus/preferences/thumbnail_limit",                      sub {                        my ($client, $cnxn_id, $entry) = @_;                        # Make sure the preference has a valid value                        return unless $entry->{value} &&                                      $entry->{value}->{type} eq 'int';                        &gconf_thumbnail_limit_callback(                          $limit_entry,                           $entry->{value}->{value},                          \$old_thumbnail_limit);                      }                     );  # Connect the thumbnail limit entry's activated callback up so that  # it can change the gconf setting.  $limit_entry->signal_connect( activate =>                                 sub {                                   &thumbnail_limit_changed_callback(                                    $limit_entry,                                    $client,                                    \$old_thumbnail_limit);                                  }                                );  # Get the main_window and make the close button quit  my $main_window = $the_widgets->get_widget('MainWindow');  $main_window->signal_connect( delete_event =>                                 sub { Gtk2->main_quit; return TRUE; }                               );  # Get the quit button and it to gtk_main_quit  my $close_button = $the_widgets->get_widget('CloseButton');  $close_button->signal_connect( clicked => sub { Gtk2->main_quit; } );}  # load the interface  $all_da_widgets = Gtk2::GladeXML->new('example-2.glade');  # Connect all the signals to the appropriate callbacks  &hook_up_callbacks_and_set_defaults($all_da_widgets);  # start the event loop  Gtk2->main;  # Return 0, meaning no errors  0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -