Re: php-gtk2 using GtkTreeView
| From: | Sander Knopper | Date: | Wed, 04 May 2005 18:41:15 +0000 |
| Subject: | Re: php-gtk2 using GtkTreeView | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-5826@lists.php.net to get a copy of this message | ||
Is the way to do this to replace "Gtk::TYPE_STRING" with
"Gtk::TYPE_PHP_VALUE" ??
Sander
Op woensdag 04 mei 2005 18:32, schreef u:
> Hi all,
>
> I'm trying to understand the stockbrowser a bit, especially the part about
> the creation of objects which are then inserted into the GtkListStore.
>
> I hope you could clarify what you're doing a bit for me.
>
> From my point of view you are doing something like this, which I'm trying
> to do as well. (a bit pseudo code):
>
> <?php
>
> class human {
>
> public $firstname;
> public $lastname;
>
> function __construct ($_firstname, $_lastname) {
>
> $this->firstname = $_firstname;
> $this->lastname = $_lastname;
> }
> }
>
> function set_firstname ($column, $cell, $model, $iter) {
>
> $human_obj = $model->get_value($iter, 0);
> $cell->set_property('text', $human_obj->firstname);
>
> // With this last step I'm getting an error about a non-existent
> property of "human_obj".
> }
>
> $model = new GtkListStore (Gtk::TYPE_STRING, Gtk::TYPE_STRING);
>
> $human = new human ("Foo", "Bar");
>
> $iter = $model->append ();
> $model->set ($iter, 0, $human); // You ARE inserting an object (as in
> stockbrowser) here right?
> I'm getting an error about object to
> string conversion, which seems logical
> to me of course.
>
> $tree = new GtkTreeView ($model);
>
> $cell_renderer = new GtkCellRendererText ();
> $tree->insert_column_with_data_function (-1, "Firstname", $cell_renderer,
> "set_firstname");
>
> /* Some code to add tree to window and show_all () ...... */