PHP-GTK
Thursday, October 23, 2014 
download | documentation | applications | faq | changelog | resources 


search for in the  


previousGtkWindow::get_destroy_with_parent
GtkWindow::get_focus_on_mapnext

Last updated: Sun, 12 May 2013
view this page in English

GtkWindow::get_focus

GtkWidget get_focus ();

Retrieves the current focused widget within the window. Returns null if no widget has the focus.

Note that this is the widget that would have the focus if the toplevel window focused; if the toplevel window is not focused then

$widget->flags() & Gtk::HAS_FOCUS
will not be > 0 for the widget.

Example 159. Using GtkWindow::get_focus()

<?php
/**
* Start the script and use <Tab> key to cycle the focus
* through the buttons. You will see the label of the focused
* button be echoed to the console every second.
* Also try to activate another window while the script is
* running.
*/
 
$wnd  = new GtkWindow();
$vbox = new GtkVBox();
 
//Create ten buttons we can focus with <Tab>
for ($nA = 1; $nA <= 10; $nA++) {
    $button = new GtkButton('Button ' . $nA);
    $vbox->add($button);
}
 
/**
* This method will write the label of the current
* focused widget to the console
* It returns true, so that the interval doesn't stop
*/
function echoFocusedLabel($wnd)
{
    //get_focus() returns the widget
    if ($wnd->get_focus()->flags() & Gtk::HAS_FOCUS) {
        $focus = 'focus is set';
    } else {
        $focus = 'focus is NOT set (window not focused?)';
    }
    echo $wnd->get_focus()->get_label() . ' - ' . $focus . "\r\n";
    return true;
}
 
//add a timeout of one second, so that the echoFocusedLabel
//method will echo the label of the focused widget every second
Gtk::timeout_add(1000, 'echoFocusedLabel', $wnd);
 
$wnd->add($vbox);
$wnd->connect_simple('destroy', array('gtk', 'main_quit'));
$wnd->show_all();
Gtk::main();
?>

See also: activate_focus() , set_focus()


User Contributed Notes
gtk.gtkwindow.method.get_focus.php
add a note about notes
There are no user contributed notes for this page.


previousGtkWindow::get_destroy_with_parent
GtkWindow::get_focus_on_mapnext

Last updated: Sun, 12 May 2013
view this page in English


credits 

PHP  Copyright © 2001-2014 The PHP Group
 All rights reserved.
Last updated: Sun May 12 20:51:01 2013 CEST