PHP-GTK2 Cookbook Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Re:How to disconnect an event? (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:How to disconnect an event?
#21
mkhattar (User)
Fresh Boarder
Posts: 8
graphgraph
User Offline Click here to see the profile of this user
How to disconnect an event? 12 Months ago Karma: 0  
Hello, :)

I have an application in which i connect a gtkeventbox to a function.
$handler_id = EventBox->connect('button-press-event', array($this, 'function'));
Then at later stage i need to disconnect it using disconnect($handler_id); but it's not working. Anyone knows a way to disconnect an event from gtkeventbox?

P.S.: I really like your site, It's been very helpful for me:)
Regards,
Manar
 
  The administrator has disabled public write access.
#24
kksou (Admin)
Admin
Posts: 443
graph
User Online Now Click here to see the profile of this user
Re:How to disconnect an event? 11 Months, 3 Weeks ago Karma: 8  
Hi Manar,

The syntax
Code:
disconnect($handler_id);
is correct. Would you want to post some lines of code here so that we can see which part is not working right? Also, would suggest that you do something like:
Code:
$handler_id = EventBox->connect('button-press-event',
    array($this, 'function')); 
echo "bp1: $handler_id"
.
.
.
echo "bp2: $handler_id";
disconnect($handler_id)
Make sure the $handler_id in bp1 and bp2 are the same. If they are the same, things should work. If they are not the same (or its value is null or 0), then try to find out where did it get changed. Hope this helps. Regards, /kksou
 
 
Last Edit: 2008/01/14 13:04 By kksou.
  The administrator has disabled public write access.
#27
kksou (Admin)
Admin
Posts: 443
graph
User Online Now Click here to see the profile of this user
Re:How to disconnect an event? 11 Months, 3 Weeks ago Karma: 8  
Hi Manar,

Have just posted a sample code that shows the disconnecting of signals:
http://www.kksou.com/php-gtk2/articles/disconnect-a-signal.php

Compare this with your code. I think you should be able to find where it's not working.

Regards,
/kksou
 
  The administrator has disabled public write access.
#32
mkhattar (User)
Fresh Boarder
Posts: 8
graphgraph
User Offline Click here to see the profile of this user
Re:How to disconnect an event? 11 Months, 3 Weeks ago Karma: 0  
Hello:) Thanks a lot for your reply!

The case that I have is not the same. I have an eventbox that should call 2 different functions depending on the condition. But this is not working because when the eventbox connects to function1, it works fine but when it calls the second function it is still connecting to the first function even if I am using the disconnect method.

In the example you gave me, my case is similar to pressing the eventbox the first time and calling function on_button_press, then the second time eventbox should stop connecting to function1 and connect to function2 instead. The piece of code that I am trying to use and is showing warnings is shown below:

function on_button_press($eventbox, $event) {
$eventbox->modify_bg(Gtk::STATE_NORMAL,
GdkColor::parse('#00ff00')); // note 3

global $signal_id;
$eventbox->disconnect($signal_id); // note 4
$signal_id2 = $eventbox->connect('button-press-event',
'on_button_press2');
}
function on_button_press2($eventbox, $event) {
$eventbox->modify_bg(Gtk::STATE_NORMAL,
GdkColor::parse('#0000ff'));
global $signal_id2;
$eventbox->disconnect($signal_id2); // note 4
$signal_id = $eventbox->connect('button-press-event',
'on_button_press');
}

Do you have any idea about how to use the same eventbox for calling two different functions?

Thanks for your help kksou,
Manar
 
  The administrator has disabled public write access.
#33
kksou (Admin)
Admin
Posts: 443
graph
User Online Now Click here to see the profile of this user
Re:How to disconnect an event? 11 Months, 3 Weeks ago Karma: 8  
Hi Manar,

Take a look at this example then:

Recipe 414: How to switch signal handlers on the fly - Part 1 - using connect disconnect?

Is this what you have in mind?

Regards,
/kksou
 
  The administrator has disabled public write access.
#56
mkhattar (User)
Fresh Boarder
Posts: 8
graphgraph
User Offline Click here to see the profile of this user
Re:How to disconnect an event? 11 Months ago Karma: 0  
Great:)

It worked! the trick was to make the same signal id for all the events happening on the same eventbox. I was changing it every time.

Thanks for your support kksou:),
Manar
 
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

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