Gtk3::Application open signal

2018-04-23 Thread Jeffrey Ratcliffe
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
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Gtk3::Application open signal

2018-04-25 Thread Jeffrey Ratcliffe
On Mon, 23 Apr 2018 13:00:06 +
oldtechaa  wrote:

> I haven't used the open signal, but with the reference here [1], it
> appears it is emitted when g_application_open() is emitted, as also
> documented here. [2] Are you using g_application_open() anywhere?
> 
> oldtechaa
> 
> [1]
> https://developer.gnome.org/gio/stable/GApplication.html#GApplication-open
> [2]
> https://developer.gnome.org/gio/stable/GApplication.html#g-application-open

Thanks for the links, but I think they just confirm what I already
thought, that assuming the handles-open flag is set, if files are
passed to the application, either by someone "using with", or via
arguments on the command line, or by gdbus, then this signal will be
emitted, along with the list of files.

Normally, you don't have to call g_application_open() yourself, this is
done for you. You can call g_application_open() if you want to handle,
say files passed via the command line yourself.

Regards

Jeff
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Gtk3::Application open signal

2018-04-29 Thread Jeffrey Ratcliffe
On Mon, 23 Apr 2018 09:43:37 +0200
Jeffrey Ratcliffe  wrote:

> 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.

These callbacks are implemented as vfuncs in Python, and I see that
Perl vfuncs that clash with core methods have a _VFUNC appended.

Could this be the reason for the open signal never being emitted in
Perl?

Regards

Jeff
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Gtk3::Application open signal

2018-05-02 Thread Torsten Schoenfeld
On 23.04.2018 09:43, Jeffrey Ratcliffe wrote:
> 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.

I think this is due to the @ARGV semantics.  In Perl, @ARGV does not
contain the program's name, but Gtk3::Application's run() expects the
C-style argv with the program's name at the beginning.  So try to use
the following:

  $app->run([$0, @ARGV]);

Also: I wrote a version of your program that more closely resembles the
Python version.  Here it is, in case it is helpful:

#!/usr/bin/perl

package MyApp;

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/;

use Glib::Object::Subclass qw/Gtk3::Application/;

sub STARTUP {
my ($app) = @_;
return $app->SUPER::STARTUP ();
}

sub ACTIVATE {
my ($app) = @_;
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_all ();
return $app->SUPER::ACTIVATE ();
}

sub OPEN {
my ($app, $files) = @_;
}

sub SHUTDOWN {
my ($app) = @_;
return $app->SUPER::SHUTDOWN ();
}

package main;

my $app = MyApp->new(
application_id => 'app.test',
flags => 'handles-open');
exit $app->run([$0, @ARGV]);
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Gtk3::Application open signal

2018-05-15 Thread Jeff
Hi Torsten,

Apologies for the delay in replying.

On 02/05/18 22:46, Torsten Schoenfeld wrote:
> I think this is due to the @ARGV semantics.  In Perl, @ARGV does not
> contain the program's name, but Gtk3::Application's run() expects the
> C-style argv with the program's name at the beginning.  So try to use
> the following:
> 
>   $app->run([$0, @ARGV]);

Thanks. That get things going.

> Also: I wrote a version of your program that more closely resembles the
> Python version.  Here it is, in case it is helpful:

Thanks for this. Very helpful. Where should I have looked to know that
the Perl method names were simply capitalised versions of the C methods?

For anyone interested, $files is an arrayref of
Glib::Object::_Unregistered::GLocalFile, for which there is a method
get_basename() to dig out the filename:

sub OPEN {
my ($app, $files, $nfiles, $arg3) = @_;
print "in open\n";
use Data::Dumper;
print Dumper($files, $nfiles, $arg3);
for my $file (@$files) {
print $file->get_basename(), "\n";
}
}

I don't understand what is going on in the signal version, though. If
the callback for the open signal is:

sub _open {
my ($app, $files, $nfiles, $arg3) = @_;
print "files: $files, $nfiles, $arg3\n";
use Data::Dumper;
print Dumper($files, $nfiles, $arg3);
}

I get output like:

files: 94684537255296, 1,
$VAR1 = '94684537255296';
$VAR2 = 1;
$VAR3 = '';

What is going on?

Regards

Jeff



signature.asc
Description: OpenPGP digital signature
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Gtk3::Application open signal

2018-05-20 Thread Torsten Schoenfeld
On 15.05.2018 11:26, Jeff wrote:
> Thanks for this. Very helpful. Where should I have looked to know that
> the Perl method names were simply capitalised versions of the C methods?

It's been like this in Gtk2, but it wasn't written down anywhere for the
introspection-based bindings.  I added a few words now:
.
 Would this have helped?

> I don't understand what is going on in the signal version, though. If
> the callback for the open signal is:
> 
> sub _open {
> my ($app, $files, $nfiles, $arg3) = @_;
> print "files: $files, $nfiles, $arg3\n";
> use Data::Dumper;
> print Dumper($files, $nfiles, $arg3);
> }
> 
> I get output like:
> 
> files: 94684537255296, 1,
> $VAR1 = '94684537255296';
> $VAR2 = 1;
> $VAR3 = '';
> 
> What is going on?

Well, the answer should have been that you need to use the following to
get the signal properly marshalled:

  Glib::Object::Introspection->setup(
basename => 'Gio',
version => '2.0',
package => 'Glib::IO',
use_generic_signal_marshaller_for => [
  ['Glib::IO::Application', 'open']
]);

(Or to get Glib::IO to do it for you.)

Unfortunately, there are two bugs that prevent this from working.  One
is on our side and is quick to fix:
.
 The other is on gio's side and needs to go through their patch approval
process before it can go in:
.  Once this has been
accepted, it also needs to be merged into gobject-introspection to be
effective.
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: Gtk3::Application open signal

2018-05-21 Thread Jeff
On 20/05/18 17:33, Torsten Schoenfeld wrote:
> It's been like this in Gtk2, but it wasn't written down anywhere for the
> introspection-based bindings.  I added a few words now:
> .
>  Would this have helped?

Absolutely. Thanks for this.

> Unfortunately, there are two bugs that prevent this from working.  One
> is on our side and is quick to fix:
> .
>  The other is on gio's side and needs to go through their patch approval
> process before it can go in:

Thanks for all your work on this!

Regards

Jeff



signature.asc
Description: OpenPGP digital signature
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list