hiding progressbar in a Gtk2::TreeViewColumn

View: New views
7 Messages — Rating Filter:   Alert me  

hiding progressbar in a Gtk2::TreeViewColumn

by anguila :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have this treeview:
| + Name |pixbuf| ProgressBar|...
| ++ Name_2 |pixbuf| Progressbar|..
|+++ Name_3|pixbuf| Progressbar|..

So my question is, how can I hide the Name_3 Progressbar so achieve this tree:

| + Name |pixbuf| ProgressBar|...|others
| ++ Name_2 |pixbuf| Progressbar|...|others
|+++ Name_3|pixbuf||...others|

code of the model:
...
    my $tc_pbar= Gtk2::TreeViewColumn->new();
    my $pbar = Gtk2::CellRendererProgress->new();
    $tc_pbar->pack_start($pbar,1);
    $tc_pbar->set_attributes($pbar, 'value' => COL_PBAR);
    $tc_pbar->set_sizing ('fixed');
    $tc_pbar->set_fixed_width (150);
...

When i set the values in the rows have the progressbar in the COL_PBAR, but i want that the child of Name_2, Name_3, have no progressbar in the COL_PBAR Column, i tried to put nothing in the field of the COL_PBAR, but still exist in the treeview.
model, when I
 
my $Name= $tree_store->append($undef);
 $tree_store->set($Name,COL_FILENAME,"Name",COL_PBAR,0);
 my $Name_2= $tree_store->append($Name);
 $tree_store->set($Name_2,COL_FILENAME,"Name_2",COL_PBAR,0);
 my $Name_3= $tree_store->append($Name_2);
 $tree_store->set($Name_3,COL_FILENAME,"Name_3");


Any idea how to hide this progressbar?



_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: hiding progressbar in a Gtk2::TreeViewColumn

by muppet-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 24, 2009, at 4:21 PM, anguila wrote:

> Any idea how to hide this progressbar?

If i'm understanding you correctly, then simply don't create a view  
column just for the progressbars -- pack the progress into the last  
column with the last column's text renderer, and decide whether to  
show it on a per-row basis.  You can pack as many renderers as you  
want into one view column, and they will share space; then when you  
hide the progressbar, the remaining contents should soak up its  
space.  I think that using an attribute to control the progress bar  
renderer's "visible" property should work, or else use a cell data  
function.


--
The one difference between Dali and a crazy man is very simple: Dali  
is not crazy at all.
   -- Salvador Dali


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: hiding progressbar in a Gtk2::TreeViewColumn

by anguila :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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?

On Fri, Jul 24, 2009 at 11:48 PM, muppet <scott@...> wrote:

On Jul 24, 2009, at 4:21 PM, anguila wrote:

Any idea how to hide this progressbar?

If i'm understanding you correctly, then simply don't create a view column just for the progressbars -- pack the progress into the last column with the last column's text renderer, and decide whether to show it on a per-row basis.  You can pack as many renderers as you want into one view column, and they will share space; then when you hide the progressbar, the remaining contents should soak up its space.  I think that using an attribute to control the progress bar renderer's "visible" property should work, or else use a cell data function.


--
The one difference between Dali and a crazy man is very simple: Dali is not crazy at all.
 -- Salvador Dali




_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: hiding progressbar in a Gtk2::TreeViewColumn

by muppet-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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?"


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: hiding progressbar in a Gtk2::TreeViewColumn

by anguila :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Trying the first option it seems not recognize sensible option:
GLib-GObject-WARNING **: unable to set property `visible' of type `gboolean' from value of type `gchararray'

With the second option it works, but still visible:

    $tc_pbar->set_cell_data_func ($pbar,
       sub {
           my ($column, $cell, $model, $iter) = @_;

           my $string = $model->get_string_from_iter ($iter);
           if ($string!~/\d:\d:0/) {
               # we should show the progress bar
               $cell->set (visible => FALSE, value => $value);
           } else {
               # we should NOT show the progress bar, so don't
               $cell->set (visible => FALSE,value=>22);
                print "pbar to off!\n";
           }
       });

All the 3rd child want to make pbar visible=>false. I tried and i can change the value of all 3rd childs to 22 and it works, but visible=>false doesn't change the state of visibility and i dont understand why because is a attribute og Gtk2::CellRenderer and it should works, but it doesn't.

Any idea?

On Sat, Jul 25, 2009 at 3:43 AM, muppet <scott@...> wrote:

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?"




_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: hiding progressbar in a Gtk2::TreeViewColumn

by muppet-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 24, 2009, at 11:34 PM, anguila wrote:

> Trying the first option it seems not recognize sensible option:
> GLib-GObject-WARNING **: unable to set property `visible' of type  
> `gboolean' from value of type `gchararray'
>
> With the second option it works, but still visible:
>
>     $tc_pbar->set_cell_data_func ($pbar,
>        sub {
>            my ($column, $cell, $model, $iter) = @_;
>
>            my $string = $model->get_string_from_iter ($iter);
>            if ($string!~/\d:\d:0/) {
>                # we should show the progress bar
>                $cell->set (visible => FALSE, value => $value);

Is that a typo?  (Should be TRUE here, not FALSE.)

>            } else {
>                # we should NOT show the progress bar, so don't
>                $cell->set (visible => FALSE,value=>22);
>                 print "pbar to off!\n";
>            }
>        });
>
> All the 3rd child want to make pbar visible=>false. I tried and i  
> can change the value of all 3rd childs to 22 and it works, but  
> visible=>false doesn't change the state of visibility and i dont  
> understand why because is a attribute og Gtk2::CellRenderer and it  
> should works, but it doesn't.
>
> Any idea?

Perplexing.  A quick scan of the gtk+ sources on git.gnome.org shows  
that the cell's visible property is honored by TreeViewColumn when  
processing each row, so this should work just fine.  I may be  
misreading that (gtktreeviewcolumn.c is 3755 lines and a web browser  
is not as good for reading code as vim).

Sanity check:  do you have the constants TRUE and FALSE defined?  
(e.g. from 'use Glib qw(:constants)').  Is strict turned on?  If perl  
is not being properly strict, it may be interpreting the bareword  
FALSE as a string, and 'FALSE' is not an empty string and therefore is  
logically true.


What if you set the other properties before setting visible, e.g.

     } else {
         # we should NOT show the progress bar
         $cell->set (text => '', value => 0, width => 0, visible =>  
FALSE);



--
Doing a good job around here is like wetting your pants in a dark  
suit; you get a warm feeling, but no one notices.
   -- unknown


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: hiding progressbar in a Gtk2::TreeViewColumn

by anguila :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

solved! forgot use Glib qw(TRUE FALSE);

thanks!



On Sat, Jul 25, 2009 at 6:40 PM, muppet <scott@...> wrote:

On Jul 24, 2009, at 11:34 PM, anguila wrote:

Trying the first option it seems not recognize sensible option:
GLib-GObject-WARNING **: unable to set property `visible' of type `gboolean' from value of type `gchararray'

With the second option it works, but still visible:

   $tc_pbar->set_cell_data_func ($pbar,
      sub {
          my ($column, $cell, $model, $iter) = @_;

          my $string = $model->get_string_from_iter ($iter);
          if ($string!~/\d:\d:0/) {
              # we should show the progress bar
              $cell->set (visible => FALSE, value => $value);

Is that a typo?  (Should be TRUE here, not FALSE.)


          } else {
              # we should NOT show the progress bar, so don't
              $cell->set (visible => FALSE,value=>22);
               print "pbar to off!\n";
          }
      });

All the 3rd child want to make pbar visible=>false. I tried and i can change the value of all 3rd childs to 22 and it works, but visible=>false doesn't change the state of visibility and i dont understand why because is a attribute og Gtk2::CellRenderer and it should works, but it doesn't.

Any idea?

Perplexing.  A quick scan of the gtk+ sources on git.gnome.org shows that the cell's visible property is honored by TreeViewColumn when processing each row, so this should work just fine.  I may be misreading that (gtktreeviewcolumn.c is 3755 lines and a web browser is not as good for reading code as vim).

Sanity check:  do you have the constants TRUE and FALSE defined?  (e.g. from 'use Glib qw(:constants)').  Is strict turned on?  If perl is not being properly strict, it may be interpreting the bareword FALSE as a string, and 'FALSE' is not an empty string and therefore is logically true.


What if you set the other properties before setting visible, e.g.


   } else {
       # we should NOT show the progress bar
       $cell->set (text => '', value => 0, width => 0, visible => FALSE);



--
Doing a good job around here is like wetting your pants in a dark suit; you get a warm feeling, but no one notices.
 -- unknown




_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list