Search code examples
pythongtkcellgtk3cellrenderer

Python3 Gtk3+: How to hide a cell of a row


I have searched the whole internet for this, but found nothing helpful. I am beginning to think that this is impossible to do, but someone must have had a requirement of this type.

My app:

  • I use a TreeStore to list parents (folders) and childs (files);
  • Minimizing the column list, I will have name, path (hidden column), size (relevant only for childs - easy masked for parent since it is of type str()), progress bar (I want it displayed - showed in TreeView only for childs, not parents).

Why I need this functionality:

  • I want to do an application that will show a progress bar for each file from a TreeStore I have defined;
  • Being a TreeStore, the files will have a parent (folder);
  • I don't want to display a progress bar for the folder, since it will be useless from my point of view and will look bad.

I have researched all the options/functions available but couldn't find one that will do this only for a specific cell from a specific row.

The only functions I have found are that come close to what I need (but are still unusable) are:

Gtk.CellRenderer.set_visible(CellRendererProgress, False) - but this makes the whole cellrenderer invisible;

Gtk.TreeViewColumn.set_visible(False) - makes the whole column invisible;

setting "None" as value for column "Progress" will still display an empty progress bar, anything else will raise an error.

I have thought of how I could accomplish this by bypassing this impossibility, but I couldn't find an answer. I am out of ideas.


Solution

  • You should make a hidden column in the tree store telling whether to show the progress bar in each row or not. Then bind that column to the visibility of the cell renderer, something like this:

    progress_bar_tree_view_column.add_attribute(progress_bar_renderer, 'visible',
        NUMBER_OF_MY_HIDDEN_COLUMN)