Re: Adding a customer cell renderer to a simplelist

muppet wrote:


i suggest, however, you try a more elegant approach to get SimpleList to do the work for you:

  # add a new column type that uses a CellRendererSpinButton
  # to display and edit a Glib::Double column
  Gtk2::SimpleList->add_column_type (
          type => 'Glib::Double',
          renderer => 'Gtk2::CellRendererSpinButton',
          attr => 'value',

  my $slist = Gtk2::SimpleList->new_from_treeview(
          'DanPK'             => 'hidden',
          'LocNo'             => 'hidden',
          'Branch Name'       => 'text',
          'Address'           => 'text',
          'Suburb'            => 'text',
          'State'             => 'text'
          'PostCode'          => 'number'

  # simplelist's set_column_editable() method doesn't know
  # how to handle a 'number' column, so we have to do
  # this one by hand.  note that it's the 7th column in the
  # model, but the *5th* column in the view, so its index
  # is 4.  (this confusion is why i like to keep the hidden
  # columns last.)
  my $numbercell = ($slist->get_column (4)->get_cell_renderers)[0];
  # tell it to allow editing...
  $numbercell->set (mode => "editable");
  # ... and hook up something to handle that editing.
  $numbercell->signal_connect (edited => sub {
      my (undef, $pathstring, $newval) = @_;
      # we'll cheat and use the path string as a stringified row number.
      $slist->{data}[$pathstring+0][2] = $newval;

having said all that, of course, i don't think a double is what you want to use to represent postal codes. you may need to hack up the CellRenderer to use an integer instead of a double.


That worked. Had to change the line:

$slist->{data}[$pathstring+0][2] = $newval;


$slist->{data}[$pathstring+0][6] = $newval;

but anyway, it's working...
... minus one small detail :)

If you change the value of the spinbutton with the mouse *alone*, the 'edited' signal doesn't fire. If you change the value with the mouse and then hit ENTER while the focus is still inside the spinbutton, the 'edit' signal fires.

This isn't too much trouble for us at the moment - I'm *pretty* sure everyone here will be typing values anyway. If it bothers me too much later I'll spend some time seeing if I can make it work. If I can't make it work, I'll be back.

Thanks muppet :)

Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak nusconsulting com au
Title: CanIt Vote for ID 91564

The following links have been inserted by the NUS Consulting internal spam filter and are for NUS Consulting staff only
Not spam
Forget previous vote

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