Re: spinbutton behaviour and key bindings for treeview
- From: muppet <scott asofyet org>
- To: BoÅtjan ÅpetiÄ <igzebedze auch eu org>
- Cc: gtk-perl-list gnome org
- Subject: Re: spinbutton behaviour and key bindings for treeview
- Date: Mon, 4 Apr 2005 20:31:18 -0400
On Apr 3, 2005, at 5:22 PM, BoÅtjan ÅpetiÄ wrote:
Yes. Connect to the key-press-event of the tree view, handle events
for
which $event->keyval == $Gtk2::Gdk::Keysyms{ Delete } and return TRUE.
When you edit a cell, the tree view doesn't have focus and thus
doesn't
receive events either -- so your signal handler never gets called.
... well, i don't work. here's what i have:
sub on_treeview_teachers_key_release_event {
my ($where, $now) = @_;
if ($now->keyval == 65535) {
don't use magic numbers. do this, instead:
use Gtk2::Gdk::Keysyms;
if ($now->keyval == $Gtk2::Gdk::Keysyms{Delete}) {
&on_button_teachers_del_clicked;
}
return 1;
returning true here prevents the default handlers from running; you
should return true only if you handled the event.
}
... ok, it's key_release, but i guess it's irrelevant?
maybe, maybe not. why did you choose release?
Here's a working example i just cooked up:
#!/usr/bin/perl -w
use strict;
use Glib ':constants';
use Gtk2 -init;
use Gtk2::Gdk::Keysyms;
my $window = Gtk2::Window->new;
$window->signal_connect (destroy => sub {Gtk2->main_quit});
$window->set_default_size (200, 200);
my $model = Gtk2::ListStore->new ('Glib::String');
foreach (qw(one two three four five six seven eight nine ten eleven
twelve)) {
$model->set ($model->append, 0, $_);
}
my $treeview = Gtk2::TreeView->new ($model);
my $cell = Gtk2::CellRendererText->new;
$cell->set (editable => TRUE);
$cell->signal_connect (edited => sub {
my ($cell, $path_string, $new_text) = @_;
$model->set ($model->get_iter (Gtk2::TreePath->new_from_string
($path_string)),
0, $new_text);
});
$treeview->insert_column_with_attributes (-1, 'Foo', $cell, text => 0);
$treeview->signal_connect (key_press_event => sub {
my ($widget, $event) = @_;
if ($event->keyval == $Gtk2::Gdk::Keysyms{Delete}) {
warn "Delete pressed!\n";
my ($model, $iter) = $widget->get_selection->get_selected;
if ($iter) {
warn " deleting ".$model->get_path ($iter)->to_string."\n";
$model->remove ($iter);
return TRUE;
} else {
warn " nothing selected, ignoring\n";
}
}
return FALSE;
});
$window->add (Glib::Object::new ('Gtk2::ScrolledWindow',
child => $treeview,
shadow_type => 'in',
hscrollbar_policy => 'automatic',
vscrollbar_policy => 'automatic'));
$window->show_all;
Gtk2->main;
--
muppet <scott at asofyet dot org>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]