I have a similar program created. The main.pl creates a window with shortcuts to different "reports" that may connect to a web server and download information or create a file from information on the local disk. Each report is it's own object - and may be of their own classes, but they all have a
new and a
create method and whatever else they need to do their assigned work.
Here is an example of what this looks like (not my actual code, and probably doesn't run, but it should give you and idea). The progress bar is created in the main script, and then a reference to it passed to the report objects that want to update it.
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_b
+ar => $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;
}