Clash between EntryCompletion functionality and key-press-event



Greetings.

I have an interesting problem, which unfortunately I can't reproduce with a simple testcase, but which happens every time with a complex test case.

I'm creating an EntryCompletion object and attaching it to an entry:

sub setup_line_autocompletion {
my ( $self, $locid ) = @_; my $model = Gtk2::ListStore->new( "Glib::String" ); my $sth = $self->{globals}->{dbh}->prepare( "select Line from TelecomLinePosting where LocID = ? group by Line" ); $sth->execute( $locid ); while ( my $row = $sth->fetchrow_arrayref ) {
       $model->set( $model->append, 0, $$row[0] );
   }
$sth->finish; my $entrycompletion = Gtk2::EntryCompletion->new();
   $entrycompletion->set_minimum_key_length( 1 );
   $entrycompletion->set_model( $model );
   $entrycompletion->set_text_column( 0 );
   $self->{form}->get_widget( "Line" )->set_completion( $entrycompletion );
}

I'm *also* intercepting keypress events:

my $signal = signal_connect( 'key-press-event' => sub { $self->process_entry_keypress( @_ ) } );

sub process_entry_keypress {
my ( $widget, $event ) = @_; if (
       $event->keyval == $Gtk2::Gdk::Keysyms{ Return } ||
       $event->keyval == $Gtk2::Gdk::Keysyms{ KP_Enter }
   ) {
       $self->{window}->child_focus('tab-forward');
# If this was a combo ( keep in mind this event occurs in the Combo's child entry ),
       # then tab-forward again, otherwise our focus has only moved along
       # to the drop-down button thingy ...
       if ( ref $widget->get_parent eq "Gtk2::ComboBoxEntry" ) {
           $self->{window}->child_focus('tab-forward');
       }
   }
return FALSE; }

to get the focus to move along when the enter key is pressed.

This works for *one* such entry with an EntryCompletion, but for the other ( in which the EntryCompletion is created in *exactly* the same way as the other ), connecting to the process_entry_keypress event for the entry breaks *part* of the functionality of the EntryCompletion ... selecting an item from the completion's list with the mouse *works*, whereas selecting an item from the completion's list with the keyboard ( ie the cursors and enter key ) *doesn't* work, and instead of getting the item selected being transferred into the entry, I get whatever text I'd already typed. For example, if I type:

0411

and get a list of phone numbers:

0411100100
0411100101

and I select one of the items with the cursor / enter key, all I get in the entry is '0411', and not the item I selected.

As noted, I can't reproduce this in a simple example :( I can create a demo app that demonstrates the problem if anyone wants. You'll have to install a couple of modules, and I can provide some sample data in an SQLite database that will 'just work' with the demo app. I'm holding off doing that in case there is a simple explanation that jumps out ...

If I put the code in process_entry_keypress in another sub and call it via a Glib::Idle the EntryCompletion functions correctly. So, I'm guessing that me hitting Enter is trigging my key-press-event signal before the EntryCompletion has a chance to do anything, and moving the focus along. What is the best way to deal with this? My current method, via a Glib::Idle, seems kinda dodgy.

Dan

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak nusconsulting com au
website: http://www.nusconsulting.com.au



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