Re: EntryCompletion



On 24 January 2017 at 21:38, Torsten Schoenfeld <kaffeetisch gmx de> wrote:
Maybe check the "has-focus" property of the entry.

Thanks for the suggestion. It seems that the entry never loses the
focus, probably because otherwise the completion would get in the way
of the entry.

If anyone has any good ideas of a mechanism with which the user could
signal to the GUI that a particular suggestion should be deleted, I
would be very grateful.

Regards

Jeff

Here is a small example of an entry with a completion:

#!/usr/bin/perl

use strict;
use warnings;

use Gtk2 -init;
use Glib qw(TRUE FALSE);

my $window = Gtk2::Window->new;
$window->signal_connect (destroy => sub { Gtk2->main_quit });

my $model = Gtk2::ListStore->new ('Glib::String');
for ('one', 'one and a half', 'one and two thirds', 'one and three quarters') {
    $model->set ($model->append, 0, $_)
}

my $completion = Gtk2::EntryCompletion->new;
$completion->set_model ($model);
$completion->set_text_column (0);
$completion->set_inline_completion(TRUE);

my $entry = Gtk2::Entry->new;
$entry->set_completion($completion);

$entry->signal_connect(
    'delete-from-cursor' => sub {
        my ( $widget, $delete_type, $count, $user_param1 ) = @_;
        my $text = $widget->get_text;
        print "'delete-from-cursor' $widget, $delete_type, $count, $text\n";
        print "entry has focus ", $widget->has_focus, "\n";
        print "entry is focus ", $widget->is_focus, "\n";
        print "entry state ", $widget->state, "\n";
#        if ($widget->state >= 'normal') { "normal\n" };
#        if ($widget->state >= 'active') { "active\n" };
#        if ($widget->state >= 'prelight') { "prelight\n" };
#        if ($widget->state >= 'selected') { "selected\n" };
#        if ($widget->state >= 'insensitive') { "insensitive\n" };
#        print "completion has focus ",
$completion->get_property('has-focus'), "\n";
    }
);
$completion->signal_connect(
    'action-activated' => sub {
        my ( $widget, $index, $user_param1 ) = @_;
        my $text = $widget->get_text;
        print "'action-activated' $widget, $index, $text\n";
    }
);
$completion->signal_connect(
    'cursor-on-match' => sub {
        my ( $widget, $model, $iter, $user_param1 ) = @_;
        my $suggestion = $model->get( $iter, 0 );
        print "'cursor-on-match' $widget, $suggestion\n";
    }
);
$completion->signal_connect(
    'match-selected' => sub {
        my ( $widget, $model, $iter, $user_param1 ) = @_;
        my $suggestion = $model->get( $iter, 0 );
        print "'match-selected' $widget, $suggestion\n";
    }
);
#$completion->signal_connect(
#    'key-press-event' => sub {
#        my ( $widget, $event ) = @_;
#        my $key = $event->keyval;
#        print "'key-press-event' $widget, $event, $key\n";
#    }
#);

$window->add ($entry);
$window->show_all;

Gtk2->main;


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