PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 409: How to disconnect a signal?
Written by kksou   
Tuesday, 15 January 2008
Problem

This is in response to Manar's post titled "How to disconnect an event?"

He has set up a button-press-event and want to disconnect the signal as shown below:

How to disconnect a signal?


Solution

Sample Code
1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
20   
21   
22   
23   
24   
25   
26   
27   
28   
29   
30   
31   
32   
33   
34   
35   
<?php
$window = new GtkWindow();
$window->set_size_request(400, 175);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());

// display title
$title = new GtkLabel("Disconnecting a signal");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$title->set_size_request(-1, 40);
$vbox->pack_start($title, 0);
$vbox->pack_start(new GtkLabel(), 0);

$vbox->pack_start(new GtkLabel('Click on the blue sqaure once. '.
    'It will change to green.'), 0);

$signal_id = setup_colorbox('#0000ff', 'blue', $vbox); // note 1

$window->show_all();
Gtk::main();


function setup_colorbox($color, $label, $vbox) {
    $hbox = new GtkHBox();
    $hbox->set_size_request(30, 30);
    $eventbox = new GtkEventBox();
    $eventbox->add($hbox);
    $eventbox->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse($color));

    $signal_id = $eventbox->connect('button-press-event', 
        'on_button_press'); // note 2

    $hbox = new GtkHBox();
    $vbox->pack_start($hbox, 0);
  • Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
  • Registration is free and immediate.
  • Have some doubt about the registration? Please read this forum article.
Explanation
  1. Set up the blue color box. Note that here we store the signal handler id in the variable $signal_id.
  2. Set up the button-press-event event. Don't forget to take note of the signal handler id.
  3. Change the color box from blue to green.
  4. Disconnect the button-press-event signal.

Related Links
 

Add comment


Security code
Refresh

< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2012. kksou.com. All Rights Reserved