Re: gtk tree get selected field



Hey Peter,

sub button_pressed_event {
       my ($widget, $event) = @_;

       my $treeselection = $tview->get_selection;

       my ($x, $y)=$event->get_coords;
       my $mouse_path=$tview->get_path_at_pos($x, $y);
       if($mouse_path) {
               $tview->set_cursor($mouse_path);
               $treeselection->select_path($mouse_path);
       }

       my ($path, $column) = $tview->get_cursor;
       print $column->get_sort_column_id . "\n";
}

So the get_cursor has update the column if I have a left button
clicked. If I have only the right button (button 3) even if I use the
set_cursor it does not update the column. Is it a bug or a feature?

However I found a simple solution, just I was blind to find it earlier:

(path, column, cell_x, cell_y) = $tree_view->get_path_at_pos ($x, $y)


Cheers,
Attila

On Tue, Oct 12, 2010 at 2:54 PM, Peter Juhasz <peter juhasz83 gmail com> wrote:
my @columns = $tview->get_columns;

sub button_pressed_event {
   my ($widget, $event) = @_;
   my ($path, $column) = $slist->get_cursor;

   # do what you want with $column...

   # or if you want to check for a specific column:
   if ($column == $columns[0]) {
       # do whatever with it
   }

Péter Juhász

On Tue, Oct 12, 2010 at 1:11 PM, Attila bardi <attila bardi gmail com> wrote:
Hey,

maybe I missed something but I can't find the solution (if it exist):
I have a tree with several columns. When I have the selected row I
would like to know which column was under the mouse pointer.
Is it possible to have it? How?

Thanks,
Attila

sub button_pressed_event {

       my ($widget, $event) = @_;
       my $treeselection = $tview->get_selection;
       my ($x, $y)=$event->get_coords;
       my $mouse_path=$tview->get_path_at_pos($x, $y);
       if($mouse_path) {
               $treeselection->select_path($mouse_path);
       }

       my $treeiter = $treeselection->get_selected;
       if ( $treeiter ) {
               if ( $event->button == 3) {
                       my $value1 = $model->get($treeiter,0);
                       my $value2 = $model->get($treeiter,4);
                       printf "first: " . $value1 . " second: " .
$value2 . "\n";
                       my $menu = Gtk2::Menu->new();
                       my $menuitem1 =
Gtk2::ImageMenuItem->new_from_stock('gtk-copy');
                       $menuitem1->signal_connect(activate => sub {
                               printf "selected :" . $value1 . "\n";
                               $clipboard->set_text($value1);
                       });
                       my $menuitem2 = Gtk2::MenuItem->new("$value2");

                       $menu->add($menuitem1);
                       $menu->add($menuitem2);
                       $menu->show_all;
                       $menu->popup(
                               undef, # parent menu shell
                               undef, # parent menu item
                               undef, # menu pos func
                               undef, # data
                               3,
                               $event->time
                       );
                       return TRUE;
               }
       } else {
               printf "No row selected\n";
       }
       return FALSE;
}

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






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