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

📄 example-1.pl

📁 Developing with Gnome一书examples例子代码
💻 PL
字号:
#!/usr/bin/perl -w# This program monitors the /apps/metacity/general/reduced_resources# gconf key, and allows the user to change it 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_key_changed_callback{  my ($check_button, $new_setting, $old_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_setting != $$old_setting) {    $$old_setting = $new_setting;    $check_button->set_active($new_setting);  }}sub checkbutton_toggled_callback{  my ($check_button, $client, $old_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_key_changed_callback again if this function was called as a  # result of the $check_button->set_active function call.  if ($is_set != $$old_setting) {    $$old_setting = $is_set;    $client->set("/apps/metacity/general/reduced_resources",                 { type => 'bool', value => $is_set }                );  }}sub hook_up_callbacks_and_set_defaults{  my ($the_widgets) = @_;  my $old_setting;  # Get the GconfClient, tell it we want to monitor /apps/metacity/general  my $client = Gnome2::GConf::Client->get_default;  $client->add_dir("/apps/metacity/general", 'preload-none');  # Get the check_button  my $check_button = $the_widgets->get_widget('Reduced Resources');  # Determine whether button should start activated or not  $old_setting = $client->get_bool("/apps/metacity/general/reduced_resources");  $check_button->set_active($old_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/metacity/general/reduced_resources",                      sub {                        my ($client, $cnxn_id, $entry) = @_;                        # Make sure the preference has a valid value                        return unless $entry->{value} &&                                      $entry->{value}->{type} eq 'bool';                        &gconf_key_changed_callback($check_button,                                                     $entry->{value}->{value},                                                    \$old_setting);                      }                     );  # Connect the check_button's clicked callback up so that it can  # change the gconf setting.  $check_button->signal_connect( clicked =>                                  sub {                                    &checkbutton_toggled_callback($check_button,                                                                 $client,                                                                 \$old_setting);                                 }                               );  # 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-1.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 + -