I'm writing a Gtk2-Perl app with a Gtk2::Ex::Simple::List (which is derived from TreeView, hence the title).

I want to set up one of the columns in a special way, specifically, I want this column to hold values from a short list, and each click on a cell in this column should toggle the next value from the pre-specified list. Run the attached code for clarification.

Obviously, for this I need to know which column did the user click into.

I found TreeView's get_path_at_pos method, which, according to the documentation:
"In scalar context, returns the Gtk2::TreePath, in array context, adds the Gtk2::TreeViewColumn, and $x and $y translated to be relative to the cell."

On Linux, this works fine and I can get the column number. However, on Windows (with newest Camelbox), get_path_at_pos doesn't seem to work in array context! All it gives back is the path object.

How can I remedy this? How can I
a) either fix get_path_at_pos's behavior, or
b) get the column number of the clicked cell in some other way?

Thanks in advance for any insight.

The code, which demonstrates both my intent (on Linux, where it works) and the problem (on Windows, where it doesn't) is below:
################################################ #!/usr/bin/perl use strict; use warnings; use Gtk2 -init; use Gtk2::Ex::Simple::List; use Glib ':constants'; my %activity_list = ( O => '<span color="#7f7f00"><b>One</b></span>', M => '<span color="#7f007f"><b>Two</b></span>', U => '<span color="#007f7f"><b>Five</b></span>', E => '<span color="#00cf00"><b>Three, Sir, Three!</b></span>', A => '<span color="#ff0000"><b>BOOM</b></span>' ); my %activity_order = ('O' => 'M', 'M' => 'U', 'U' => 'E', 'E' => 'A', +'A' => 'O'); my %activities_rev = reverse %activity_list; my $win = Gtk2::Window->new; $win->set_border_width (6); $win->signal_connect (delete_event => sub { Gtk2->main_quit; }); my $tslist = Gtk2::Ex::Simple::List->new ( "Special column" => 'markup', "Normal column" => 'text' ); $win->add ($tslist); $tslist->get_selection->set_mode ('single'); $tslist->set_reorderable(FALSE); $tslist->set_column_editable (0, FALSE); $tslist->set_column_editable (1, TRUE); my $dtslist = $tslist->{data}; push @$dtslist, [ $activity_list{M}, "text" ], [ $activity_list{O}, "t +ext2" ]; my @columns = $tslist->get_columns; $tslist->signal_connect('button-release-event' => sub { my ($self, $event) = @_; my ($path, $column, $cell_x, $cell_y) = $tslist->get_path_a +t_pos ($event->x, $event->y ); # <------- !!!!! if ($path) { if ($column == $columns[0]) { my $row = $path->to_string; my $value = $dtslist->[$row][0]; $dtslist->[$row][0] = $activity_list{$activity_order{$ +activities_rev{$value}}}; } } }); $win->show_all; Gtk2->main; ################################################

PS. Please direct me to the right place if this is not the right place to ask this.

In reply to Gtk2::TreeView get_path_at_pos doesn't return array on Windows by kikuchiyo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.