« Return to Thread: emit_stop_by_name

Re: emit_stop_by_name

by someGuy :: Rate this Message:

Reply to Author | View in Thread

kksou wrote:
> 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.
>
>
>  

I played around with your example and came up with the following. You
don't have to manually insert the characters and the filter works even
though the logic of the if() statement may seem "backwards." Other than
that, it's pretty straightforward, IMHO.

Hope this helps.

<?php

function onInsert($widget, $event)

{

    $result = false;

    $character = chr($event->keyval);

    if(!preg_match("/[0-9a-fA-F]/", $character))

    {

        $result = true;

    }

    return($result);

} // onInsert()

$entry = new GtkEntry();

$entry->connect('key-press-event', 'onInsert');

$window = new GtkWindow();

$window->set_size_request(400, 200);

$window->connect_simple('destroy', array('Gtk','main_quit'));

$window->connect('destroy', array('Gtk','main_quit'));

$window->add($entry);

$window->show_all();

Gtk::main();

?>


-Ron T.

--
PHP-GTK General Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

 « Return to Thread: emit_stop_by_name