Autoupdating EntryCompletion (was Selectively trapping keypresses)
On 16/04/07, muppet [EMAIL PROTECTED] wrote: Everything's good right up until the end. ;-) I've added a couple of callbacks to get new entries into the ListModel to which the EntryCompletion is bound. Selecting entries several times from the EntryCompletion is giving me: Gtk-CRITICAL **: gtk_list_store_get_value: assertion `VALID_ITER (iter, list_store)' failed at ./EntryCompletion3.pl line 105. GLib-GObject-CRITICAL **: g_object_set_property: assertion `G_IS_VALUE (value)' failed at ./EntryCompletion3.pl line 105. I've attached the code. What am I doing wrong? #!/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-{completion}) if ($editable $editable-isa ('Gtk2::Entry') $cell- {completion}); 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); $cmp_model - signal_connect('row-inserted' = sub { my ($model, $path, $iter) = @_; my ($val) = $cmp_model-get($iter, 0); warn inserted $val\n; # Weed out duplicates my $iter2 = $cmp_model-iter_next($iter); while ($iter2) { my ($val2) = $cmp_model-get($iter2, 0); warn list $val2\n; if ($val eq $val2) { warn removing $val2\n; $cmp_model-remove ($iter2); warn removed $val2\n; } else { $iter = $iter2; } $iter2 = $cmp_model-iter_next($iter); } }); 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-{data}}, [$_] foreach ('one', 'one and a half', 'one and two thirds', 'one and three quarters', 'two'); $slist - get_model - signal_connect('row-changed' = sub { my ($model, $path, $iter) = @_; my $text = $slist-get_model-get($iter, 0); $cmp_model-insert_with_values(0, 0, $text); }); my $window = Gtk2::Window-new; $window-signal_connect (destroy = sub { Gtk2-main_quit }); # 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-{data}[$path][0] = $new_value; }); $window-add ($slist); $window-show_all; Gtk2-main; ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Autoupdating EntryCompletion (was Selectively trapping keypresses)
On 17/04/07, Jeffrey Ratcliffe [EMAIL PROTECTED] wrote: Replace one with twelve twice, and during the second replacement, the error comes. I tested a stock Edgy box with the same result. Any ideas? Jeff ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Selectively trapping keypresses
Perfect. Thanks! Jeff On 16/04/07, muppet [EMAIL PROTECTED] 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-{data}[$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-{data}[$path_string][0] = $new_value; }); ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Selectively trapping keypresses
On 13/04/07, Jeffrey Ratcliffe [EMAIL PROTECTED] 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 [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Selectively trapping keypresses
On Apr 14, 2007, at 8:39 AM, Jeffrey Ratcliffe wrote: On 13/04/07, Jeffrey Ratcliffe [EMAIL PROTECTED] 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 [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-perl-list