FAQ



Hi,

may be these two can be added to the FAQ...

Rgds, Jens

Treeview reorderable
------------------------

How to get the model data on signal-connect "row-inserted", since
$data = $model->get($iter, 0) seems to be undef by default.
The problem is, that this iter is newly created, after "row-inserted"
and for this reason, it's model data are undef.
But the selection of the former iter is still available.
It is possible to use this selection to know, which data were moved:

$treeview->set_reorderable(1);
$model->signal_connect('row-inserted', \&row_moved, $treeview);

sub row_moved {
        ($model, $path, $iter, $treeview) = @_;
        $selection= $treeview->get_selection();
        if($selection){
                $oiter = $selection->get_selected;
                $data = $model->get($oiter, 0);
        }else{
                print"I'm a child iter, don't ask me for data\n";
                # the childeren are displayed, but the model seems to be undef,
                # as the children of $oiter are.
                # The subtree should completly be recreated
        }
}

=====================================

Receiving/Emitting  Signals
-------------------------------
* Receiving Keystrokes

This signal handler reacts on keystrokes.

$widget->signal_connect (key_press_event => sub {
                ($widget, $event) = @_;
                $data = $event->keyval ;
}

# $event->keyval receives the code of the stroked key


* Emitting Signals

It is possible to emit signals to widgets to simulate events, such as
key- or button press events.
Signals are emitted to a widget by a
Gtk2::Gdk::Event (link: /doc/pod/Gtk2/Gdk/Event.html) and its 
type (link: /doc/gtk2-perl-tut/sec-Events.html#enum_Gtk2_Gdk_EventT)

        $eventt = Gtk2::Gdk::Event::Key->new('key-press');
        $event->keyval('102');
        $button->signal_connect (clicked => sub
{  $widget->signal_emit('key_press_event', $event) } );

widget will receive a keystroke of key 102 'F', if button is clicked.

-------------------------------------------------------





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