Gtk3::Application example (WAS: Override of Gtk3::Application->new)
- From: Jeremy Volkening <jdv base2bio com>
- To: Maximilian Lika <max augsburg gmx de>
- Cc: GTK-Perl List <gtk-perl-list gnome org>
- Subject: Gtk3::Application example (WAS: Override of Gtk3::Application->new)
- Date: Sun, 29 May 2016 13:11:50 -0500
Hello Max,
The structure of a GtkApplication program is different than that of a "Gtk2
mainloop"-style application. You should't call Gtk3::init - that is handled
automatically. All of the program initialization is supposed to be done inside
of the 'startup' and 'activate' callbacks. Instead of calling Gtk3::main and
Gtk3::quit, you call the GApplication 'run' and 'quit' methods (therefore you
also need to import Glib::IO). This is the most useful site I've found:
https://wiki.gnome.org/HowDoI/GtkApplication
The problems you're encountering relate to the fact that the App hasn't been
intitialized yet. At the bottom is a working example.
Regards,
Jeremy
use strict;
use warnings;
use Gtk3;
use Glib::IO;
use Glib qw/TRUE FALSE/;
my $app = Gtk3::Application->new('app.test', 'flags-none');
$app->signal_connect('startup' => \&_init );
$app->signal_connect('activate' => \&_build_ui );
$app->signal_connect('shutdown' => \&_cleanup );
$app->run(\ ARGV);
exit;
sub _init {
my ($app) = @_;
# Handle program initialization
print "Hello world!\n";
}
sub _build_ui {
my ($app) = @_;
my $window = Gtk3::ApplicationWindow->new($app);
$window->set_title ("Gtk3 Menu Example");
$window->set_default_size (200, 200);
$window->signal_connect( "delete_event" => sub {$app->quit()} );
$window->show();
}
sub _cleanup {
my ($app) = @_;
# Handle cleanup
print "Goodbye world!\n";
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]