Why does the add() method in PHP-GTK cause 2 parent-set signals to be emmitted?

Posted by JW on Stack Overflow See other posts from Stack Overflow or by JW
Published on 2010-04-30T02:41:57Z Indexed on 2010/04/30 2:47 UTC
Read the original article Hit count: 335

Filed under:
|
|

I am going through the book PHP-GTK and trying out listing 4-1

One thing I notice is that with the following code some odd output occurs:

<?php
//listing4-1b.php
function setParentFunction($widget)
    {
    //get the widgets parent
    $parent = $widget->get_parent();

    //echo a mssg about the widget
    echo 'The ' . get_class($widget) .' has ';

    if (isset($parent))
        {
        //ech the class of the parent widget
        echo 'a '. get_class($parent);
        }
    else    {
        //the widget does not have a parent
        echo 'no';
        }
    echo " parent. \n";
    }

//start with  widgets
$frame = new GtkFrame('i am a frame');
$button = new GtkButton('i am a button');

//connect the event to our test function
$button->connect('parent-set', 'setParentFunction');

$frame->add($button);

?>

The output is:

# php listing4-1b.php
The GtkButton has a GtkFrame parent.
The GtkButton has no parent.

Now, I can understand why the first signal is getting emitted and causing the first line of output:

The GtkButton has a GtkFrame parent.

But, I don't understand why the 2nd 'parent change' is reported to have happened:

The GtkButton has no parent.

I expected only to see the signal getting emitted / and handled only once in this short script.

Does this 2nd signal get emmitted when the script closes down?

© Stack Overflow or respective owner

Related posts about php-gtk

Related posts about signals