Re: editable cells in GtkListView



On Sat, 2003-02-15 at 18:14, tom roth wrote:
On 14 Feb 2003 17:30:10 +0100
Guillaume Cottenceau <gc mandrakesoft com> wrote:

tom roth <tom tomroth de> writes:

with the help of misc-examples/treeview.pl i was able to produce a Listview.
Now i would like to make some of the cells editable.
Is there any codefragments, docu or tutorial ?

usually it's nice to try to follow c code examples or api doc.

that requires a knowledges of c syntax that i do not comand.

c has very simple syntax.  deceptively so, but a lot less is going on
behind the scenes in C than in any other language except assembly.



add_items (void)
{
  Item foo;

  g_return_if_fail (articles != NULL);

  foo.number = 3;
  foo.product = g_strdup ("bottles of coke");
  foo.editable = TRUE;
  g_array_append_vals (articles, &foo, 1);
....

now my problem is: what is this foo.editable business exactly ? I know
very little about c.
so my wild guess is, foo is  a hash (?) and a pointer of that hash
then is appended to an array ???  

nay.  C is *much* simpler than that.

the dot syntax is how you access a member of a "struct", which is a
multi-element structure; you can think of a struct as similar to a perl
hash, except that you cannot add arbitrary elements to a struct at
runtime as you can with a hash.

equivalent perl syntax would be

$foo{editable} = TRUE;

a pointer is roughly analogous to a perl reference.  for example

        Item * foo;
        ...
        foo->editable = TRUE;

and

        $fooref->{editable} = TRUE;

any clearer?


by the way, since the Item type doesn't have a Gtk prefix, i presume
it's something application-specific.


If i could have this example code (Tree View/Editable Cells of the
gtk-demo example) in perl syntax, things would be way easier for me.

no argument there, the rationale is that since the gtk-perl API is so
close to the C API that documentation would be largely duplicated, and
about 80% redundant, making a lot of maintenance work for not a whole
lot of return.

just an explanation, not an apology or rationalization.


If i could read the c code easily, i would probably write my code in
c.

i can write C code easily, and prefer to write in perl.  why?  because C
is very explicit, which is nice, because everything is laid out there
and unmistakable, but it also sucks because it's a hell of a lot of
work.



Anyway this is what i have so far


according to the C API docs for the text cell renderer,
http://developer.gnome.org/doc/API/2.0/gtk/GtkCellRendererText.html
one of the object's properties is "editable", a boolean, read/write
property.  my wager is that you just need to set this to 1 on the
renderer you supply for any column you want to be editable.


# now build the treeview widget
      $widgets->{'treeview1'} = new Gtk2::TreeView;
              $widgets->{'treeview1'}->set_headers_visible('1');
              $forms->{'dialog1'}{'scrolledwindow2'}->add_with_viewport($widgets->{'treeview1'});   
                my $cell = Gtk2::CellRendererText->new;

                  # tell this renderer that its cells are to be editable
                  $cell->set_property ("editable", 1);

                my $column = Gtk2::TreeViewColumn->new_with_attributes("No", $cell, 'text' => 0);

                  # create a new renderer to use for the remaining 
                  # cells, which are *not* to be editable.
                  my $cell = Gtk2::CellRendererText->new;

                $widgets->{'treeview1'}->append_column($column);
                my $column1 = Gtk2::TreeViewColumn->new_with_attributes("Name", $cell, 'text' => 1);
                $widgets->{'treeview1'}->append_column($column1);
                my $column2 = Gtk2::TreeViewColumn->new_with_attributes("Start", $cell, 'text' => 2);
                 ...
                $widgets->{'treeview1'}->set_model($model);
              $widgets->{'treeview1'}->show;


does that work?


-- 
muppet <scott asofyet org>




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