Re: Misbehaving Gtk2::Ex::Simple::Lists



On 06/27/2012 10:51 AM, Aaron Lewis wrote:
Hello all,
After several months of writing perl-gtk2 code, I've reduced my list of "how on earth do I do this...?" 
questions to a small handful.
I haven't been able to answer of them from the various tutorials, with questions on Perl Monks, or from 
Google searches - I wonder if anyone can
help?
The enclosed script displays a Gtk2::Ex::Simple::List. The list contains too much data to display in the 
window, so there's a scroller.
1. Annoyingly, the scrollbar scrolls the column titles, as well as the data. How do I stop the column titles 
from scrolling away?
(I've seen Gtk2 applications written in C that don't behave in this way, so I'm sure it can be done!)

The Gtk2-Perl Study Guide gave me the clue here:
http://gtk2-perl.sourceforge.net/doc/gtk2-perl-study-guide/c3835.html

In the code, it uses $scrolled->add() instead of $scrolled->add_with_viewport.

The C docs are a little (only a little) more edifying:
http://developer.gnome.org/gtk/2.24/GtkScrolledWindow.html#gtk-scrolled-window-add-with-viewport

"Used to add children without native scrolling capabilities. This is simply a convenience function; it is equivalent to adding the unscrollable child to a viewport, then adding the viewport to the scrolled window. If a child has native scrolling, use gtk_container_add() instead of this function."

I don't know how you know that a child has native scrolling, but it seems like TreeViews do.

32c33
<    $scroller->add_with_viewport($list);
---
>         $scroller->add($list);

2. I don't want the second column to be editable - that is, I don't want the user to be able to click on the 
checkboxes; I want them to simply
display the boolean values I give them.
The help for simple lists tells us to use ->set_column_editable for this. It works for 'scalar' and 'text' 
columns, but for 'bool' columns, the
following error is produced:
<type Gtk2::CellRendererToggle does not support property 'editable' at /usr/share/perl5/Gtk2/Ex/Simple/List.pm 
line 130.>
I have commented out line 26 to stop this error. What can I do to make it go away?

Again, we go to the C Docs for our answer:
http://developer.gnome.org/gtk/2.24/GtkCellRenderer.html#GtkCellRenderer.description

"A cell renderer can be activatable like GtkCellRendererToggle, which toggles when it gets activated by a mouse click, or it can be editable like GtkCellRendererText, which allows the user to edit the text using a GtkEntry."

Seems like a weird distinction to me, too. Certainly confusing. Anyway, neither the C Docs nor the Perl docs (http://gtk2-perl.sourceforge.net/doc/pod/index.html) show a set_column_activatable method, so you'll have to dig into the TreeView API. You need to get the column you want, then get the cell renderer for that column, and then use the set() method to change it's activatable property to FALSE:

26c26,27
<    $list->set_column_editable (1, FALSE);
---
>         my ($cell_renderer)=$list->get_column(1)->get_cell_renderers;
>         $cell_renderer->set(activatable => FALSE);

That should fix your two problems.  Attaching patch.

HTH,
-Ken

Attachment: example1.pl.patch
Description: Text Data



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