List Info

Thread: Re: Selectively trapping keypresses




Re: Selectively trapping keypresses
user name
2007-04-16 04:06:51
On 14/04/07, muppet <scottasofyet.org> wrote:
> To modify the behavior of SimpleList's editing
controls, you'll
> basically have to create a custom column type, and
handle the editing
> behavior all for yourself.

> There are other discussions on this list about how to
make all that
> work, and several cell editing examples available.

I've realised that I want EntryCompletion working in a
SimpleList. (I
hadn't realised that the EntryCompletion widget existed
before) You
provided an example with a TreeView in:

http://mail.gnome.org/archives/gtk-perl-list
/2006-June/msg00021.html

But I am having trouble converting it to a SimpleList.

Below is my (non-completing) version of your example. Where
am I going
wrong? Or is this not possible with a SimpleList?

Thanks for any help

Jeff

#!/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
 );
 $editable->set_completion ($cell->)
 if ($editable && $editable->isa ('Gtk2::Entry')
&& $cell-> );
 return $editable;
}



############################################################
############ #######

package main;

use strict;
use Gtk2 -init;
use Glib qw(TRUE FALSE);
use Gtk2::Ex::Simple::List;

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);

Gtk2::Ex::Simple::List->add_column_type(
'entrycompletion',
 type     => 'Glib::Scalar',
 renderer => 'Mup::CellRendererCompletion',
 attr     => sub {
 my ($treecol, $cell, $model, $iter, $col_num) = _;
 my $info = $model->get ($iter, $col_num);
 $cell->set (text => $info);
 }
);
my $slist = Gtk2::Ex::Simple::List->new( text =>
'entrycompletion' );
$slist -> set_column_editable (0, TRUE);
push {$slist->}, [$_]
 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 $renderer = Mup::CellRendererCompletion->new;
$renderer->set (mode => "editable",
               editable => TRUE,
               completion => $completion);
$renderer->signal_connect (edited => sub {
 my ($cell, $path, $new_value) = _;
 $slist->[$path->get_indices][0] = $new_value;
});

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

Gtk2->main;
>
>
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Selectively trapping keypresses
user name
2007-04-13 09:51:00
How do I check whether a Gtk2::Ex::Simple::List is being
edited (when
selectively trapping keypresses)?

I want to

a. When the user presses enter, save the new data to a file
b. Whilst the user is entering data, suggest values (text)

Are there edited or insert-text signals? I can't find
anything.

I'm not sure of the best way to proceed, and would be
grateful for any help.

Regards

Jeff
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Selectively trapping keypresses
user name
2007-04-14 07:39:08
On 13/04/07, Jeffrey Ratcliffe <jeffrey.ratcliffegmail.com> wrote:
> How do I check whether a Gtk2::Ex::Simple::List is
being edited (when
> selectively trapping keypresses)?

> a. When the user presses enter, save the new data to a
file

I'm being dim (serves me right for coding when I should be
in bed).

row-changed will give me that.

I still can't see how to check whether a
Gtk2::Ex::Simple::List is
being edited. Does it has something to do with custom cell
renderers?

Jeff
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Selectively trapping keypresses
country flaguser name
United States
2007-04-14 11:55:15
On Apr 14, 2007, at 8:39 AM, Jeffrey Ratcliffe wrote:

> On 13/04/07, Jeffrey Ratcliffe
<jeffrey.ratcliffegmail.com> wrote:
>> How do I check whether a Gtk2::Ex::Simple::List is
being edited (when
>> selectively trapping keypresses)?
>
>> a. When the user presses enter, save the new data
to a file
>
> I'm being dim (serves me right for coding when I should
be in bed).
>
> row-changed will give me that.
>
> I still can't see how to check whether a
Gtk2::Ex::Simple::List is
> being edited. Does it has something to do with custom
cell renderers?

In order to get that sort of stuff to work, you have to use
the  
TreeView API.

The user does not edit a TreeView (which is what a
SimpleList is).   
The user edits cells.

Basically, when the user activates an editable cell, the
tree view  
tells the cell to start editing itself.  At this point the
cell  
creates an editable that the tree view puts in the right
spot.  The  
user does stuff and then "ends" the editing
somehow.  Generally, it  
is up to your code to catch the "editing-done"
signal and make  
appropriate changes to the model.

SimpleList does some work for you to apply automatically a
user's  
changes.

To modify the behavior of SimpleList's editing controls,
you'll  
basically have to create a custom column type, and handle
the editing  
behavior all for yourself.

There are other discussions on this list about how to make
all that  
work, and several cell editing examples available.


Does that answer your question?


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


_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Selectively trapping keypresses
user name
2007-04-16 09:03:14
Perfect. Thanks!

Jeff

On 16/04/07, muppet <scottasofyet.org> wrote:
> Jeffrey Ratcliffe wrote:
> > Below is my (non-completing) version of your
example. Where am I going
> > wrong? Or is this not possible with a SimpleList?
>
> Everything's good right up until the end.  
>
> The SimpleList constructor creates the cell renderer
for you.  Your methods
> are not affecting the cell renderer in the simple list,
because you're
> creating a new object that isn't connected to anything.
 There's also a bug in
> the 'edited' callback.
>
>
> > my $renderer =
Mup::CellRendererCompletion->new;
>
> # Get the already-existing renderer for column 0, so we
can modify it.
> my $renderer = ($slist->get_column
(0)->get_cell_renderers)[0];
>
> > $renderer->set (mode =>
"editable",
> >                 editable => TRUE,
> >                 completion => $completion);
> > $renderer->signal_connect (edited => sub {
> >  my ($cell, $path, $new_value) = _;
> >   $slist->[$path->get_indices][0] =
$new_value;
>
>   # This is a list, so $path_string will have only one
index, and perl
>   # will quite happily use the string-containing-number
as a number.
>   my ($cell, $path_string, $new_value) = _;
>   $slist->[$path_string][0] = $new_value;
>
> > });
_______________________________________________
gtk-perl-list mailing list
gtk-perl-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-perl-list

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )