Re: emit_stop_by_name

From: Date: Fri, 27 Oct 2006 07:09:06 +0000
Subject: Re: emit_stop_by_name
References: 1 2 3 4  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-7380@lists.php.net to get a copy of this message
Steph Fox wrote: > What happens if you simply have the function/method return TRUE where you > would've called emit_stop? This should propagate, so long as it's an event > signal you're dealing with. > > That technique seems to have been used successfully in place of both > emit_stop_by_name and its newer cousin throughout the GTK+ source, so > depending on the nature of the signal you're dealing with, it could be > worth > a try. > Hi Steph, Yes, return TRUE works for most of the signals. But when it comes to 'insert-text' for GtkEntry. It doesn't seem to work. Here's an example. Scenario: To set up a GtkEntry that accepts only hexadecimal numbers. With php-gtk1, the code is short and sweet with the use of emit_stop_by_name() <?php if( !extension_loaded('gtk')) dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); $window = &new GtkWindow(); $window->connect('destroy', array('Gtk','main_quit')); $entry = &new GtkEntry(); $entry->connect('insert-text', 'on_insert'); $window->add($entry); $window->show_all(); Gtk::main(); function on_insert($widget, $text, $len, $position) { $text = substr($text, 0, $len); if (!preg_match("/[0-9a-fA-F]/", $text)) { # not hexadecimal number - just gobble it up $widget->emit_stop_by_name('insert-text'); } } ?> With php-gtk2, return TRUE doesn't work as expected. Thought it would stop the signal propagation. But the non-hexadecimal character still gets displayed in GtkEntry. <?php $window = new GtkWindow(); $window->set_size_request(400, 200); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->connect('destroy', array('Gtk','main_quit')); $entry = new GtkEntry(); $entry->connect('insert-text', 'on_insert'); $window->add($entry); $window->show_all(); Gtk::main(); function on_insert($widget, $text, $len, $position) { $text = substr($text, 0, $len); if (!preg_match("/[0-9a-fA-F]/", $text)) { echo "not hexadecimal number!\n"; #$widget->emit_stop_by_name('insert-text'); return true; } return false; } ?> I have done some trial and errors, and managed to get the same effect in php-gtk2 by capturing 'key-press-event' in $windows and then manually insert the characters into the GtkEntry. Though the effect is the same, the solution, if emit_stop_by_name() is available, would be more straightforward. Regards, /kksou -- View this message in context: http://www.nabble.com/emit_stop_by_name-tf2513138.html#a7025505 Sent from the Php - GTK - General mailing list archive at Nabble.com.

« previous php.gtk.general (#7380) next »