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

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

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

max.augsburg
Dear oldtechaa,
Thank you for all your help. But this is exactly the problem. Gtk3::SourceView::CompletionProvider has no "new"-method. Enclosed you will find the solution of this problem in python. I don't master this language, but perhaps someone is also experienced in python and can help to translate this in the perl syntax:
class TestProvider(GObject.Object, GtkSource.CompletionProvider):
    __gtype_name__ = 'TestProvider'
    def __init__(self):
        GObject.Object.__init__(self)
        self.priority = 1
        theme = Gtk.IconTheme.get_default()
        icon = theme.load_icon(Gtk.STOCK_DIALOG_INFO, 16, 0)
        self.proposals = []
        self.proposals.append(GtkSource.CompletionItem.new("Proposal 1", "Proposal 1", icon, "blah 1"))
        self.proposals.append(GtkSource.CompletionItem.new("Proposal 2", "Proposal 2", icon, "blah 2"))
        self.proposals.append(GtkSource.CompletionItem.new("Proposal 3", "Proposal 3", icon, "blah 3"))
    def do_get_name(self):
        return "Test Provider"
    def do_get_priority(self):
        return self.priority
    def do_match(self, context):
        return True
    def do_populate(self, context):
    proposals = [
            GtkSource.CompletionItem(label='Hello World!', text='Hello World!', icon=None, info=None)  # always proposed
        context.add_proposals(self, self.proposals, True)
    def set_priority(self, priority):
        self.priority = priority
GObject.type_register(TestProvider)
[.....]
 
 

_______________________________________________
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

I looked up the hierarchy and I see what you mean about no constructor. It seems, in fact, that CompletionProviders can only be constructed by the SourceView itself. The course I probably would recommend is to use your class to subclass every CompletionProvider returned by your SourceView's Completion object's get_providers() function. Here are the links:

https://developer.gnome.org/gtksourceview/stable/GtkSourceView.html#gtk-source-view-get-completion

https://developer.gnome.org/gtksourceview/stable/GtkSourceCompletion.html#gtk-source-completion-get-providers

When get_providers() returns the list, you can use each element and pass it to your class constructor, where it can be blessed. Then your constructor would look more like this:

sub new {
    return bless $_[1];
}

This way you return a blessed version of the class you pass to it from wherever you call your constructor.


_______________________________________________
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
Dear oldtechaa,
Thank you very much for your answer. Unfortunately the Gtk3::SourceCompletion::get_providers method doesn't create a new Provider, but only returns the providers which has been added to the Gtk3::Completion with the function Gtk3::SourceCompletion::add_provider. For the last command I need a created Provider... The API ist unfortunately very circular :-)
I read in https://developer.gnome.org/gtksourceview/stable/GtkSourceCompletionProvider.html that one prerequisit is GObject. Perhaps this is the reason, why it doesn't work at the moment.
A dirty work-aroung could be to use Gtk3::Source::CompletionWords which is a implementation of CompletionProvider and try to change this word completion (I need special characters, so that CompletionWords is not enough). I will try this later but I don't know whether the structure of CompletionWords is the same. I don't think so...
 
Gesendet: Sonntag, 22. Mai 2016 um 14:05 Uhr
Von: oldtechaa <[hidden email]>
An: [hidden email]
Betreff: Re: Writing a class from type Gtk3::SourceView::CompletionProvider

I looked up the hierarchy and I see what you mean about no constructor. It seems, in fact, that CompletionProviders can only be constructed by the SourceView itself. The course I probably would recommend is to use your class to subclass every CompletionProvider returned by your SourceView's Completion object's get_providers() function. Here are the links:

https://developer.gnome.org/gtksourceview/stable/GtkSourceView.html#gtk-source-view-get-completion

https://developer.gnome.org/gtksourceview/stable/GtkSourceCompletion.html#gtk-source-completion-get-providers

When get_providers() returns the list, you can use each element and pass it to your class constructor, where it can be blessed. Then your constructor would look more like this:

sub new {
    return bless $_[1];
}

This way you return a blessed version of the class you pass to it from wherever you call your constructor.

_______________________________________________ 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

Jeremy Volkening-2
> I read in
> https://developer.gnome.org/gtksourceview/stable/GtkSourceCompletionProvider.html
> that one prerequisit is GObject. Perhaps this is the reason, why it
> doesn't work at the moment.

I suspect you will have more (eventual) success with your initial approach
using Glib::Object::Subclass. The part I'm not sure about is that
CompletionProvider is listed as an interface rather than a class in Torsten's
perli11ndoc GIR browser tool, and I don't know how this will change the
necessary approach.

Could you provide the source for your Gtk3::SourceView bindings? Might help
with troubleshooting.

Regards,
Jeremy

_______________________________________________
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
Dear Jeremy,
Thank you for your advise. "use Glib::Object::Subclass 'Gtk3::SourceView::CompletionProvider';" was my first attempt, but with this I received the following error (see also my first eMail):
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.
 
Of course you can download the SourceView Module at https://github.com/MaxPerl/perl-Gtk3-SourceView/blob/master/SourceView.pm 
I hope I can put it the next weeks on CPAN. It is my first try to writ a perl module. Therefore please be not too critical, although I am thankful for all advise on how make things better ;-)
In anticipation thank you very much for all your help!
 
Gesendet: Sonntag, 22. Mai 2016 um 18:00 Uhr
Von: "Jeremy Volkening" <[hidden email]>
An: [hidden email]
Betreff: Re: Writing a class from type Gtk3::SourceView::CompletionProvider
> I read in
> https://developer.gnome.org/gtksourceview/stable/GtkSourceCompletionProvider.html
> that one prerequisit is GObject. Perhaps this is the reason, why it
> doesn't work at the moment.

I suspect you will have more (eventual) success with your initial approach
using Glib::Object::Subclass. The part I'm not sure about is that
CompletionProvider is listed as an interface rather than a class in Torsten's
perli11ndoc GIR browser tool, and I don't know how this will change the
necessary approach.

Could you provide the source for your Gtk3::SourceView bindings? Might help
with troubleshooting.

Regards,
Jeremy

_______________________________________________
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

Jeremy Volkening-2
> 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.

Definitely seems like the problem is that GktSourceCompletionProvider
is an interface and not a class. Try this (inspired by
https://github.com/GNOME/perl-Glib-Object-Introspection/blob/master/t/interface-implementation.t):


package Provider;

use Glib qw/TRUE FALSE/;
use Gtk3::SourceView;
use Glib::Object::Subclass
    'Glib::Object',
    interfaces => [ 'Gtk3::SourceView::CompletionProvider' ];


# etc etc etc

1;


At least it doesn't throw any errors for me when loaded - haven't taken
it any further. Also note that when you use Glib::Object::Subclass you
don't usually define a new() method yourself - it's automatically
created for you. You can initialize things in an INIT_INSTANCE()
method. If you haven't read the Glib::Object::Subclass tutorial yet you
should do so - sometimes you need to specifically enable signal
handlers, properties, etc in a specific way.

Regards,
Jeremy
_______________________________________________
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
Dear Jeremy,
You are great!!!! Thanks a lot for your help. With the following code I got the custom Completion Provider:
package Provider;
use Glib ("TRUE","FALSE");
use Gtk3::SourceView;
use Glib::Object::Subclass
    'Glib::Object',
    interfaces => [ 'Gtk3::SourceView::CompletionProvider' ];
sub GET_NAME {
    return 'Custom'
}
sub GET_ICON {
}
sub POPULATE {
    my ($self, $context) = @_;
    my $proposal = Gtk3::SourceView::CompletionItem->new('Hello','Hello');
    my @proposals = ($proposal);
    $context->add_proposals($self, \@proposals, TRUE);
}
sub MATCH {
    return TRUE;
}
sub GET_ACTIVATION {
    return 'interactive';
}
sub GET_INFO_WIDGET {
    
}
sub GET_START_ITER {
    return FALSE;
}
sub ACTIVATE_PROPOSAL {
    return FALSE;
}
sub GET_INTERACTIVE_DELAY {
    return '-1';
}
sub GET_PRIORITY {
    return 0;
}
In the main program, one just has to add the custom Completion function with the following lines:
my $completion = $textview->get_completion();
my $custom_provider = Provider->new();
$completion->add_provider($custom_provider);
 
I am very happy! I have not any more guessed, that I can solve this problem! Thank you very very much!
 
I will also implement your improvement suggestions for the Module. Yes, adding to CPAN will be the next adventure. But I have a very good instruction in the german perl-community, so that I hope to getting it. But with regard to your hints it will probably take some times more...
Best wishes, 
Max
 

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