example-2.pl

来自「Developing with Gnome一书examples例子代码」· PL 代码 · 共 68 行

PL
68
字号
#!/usr/bin/perl -w# This program displays a "pulsing" (or whatever it's called)# ProgressBar, adds a timeout function to keep it updated, shows how# to obtain an individual widget that libglade created, and also# manually sets up the callback for the delete_event on the main# window so that some data (a glib timer) can be attached to the# callback.## Note that most programs update progress bars during some kind of# function that doesn't return to the main event loop (unlike this# simple example).  In that case, you must manually tell gtk to update# widgets yourself by calling Glib::MainContext->default->iteration.# (See example-3.pl for an example of doing this in a different# context).use Glib qw(TRUE FALSE);use Gtk2 '-init';use Gtk2::GladeXML;use Time::HiRes qw(gettimeofday tv_interval);# Just to be pedantic...use strict;use vars qw($what_a_waste $worthless_window $progress_bar $wasted_time_tracker);sub inform_user_of_time_wasted{  my (undef, undef, $timer) = @_;  # widget, event are unused  my $elapsed;  # Get the elapsed time since the timer was started  $elapsed = tv_interval ( $timer );  # Tell the user how much time they used  printf("You wasted %.2f seconds with this program.\n", $elapsed);  # Make the main event loop quit  Gtk2->main_quit;}sub update_progress_bar{  my ($progress_bar) = @_;  $progress_bar->pulse;  return TRUE;}  # load the interface  $what_a_waste = Gtk2::GladeXML->new('example-2.glade');  # Get the progress bar widget and change it to "activity mode", i.e. a block  # that bounces back and forth instead of a normal progress bar that fills  # to completion.  $progress_bar = $what_a_waste->get_widget('Progress Bar');  $progress_bar->pulse;  # Add a timeout to update the progress bar every 100 milliseconds or so  Glib::Timeout->add(100, \&update_progress_bar, $progress_bar);  # Start the wasted_time_tracker timer, and connect it to the callback  $wasted_time_tracker = [gettimeofday];  $worthless_window = $what_a_waste->get_widget('WasteTimeWindow');  $worthless_window->signal_connect(delete_event => \&inform_user_of_time_wasted,                                    $wasted_time_tracker);  # start the event loop  Gtk2->main;

⌨️ 快捷键说明

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