Re: EntryCompletion in a renderer in a TreeView?
- From: muppet <scott asofyet org>
- To: Daniel Kasak <dkasak nusconsulting com au>
- Cc: gtk-perl-list gnome org
- Subject: Re: EntryCompletion in a renderer in a TreeView?
- Date: Sun, 4 Jun 2006 23:23:04 -0400
On Jan 29, 2006, at 9:44 PM, Daniel Kasak wrote:
Is there an easy way to set up autocompletion in a
CellRendererCombo's child ( the entry ) in a treeview?
Depends on what you consider "easy". From what i can tell, you have
to subclass the renderer and override START_EDITING, so that you can
attach a completion to the created Entry.
Not sure why you'd want this on a CellRendererCombo, however --
having both the completion drop-down and the combo menu would be
rather confusing.
-=-=-=-=-=-
#!/usr/bin/perl -w
package Mup::CellRendererCompletion;
use strict;
use Gtk2;
use Glib ':constants';
use Glib::Object::Subclass
"Gtk2::CellRendererText",
properties => [
Glib::ParamSpec->object ('completion',
'Completion',
'The entry completion object for
this cell',
'Gtk2::EntryCompletion',
G_PARAM_READWRITE),
],
;
sub START_EDITING {
my ($cell, $event, $view, $path, $background_area, $cell_area,
$flags) = @_;
my $editable = $cell->SUPER::START_EDITING ($event, $view,
$path, $background_area, $cell_area, $flags);
if ($editable && $editable->isa ('Gtk2::Entry') && $cell->
{completion}) {
$editable->set_completion ($cell->{completion});
}
return $editable;
}
########################################################################
#######
package main;
use strict;
use Gtk2 -init;
use Glib qw(TRUE FALSE);
my $cmp_model = Gtk2::ListStore->new ('Glib::String');
$cmp_model->set ($cmp_model->append, 0, $_)
foreach qw(one two three four five six seven eight nine ten
eleven twelve);
my $completion = Gtk2::EntryCompletion->new;
$completion->set_model ($cmp_model);
$completion->set_text_column (0);
my $model = Gtk2::ListStore->new ('Glib::String');
$model->set ($model->append, 0, $_)
foreach ('one', 'one and a half', 'one and two thirds', 'one and
three quarters', 'two');
my $window = Gtk2::Window->new;
$window->signal_connect (destroy => sub { Gtk2->main_quit });
my $view = Gtk2::TreeView->new ($model);
my $renderer = Mup::CellRendererCompletion->new;
$renderer->set (mode => "editable",
editable => TRUE,
completion => $completion);
$renderer->signal_connect (edited => sub {
my ($cell, $path, $new_value) = @_;
$model->set ($model->get_iter (Gtk2::TreePath->new_from_string
($path)),
0 => $new_value);
});
$view->insert_column_with_attributes (-1, "Stuff", $renderer, text =>
0);
$window->add ($view);
$window->show_all;
Gtk2->main;
--
She's obviously your child. She looks like you, she talks a lot, and
most of it is gibberish.
-- Elysse, to me, of Zella.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]