I've been failing to make the Gtk3::Application "open" signal work. Below, I've adapted an example from maxperl's tutorial on github. This should take filenames as arguments.
Unfortunately the open signal is never emitted. Below the Perl example is a Python one which works as expected. I've poked around the Gtk3 and Gio code, but can't find any reference to the GtkApplication stuff. Any help would be much appreciated Regards Jeff #!/usr/bin/perl # Make a binding to the Gio API in the Perl program (just copy&paste ;-)) # This is necessary mainly for Gtk3::Application and some more stuff # Alternatively you find an early implementation as a Perl module # on https://git.gnome.org/browse/perl-Glib-IO (not yet published on CPAN!) # Hopefully this module simplifies the use of the Gio API in the future # (see also the notes above). BEGIN { use Glib::Object::Introspection; Glib::Object::Introspection->setup( basename => 'Gio', version => '2.0', package => 'Glib::IO'); } use strict; use warnings; use Gtk3; use Glib qw/TRUE FALSE/; # The MAIN FUNCTION should be as small as possible and do almost nothing except creating # your Gtk3::Application and running it # The "real work" should always be done in response to the signals fired by Gtk3::Application. # see below my $app = Gtk3::Application->new('app.test', 'handles-open'); $app->signal_connect('startup' => \&_init ); $app->signal_connect('activate' => \&_build_ui ); $app->signal_connect('open' => \&_open ); $app->signal_connect('shutdown' => \&_cleanup ); print "starting with @ARGV\n"; $app->run(\@ARGV); exit; # The CALLBACK FUNCTIONS to the SIGNALS fired by the main function. # Here we do the "real work" (see above) sub _init { my ($app) = @_; # Handle program initialization print "Hello world!\n"; } sub _build_ui { my ($app) = @_; print "running activate\n"; my $window = Gtk3::ApplicationWindow->new($app); $window->set_title ('Welcome to GNOME'); $window->set_default_size (200, 200); $window->signal_connect( 'delete_event' => sub {$app->quit()} ); $window->show(); } sub _open { my ($app, $files) = @_; print "files: $files\n"; } sub _cleanup { my ($app) = @_; # Handle cleanup print "Goodbye world!\n"; } import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gio import sys # a Gtk ApplicationWindow class MyWindow(Gtk.ApplicationWindow): # constructor: the title is "Welcome to GNOME" and the window belongs # to the application app def __init__(self, app): Gtk.Window.__init__(self, title="Welcome to GNOME", application=app) class MyApplication(Gtk.Application): # constructor of the Gtk Application def __init__(self): Gtk.Application.__init__(self, flags=Gio.ApplicationFlags.HANDLES_OPEN) # create and activate a MyWindow, with self (the MyApplication) as # application the window belongs to. # Note that the function in C activate() becomes do_activate() in Python def do_activate(self): win = MyWindow(self) # show the window and all its content # this line could go in the constructor of MyWindow as well win.show_all() print "activate" # start up the application # Note that the function in C startup() becomes do_startup() in Python def do_startup(self): Gtk.Application.do_startup(self) print "startup" # open any files # Note that the function in C open() becomes do_open() in Python def do_open(self, list_of_file_objects, number_of_files, arg3): print "open", list_of_file_objects, number_of_files, arg3 for f in list_of_file_objects: print f.get_basename() Gtk.Application.do_open(self, list_of_file_objects, str(number_of_files)) # create and run the application, exit with the value returned by # running the program app = MyApplication() exit_status = app.run(sys.argv) sys.exit(exit_status) _______________________________________________ gtk-perl-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/gtk-perl-list
