On Sun, 2004-09-05 at 14:32, Jens Wilke wrote:

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

Sorry for the late reply.

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:

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

sub row_moved {
      ($model, $path, $iter, $treeview) = @_;
      $selection= $treeview->get_selection();
              $oiter = $selection->get_selected;
              $data = $model->get($oiter, 0);
              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

row-inserted will also be triggered if you manually/programmatically add
a new row, won't it?  The whole reorderable tree view stuff does indeed
come up quite often, so if there's a proper solution to finding out
if/when a row has been moved and which one it was, then it's a prime
candidate for the FAQ.

The only semi-cool way I know of is to set some kind of global flag if
drag-begin is fired, check for that flag in row-inserted to decide if it
was a d'n'd-induced insertion, and unset the flag in drag-end.

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

I think this is too basic to go in the FAQ.  Pretty much all tutorials
cover this.

* 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');
      $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.

And we usually try not to encourage people to synthesize events.  What
did you need it for?  Are other people likely to run into the same


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