Writing a class from type Gtk3::SourceView::CompletionProvider

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Writing a class from type Gtk3::SourceView::CompletionProvider

max.augsburg
Hello everybody,
As someone of you know, I try to write a perl module for Gtk3::SourceView. For testing a custom Completion I need an object from Gtk3::SourceView::CompletionProvider for the method $context->add_provider($custom_provider).
 
As I saw in some python examples about this topic, I tried to create a class for Custom Providers and create the $custom_provider as a object of this class. Here is my code so far for the class from which I create the $custom_provider with $custom_provider=Provider->new():
 
package Provider;
use Glib ("TRUE","FALSE");
use Gtk3::SourceView;
use Glib::Object::Subclass 
    "Gtk3::SourceView::CompletionProvider";
sub new {
    my $obj = {};
    bless $obj;
    return $obj;
}
sub get_name {
    return 'Custom'
}
sub match {
    return TRUE;
}
sub populate {
    my ($self, $context) = @_;
    my $proposal = Gtk3::SourceView::CompletionItem->new('Hello World','Hello World');
    $context->add_proposals($self, $proposal, TRUE);
}
 
The problem is that I get the following error:
GLib-GObject-WARNING **: cannot derive 'Provider' from non-fundamental parent type 'GtkSourceCompletionProvider' at /usr/local/lib/x86_64-linux-gnu/perl/5.20.2/Glib/Object/Subclass.pm line 235.
GLib-GObject-CRITICAL **: g_type_set_qdata: assertion 'node != NULL' failed at /usr/local/lib/x86_64-linux-gnu/perl/5.20.2/Glib/Object/Subclass.pm line 235.
GLib-GObject-WARNING **: cannot retrieve class for invalid (unclassed) type '<invalid>' at /usr/local/lib/x86_64-linux-gnu/perl/5.20.2/Glib/Object/Subclass.pm line 235.
 
The error appears also, if I just write:
package Provider;
use Glib ("TRUE","FALSE");
use Gtk3::SourceView;
use Glib::Object::Subclass 
    "Gtk3::SourceView::CompletionProvider";

 
Perhaps someone of you knows how to solve this problem?
Thanks much,
Max

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Writing a class from type Gtk3::SourceView::CompletionProvider

oldtechaa

You may have to "use base Gtk3::SourceView::CompletionProvider". This will make your subclass inherit the members of the CompletionProvider class.

For more info, read the gtk2-perl faq at
https://wiki.gnome.org/Projects/GTK-Perl/FrequentlyAskedQuestions#How_do_I_create_a_new_widget_as_a_subclass_of_an_existing_Gtk_widget.3F
which deals with a subclassed widget.


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Aw: Re: Writing a class from type Gtk3::SourceView::CompletionProvider

max.augsburg
Thanks a lot! This seems to work a little bit better. Unfortunately now I get the following error:
*** unhandled exception in callback:
***   Provider=HASH(0x2567598) is not a proper Glib::Object (it doesn't contain the right magic) at /usr/local/lib/x86_64-linux-gnu/perl/5.20.2/Glib/Object/Introspection.pm line 67.
***  ignoring at /usr/local/share/perl/5.20.2/Gtk3.pm line 546.

Somebody an idea?
Thanks much!
 
Gesendet: Samstag, 21. Mai 2016 um 13:46 Uhr
Von: oldtechaa <[hidden email]>
An: [hidden email]
Betreff: Re: Writing a class from type Gtk3::SourceView::CompletionProvider

You may have to "use base Gtk3::SourceView::CompletionProvider". This will make your subclass inherit the members of the CompletionProvider class.

For more info, read the gtk2-perl faq at
https://wiki.gnome.org/Projects/GTK-Perl/FrequentlyAskedQuestions#How_do_I_create_a_new_widget_as_a_subclass_of_an_existing_Gtk_widget.3F
which deals with a subclassed widget.

_______________________________________________ gtk-perl-list mailing list [hidden email] https://mail.gnome.org/mailman/listinfo/gtk-perl-list
 
 

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Writing a class from type Gtk3::SourceView::CompletionProvider

oldtechaa

To "use base", you'll have to return a blessed object of your "base" from your constructor. Like this:

sub new {
    return bless Gtk3::SourceView::CompletionProvider;
}

This will return a Gtk3::SourceView::CompletionProvider with the "Provider" functions added to it. See "perl -f bless" for more on blessing and what it really does.


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Aw: Re: Writing a class from type Gtk3::SourceView::CompletionProvider

max.augsburg
Thanks a lot for your answer. Unfortunately it still doesn't work.
 
I tried the following codes:
package Provider;
use Glib ("TRUE","FALSE");
use Gtk3::SourceView;
use base 'Gtk3::SourceView::CompletionProvider';
sub new {
    return bless 'Gtk3::SourceView::CompletionProvider';
}
with this I get the following error:
*** unhandled exception in callback:
***   Can't bless non-reference value at ./edit.pl line 16.
***  ignoring at /usr/local/share/perl/5.20.2/Gtk3.pm line 546.
 
Then I tried the following:
package Provider;
use Glib ("TRUE","FALSE");
use Gtk3::SourceView;
use base 'Gtk3::SourceView::CompletionProvider';
sub new {
    my $obj = {};
    bless $obj, 'Gtk3::SourceView::CompletionProvider';
    return $obj;
}
with the following error:
*** unhandled exception in callback:
***   Gtk3::SourceView::CompletionProvider=HASH(0xcb3668) is not a proper Glib::Object (it doesn't contain the right magic) at /usr/local/lib/x86_64-linux-gnu/perl/5.20.2/Glib/Object/Introspection.pm line 67.
***  ignoring at /usr/local/share/perl/5.20.2/Gtk3.pm line 546.

 
I am very clueless. Nevertheless thanks a lot for your help.
 
Gesendet: Samstag, 21. Mai 2016 um 21:58 Uhr
Von: oldtechaa <[hidden email]>
An: [hidden email]
Betreff: Re: Writing a class from type Gtk3::SourceView::CompletionProvider

To "use base", you'll have to return a blessed object of your "base" from your constructor. Like this:

sub new {
    return bless Gtk3::SourceView::CompletionProvider;
}

This will return a Gtk3::SourceView::CompletionProvider with the "Provider" functions added to it. See "perl -f bless" for more on blessing and what it really does.

_______________________________________________ gtk-perl-list mailing list [hidden email] https://mail.gnome.org/mailman/listinfo/gtk-perl-list
 
 

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Fwd: Re: Writing a class from type Gtk3::SourceView::CompletionProvider

oldtechaa
Sorry, I forgot that you'll need to call the constructor of the class you're blessing. Here's how it should be:

sub new {
    return bless Gtk3::SourceView::CompletionProvider->new();
}

Here's an example of some code from my gtk2-perl project, SeekMIDI at https://github.com/oldtechaa/seekmidi/:

use Gtk2;
use base 'Gtk2::VBox';

sub new {
    my $topVBox = bless Gtk2::VBox->new();
    return($topVBox);
}


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list