Re: hiding progressbar in a Gtk2::TreeViewColumn




On Jul 24, 2009, at 6:04 PM, anguila wrote:

but with the 3th child how can i set the property of progressbar at visible = false, this will affect to the other parents using same model, isn't it?

You must set up some way to discern that from the model. The column will inspect its attributes list or cell data func for every row, to set up each cell for this row and draw. I can't really experiment to show you an example (i'm on vacation, away from a machine on which to hack), but here is some pseudocode:

    # first, create and arrange

    $column = Gtk2::TreeViewColumn->new ();
    $treeview->append_column ($column);

    $progress_renderer = Gtk2::CellRendererProgress->new ();
    $column->pack_start ($progress_renderer, FALSE);

    $text_renderer = Gtk2::CellRendererText->new ();
    # set expand to TRUE so he will take up all remaining space
    $column->pack_start ($text_renderer, TRUE);

# in any case, the remainder text in the text renderer is unchanged...

$column->set_attributes ($text_renderer, "text" => COL_REMAINDER_TEXT);

First possibility:

    # another column in the model, COL_PBAR_VISIBLE, tells us whether
# we need to use the progressbar. Map this directly to the "visible"
    # property on the renderer.
    $column->add_attributes ($progress_renderer,
                             value => COL_PBAR_VALUE,
                             visible => COL_PBAR_VISIBLE);

Or, next possibility:

    # if we have to use some complicated condition to calculate whether
    # to use the progressbar, the cell data func is more appropriate.
    $column->set_cell_data_func ($progress_renderer,
        sub {
            my ($column, $cell, $model, $iter) = @_;
            my $value = calculate_progress ($model, $iter);
            if (defined $value) {
                # we should show the progress bar
                $cell->set (visible => TRUE, value => $value);
            } else {
                # we should NOT show the progress bar, so don't
                $cell->set (visible => FALSE);
            }
        });


Remember that cell data functions are called rather often, so you don't want to do something expensive there.

The principle is that the attributes on each cell in the column are somewhat distinct. You might have to add_attributes() for the text renderer after setting the data func, the docs are not entirely clear and i can't experiment at the moment.


--
The stereo, playing the Beastie Boys' "Rhymin' and Stealin'": "I'll steal your girlie like I stole your bike!"

Elysse:  "You mean, take off the chain and ride away?"





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