use warnings; use strict; use Report; my $window = Gtk2::Window->new; $window->set_title('Main Window'); $window->signal_connect('delete-event' => sub {Gtk2->main_quit}); my $vbox = Gtk2::VBox->new; my $bbox = Gtk2::VButtonBox->new; my $b1 = Gtk2::Button->new_with_mnemonic('_Report'); $b1->signal_connect(clicked => \&create_report); my $b2 = Gtk2::Button->new_with_mnemonic('E_xit'); $b2->signal_connect(clicked => sub {Gtk2->main_quit}); my $progress = Gtk2::ProgressBar->new; $bbox->add($b1); $bbox->add($b2); $vbox->add($bbox); $vbox->add($progress); $window->add($vbox); $window->show_all; Gtk2->main; sub create_report { my $dialog = Gtk2::Dialog->new; $dialog->set_title('Report Parameters'); # create the buttons and the content fields my $entry = Gtk2::Entry->new; $dialog->vbox->add($entry); # create the dialog action-area # run the dialog, get the response my $response = $dialog->run; $dialog->destroy; # return if user canceled return undef unless $response eq 'ok'; # create the report my $report = Report->new(parameter => $entry->get_text, progress_bar => $progress); $report->create; } package Report; use Gtk2; sub new { my ($class, %args) = @_; my $self = bless \%args, $class; return $self; } sub create { my $self = shift; # do stuff # update the progress bar $self->{progress_bar}->pulse; # required to see the change in the progress bar Gtk2->main_iteration while Gtk2->events_pending; # do stuff # update the progress bar $self->{progress_bar}->pulse; # required to see the change in the progress bar Gtk2->main_iteration while Gtk2->events_pending; }