Re: More on issues with custom cell renderers ( working example )



On Fri, 2006-09-29 at 11:27 +1000, Daniel Kasak wrote:

Any help greatly appreciated :)

The problem seems to go away if you use Gtk2::Entry instead of
Some::CellEditableText for the cell editable.  So if you don't need the
multi-line editing stuff the custom cell editable provides, just use the
normal stuff.

Also, if all you do is play with the formatting of the displayed text,
consider using a cell data func instead of custom renderers.  See
Gtk2::TreeViewColumn.  Here's one example I had handy (from tprove_gtk):

  my $renderer_progress = Gtk2::CellRendererProgress -> new();
  my $column_progress = Gtk2::TreeViewColumn -> new_with_attributes(
                          "Progress",
                          $renderer_progress);
  $column_progress -> set_cell_data_func($renderer_progress, sub {
    my ($column, $renderer, $model, $iter) = @_;

    my ($total, $run) = $model -> get($iter, COLUMN_TOTAL, COLUMN_RUN);

    if ($run == 0) {
      $renderer -> set(text => "",
                       value => 0);
      return;
    }

    if ($total != 0) {
      $renderer -> set(text => "$run/$total",
                       value => $run/$total * 100);
    } else {
      $renderer -> set(text => $run,
                       value => 0);
    }
  });
  $view -> append_column($column_progress);

-- 
Bye,
-Torsten




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