Re: A $treeview->set_cursor question
- From: Yuri Myasoedov <ymyasoedov yandex ru>
- To: "aullidolunar gmail com" <aullidolunar gmail com>,	"gtk-perl-list gnome org" <gtk-perl-list gnome org>
- Subject: Re: A $treeview->set_cursor question
- Date: Wed, 02 Apr 2014 20:27:49 +0400
02.04.2014, 19:29, "aullidolunar gmail com" <aullidolunar gmail com>:
my problem is if the current cell is "1", when hit up key doesn't go to "5" as expected, it goes to 
"4"....any ideas, please?
Hi!
I guess, you need to preserve your handler window1_key_press_event_cb from propagating the signal, when the 
focus is at the top or at the bottom of your treeview. Otherwise, set_cursor is called twice. Note, that 
returning TRUE stops a signal:
sub window1_key_press_event_cb {
    my ($widget, $event, $data) = @_;
    my $tv = $data->{'treeview'};
    if ($event->keyval == $Gtk2::Gdk::Keysyms{Up}) {
        return moveUP($tv);
    } elsif ($event->keyval == $Gtk2::Gdk::Keysyms{Down}) {
        return moveDown($tv);
    }
}
You also need to fix moveUP and moveDown subroutines to return TRUE or FALSE:
sub moveUP {
    my $treeview = shift;
    my ($path, $focus_column) = $treeview->get_cursor;
    my $modelSort = $treeview->get_model();
    if (!$path->prev) {
        $path = undef;
        my $totalItems = $modelSort->iter_n_children();
        my $iter = $modelSort->iter_nth_child(undef, $totalItems-1);
        $path = $modelSort->get_path($iter);
        $treeview->set_cursor($path, $focus_column);
        return TRUE;
    }
    $path = undef;
    return FALSE;
}
sub moveDown {
    my $treeview = shift;
    my ($path, $focus_column) = $treeview->get_cursor;
    my $modelSort = $treeview->get_model();
    my $iter = $modelSort->get_iter($path);
    if (!defined $modelSort->iter_next($iter)) {
        $path = undef;
        $path = Gtk2::TreePath->new_first();
        $treeview->set_cursor($path, $focus_column);
        return TRUE;
    }
    $path = undef;
    return FALSE;
}
Try once again with these fixes.
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]