Re: signals in simplelist - editable fields



David Sword said:
I am using a simplelist with a column set to be editable (type double).
I can correctly pick up the values, using the changed signal, when the
user clicks on another row.  However, when they merely enter a new value
and press return, the selection doesn't move so there is no changed
signal (obviously).

I still need to handle a changed signal, but how do I combine with
another signal which will allow me to detect a value being entered,
and/or even be able to restrict entry to numeric characters.

You're stepping outside the realm of a "simple" list and into the wide world
of handling the TreeView and ListStore yourself for fancy list stuff.

SimpleList encapsulates the work necessary to edit the cell, so you won't see
that signal without diving into some of the TreeView stuff.  At line 123 of
SimpleList.pm
(http://cvs.sourceforge.net/viewcvs.py/gtk2-perl/gtk2-perl-xs/Gtk2/pm/SimpleList.pm?annotate=1.21.2.1)
we attach a handler to the cell renderer's "edited" signal, which will be
fired later on when the user edits the cell (after the owning code has called
set_column_editable() on the cell renderer's column).

Beyond that, if you want to limit your column to numeric entry or do special
processing on what the user types, you will really be wanting to write a
custom cell renderer.  There's an example script
(http://cvs.sourceforge.net/viewcvs.py/gtk2-perl/gtk2-perl-xs/Gtk2/examples/cellrenderer_spinbutton.pl?annotate=1.3)
that creates a CellRenderer that lets you edit the numeric value with a
SpinButton.

The other approach is to implement your own validation on what the user types.
 Since the edited signal on a cell renderer fires after the user has finished
editing, this is too late; so you need to create a custom cell renderer so
that you can hook directly to the Editable widget in which the user will type.
 Again, the changed signal on the editable is also too late -- you want to use
the insert-text signal, which gives you a chance to disallow the user's
typing.  See the insert-text example:
http://cvs.sourceforge.net/viewcvs.py/gtk2-perl/gtk2-perl-xs/Gtk2/examples/insert-text-test.pl?annotate=1.3
...

I would really suggest going the SpinButton route, as it will save you work.


If the validation was the only thing for which you needed the changed signal
on the cell, you will have no problems continuing to use SimpleList, as you
can tell SimpleList to use your special renderer by installing a custom column
type:

  Gtk2::SimpleList->add_column_type (
          'numeric',  # name to use when specifying column types
          type => 'Glib::Double',
          renderer => 'MyCoolCustomCellRenderer',
          attr => 'text', # assuming it's just a text renderer with a special
editor
  )


And just a little secret, it looks like you can even override the renderer
used for the builtin column types this way.  Careful with that, because this
change will affect all SimpleLists you create for the rest of your program.

-- 
muppet <scott at asofyet dot org>



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