gnope php gtk gui gnope.org  

Editable Treeview

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
ron_t



Joined: 11 Dec 2005
Posts: 78
Location: Gatineau, Quebec

PostPosted: Wed Jan 25, 2006 3:29 pm    Post subject: Editable Treeview Reply with quote

Hi all,

I've been banging my head against the wall on this one for a while with no luck...

I'd like to create an editable treeview. I've figured out how to make the cells editable using:

Code:
set_property('editable', True)


and I've got a callback connected to the cell using:

Code:
cell->connect("edited", "cell_edited", $model)


My callback looks like this:

Code:
function cell_edited($cell, $path, $newText, $model)
{
   $column = $cell->get_data("Column 0");
   $iter = $model->get_iter_from_string($path);
   $model->set($iter, $column, $newText);
} // cell_edited()


However, I can't seem to get the iter worked out for editing the treestore. The ones available seem to be for appending, prepending, etc. but not for simply changing the text in a treestore cell.

In Python, the model can be treated as an array which really simplifies things for python but sets no example for PHP-Gtk2 (naturally, since a model isn't an array).

Does anyone have a simple working example of an editable treeview?

Or can someone enlighten me as to what I'm doing wrong? Is this enough of my code, or do you need more?

Am I way off on what an iter is and how to use it?

-Ron T.
Back to top
karlbowden



Joined: 18 Dec 2005
Posts: 21
Location: Taree, NSW, Australia

PostPosted: Wed Jan 25, 2006 4:31 pm    Post subject: Reply with quote

Hey Ron,

The only part i'm not sure about is the $column.
I could get a sample of your code working by putting in the column number as a fixed int. eg:
Code:
$model->set($iter, 0, $newText);

0 being the first column.

Does that help at all?

Do you need a work around for multiple editable columns?
Back to top
ron_t



Joined: 11 Dec 2005
Posts: 78
Location: Gatineau, Quebec

PostPosted: Wed Jan 25, 2006 5:25 pm    Post subject: Reply with quote

karlbowden wrote:
Hey Ron,

The only part i'm not sure about is the $column.
I could get a sample of your code working by putting in the column number as a fixed int. eg:
Code:
$model->set($iter, 0, $newText);

0 being the first column.

Does that help at all?


By gum! It does, too!

Thanks, Karl!

Question is, why doesn't $column get assigned properly with this line:
Code:

$column = $cell->get_data("Column 0");

I've even tried substituting '0' (without the quotes, of course) for "Column 0", but I get the same error.

[quote="karlbowden"]
Do you need a work around for multiple editable columns?

That sounds great, Karl! I'd love to see that.

Is it a bug in get_data() that causes this?

-Ron T.
Back to top
karlbowden



Joined: 18 Dec 2005
Posts: 21
Location: Taree, NSW, Australia

PostPosted: Thu Jan 26, 2006 2:08 am    Post subject: Reply with quote

Use a cell_renderer for each column, then add to the connect call the $col on the end
Code:
cell->connect("edited", "cell_edited", $model, {eg 0 or 1})


then add the $col to the call back function:
Code:
function cell_edited($cell, $path, $newText, $model, $col) {
   $iter = $model->get_iter_from_string($path);
   $model->set($iter, $col, $newText);
}


Depends on how many column's you have as to how messy it gets.
Back to top
ron_t



Joined: 11 Dec 2005
Posts: 78
Location: Gatineau, Quebec

PostPosted: Thu Jan 26, 2006 4:00 am    Post subject: Reply with quote

karlbowden wrote:
Use a cell_renderer for each column, then add to the connect call the $col on the end
Code:
cell->connect("edited", "cell_edited", $model, {eg 0 or 1})


then add the $col to the call back function:
Code:
function cell_edited($cell, $path, $newText, $model, $col) {
   $iter = $model->get_iter_from_string($path);
   $model->set($iter, $col, $newText);
}


Depends on how many column's you have as to how messy it gets.


That's pretty straightforward, now that I think about it. Thanks, Karl!

One other question...

In a treeview where a top level row has children, is it possible to have the top level editable while the children are not?

None of the references I've found talk about using different renderers on different rows, which I'm assuming you'd have to do in order to achieve this.

Any ideas?

-Ron T.
Back to top
karlbowden



Joined: 18 Dec 2005
Posts: 21
Location: Taree, NSW, Australia

PostPosted: Fri Jan 27, 2006 12:36 am    Post subject: Reply with quote

I've not seen support in gtk or php-gtk for that, but if you need a work around on that too, you could catch comething like a 'changed selection' event, and at that point set wether that column is editable or not.

Not sure about your data structure as to how easy that would be. But if you look at the path generated and the difference in path for children and parents it might hold some clues, or the iter may have a function 'has children' or similar that would make it real easy.

Getting even cludger now, but hope that helps a bit.
Back to top
ron_t



Joined: 11 Dec 2005
Posts: 78
Location: Gatineau, Quebec

PostPosted: Fri Jan 27, 2006 12:54 am    Post subject: Reply with quote

karlbowden wrote:
I've not seen support in gtk or php-gtk for that


Yeah, me neither.

karlbowden wrote:

, but if you need a work around on that too, you could catch comething like a 'changed selection' event, and at that point set wether that column is editable or not.


I was thinking along the same lines, Karl. I think I'm going to have to react to a seletion event, no matter what I end up doing, even if I pop up a dialog and forget about editable cells (which I've seen done and it seems to work fine).

karlbowden wrote:

Getting even cludger now, but hope that helps a bit.


Well, one coder's cludge is another coder's algorythm. Smile

-Ron T.
Back to top
karlbowden



Joined: 18 Dec 2005
Posts: 21
Location: Taree, NSW, Australia

PostPosted: Fri Jan 27, 2006 2:33 am    Post subject: Reply with quote

Another option is also to extend GtkCellRendererText or GtkTreeViewColumn class to suit your needs (if possible).

I ended up extending GtkTable for an application of mine to add a whole row at once, and to accecpt strings as widgets and automatically generate GtkLabel widgets for the strings.

Hey, kudos on the blog. I've found it handy for plenty of tips too.
Back to top
ron_t



Joined: 11 Dec 2005
Posts: 78
Location: Gatineau, Quebec

PostPosted: Fri Jan 27, 2006 3:52 am    Post subject: Reply with quote

karlbowden wrote:
Another option is also to extend GtkCellRendererText or GtkTreeViewColumn class to suit your needs (if possible).

I ended up extending GtkTable for an application of mine to add a whole row at once, and to accecpt strings as widgets and automatically generate GtkLabel widgets for the strings.


That sounds like quite the undertaking, but worth it just for a pure fun of it, eh?

karlbowden wrote:

Hey, kudos on the blog. I've found it handy for plenty of tips too.


Thanks, Karl. I was wondering who was reading it. Smile

-Ron T.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.