Re: Adding a customer cell renderer to a simplelist
- From: Daniel Kasak <dkasak nusconsulting com au>
- To: Gtk-Perl-List <gtk-perl-list gnome org>
- Subject: Re: Adding a customer cell renderer to a simplelist
- Date: Mon, 30 Aug 2004 14:41:39 +1000
muppet wrote:
<snipped>
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 (
'number',
type => 'Glib::Double',
renderer => 'Gtk2::CellRendererSpinButton',
attr => 'value',
);
my $slist = Gtk2::SimpleList->new_from_treeview(
$prospects->get_widget('Locations_SList'),
'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.
Right.
That worked. Had to change the line:
$slist->{data}[$pathstring+0][2] = $newval;
to:
$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
website: http://www.nusconsulting.com.au
Title: CanIt Vote for ID 91564
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]