Re: Gtk3 and subclassing



On 01/12/2018 00:36, Emmanuele Bassi wrote:
On Fri, 30 Nov 2018 at 19:09, Jeff via gtk-perl-list
<gtk-perl-list gnome org <mailto:gtk-perl-list gnome org>> wrote:

    Whilst working up a smallest working example for another bug, I've
    discovered that I cannot get subclassing working when the main package
    is in the same file as the module.

    Below is the Gtk2 subclassing example from Muppet which I have trivially
    converted to Gtk3.


Your GTK 3 port is wrong.

Grrr. Thanks for the feedback. The example I originally had was that
below, which I replaced with the one from the previous email to
eliminate the GooCanvas2 dependency. As the error seemed to have the
same source, I thought it would be simpler. Sorry for wasting your time.

The code below is cut down from that in gscan2pdf, where in a separate
file, the subclass, and thus the add_events() call works fine. Here, I get:

Can't locate object method "add_events" via package "My::Canvas" at
gtk3-subclass2.pl line 15.

I still can't work out why and would appreciate some insight.

Regards

Jeff

#!/usr/bin/perl -w

use strict;

package My::Canvas;

use strict;
use warnings;
use GooCanvas2;

use Glib::Object::Subclass GooCanvas2::Canvas::;

sub INIT_INSTANCE {
    my $self = shift;
    $self->add_events(
            Glib::Object::Introspection->convert_sv_to_flags(
                'Gtk3::Gdk::EventMask', 'exposure-mask' ) |
              Glib::Object::Introspection->convert_sv_to_flags(
                'Gtk3::Gdk::EventMask', 'button-press-mask' ) |
              Glib::Object::Introspection->convert_sv_to_flags(
                'Gtk3::Gdk::EventMask', 'button-release-mask' ) |
              Glib::Object::Introspection->convert_sv_to_flags(
                'Gtk3::Gdk::EventMask', 'pointer-motion-mask' ) |
              Glib::Object::Introspection->convert_sv_to_flags(
                'Gtk3::Gdk::EventMask', 'scroll-mask'
              )
        );
    return $self;
}

package main;

use strict;
use warnings;

use Gtk3 -init;
use GooCanvas2;

my $window = Gtk3::Window->new();
$window->set_default_size(640, 600);
$window->signal_connect('destroy' => sub {Gtk3->main_quit()});
my $canvas = My::Canvas->new();
$window->add($canvas);
$window->show_all;
Gtk3->main();

Attachment: signature.asc
Description: OpenPGP digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]