Re: Gtk2::EntryCompletion cursor-on-match




On Nov 6, 2010, at 7:53 AM, Zettai Muri wrote:

Hi All,

Am trying to connect to events again and this time in a Gtk2::EntryCompletion.

I have borrowed some of the code from:
http://www.koders.com/perl/fidB8CEA21DDF39929C30B4914E5CD897D03858890E.aspx?s=gtk2#L14

Below is what I have so far:

I've added inline the changes you need to make it work.



#!/usr/bin/perl
package main;

use strict;
use Gtk2 -init;

use Glib ':constants';

# Read in glade file with gui
my $builder = Gtk2::Builder->new;
$builder->add_from_file("EntryCompletion.glade");

my $main_window;
my $entry;


retrieve_widgets ();


# Create the completion object
my $completion = Gtk2::EntryCompletion->new;

# Assign the completion to the entry
$entry->set_completion ($completion);

# Create a tree model and use it as the completion model
$completion->set_model (create_completion_model ());

# Use model column 0 as the text column
$completion->set_text_column (0);

&connect_signals;

# Maximise window
#$main_window->maximize;

# Run main loop.
Gtk2->main;

sub retrieve_widgets
{
   # Get Widgets from gui file
   $main_window = $builder->get_object('window1') || die "Can't find
window.\n";
   $entry = $builder->get_object('entry1') || die "Can't find window.\n";
}

sub connect_signals
{
   # Quit when user clicks on the close button/alt-f4 etc.
   $main_window->signal_connect (destroy => sub { Gtk2->main_quit; });

# according to the gtk source, the cursor-on-match signal
# will be emitted only if the completion's inline-selection
# property is set to true.
$completion->set (inline_selection => TRUE);

   $completion->signal_connect('cursor-on-match' => sub {

       print("Cursor on Match\n");

# This is an event signal and must return TRUE if the event
# was handled or FALSE to let the default behavior go.

        return FALSE;

   });
}

# Creates a tree model containing the completions
sub create_completion_model {
 my $store = Gtk2::ListStore->new (Glib::String::);

 # Append one word
 $store->set ($store->append, 0, "GNOME");

 # Append another word
 $store->set ($store->append, 0, "total");

 # And another word
 $store->set ($store->append, 0, "totally");

 return $store;
}

I'm just trying to get the cursor-on-match event to trigger my print statement.

I was under the impression that the following would trigger the event:
1. In the entry field type 'to' (without the quotes).
2. This brings up the EntryCompletion and shows 'total' and 'totally'
3. Using the up and down arrow keys you can highlight the possible matches.
- At this point as I moved the selection up and down I thought this
would trigger the 'cursor-on-match' event.  However I'm not getting
anything printed to my screen.

Is someone able to tell me how I match this event?

Have attached the glade file if that helps.
<EntryCompletion.glade>


--
It's all very complicated and would take a scientist to explain it.
  -- MST3K





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