GtkFileSelection

This example shows how to display a GtkFileSelection.

Once you understand this basic example, you can check out the more advanced Extending GtkFileSelection page, which wraps the standard GtkFileSelection within a class with richer functionality.

<?php
// ENVIRONMENT CHECK
if (!class_exists("gtk")) {
    die(
"The PHP-GTK2 class was not detected "
      
. "and therefore this file cannot continue");
    }

// ENVIRONMENT CHECK

// CREATE THE INITIAL WINDOW WIDGET
$window = &new GtkWindow();

//NAME THE WIDGET
$window->set_title("Dialog Window");

// NOW FOR SOME AESTHETICS (SCREEN POSITION FOR THE WIDGET)
$window->set_position('GTK_WIN_POS_CENTER');

// NOW FOR SOME AESTHETICS (INITIAL SIZE OF THE WIDGET)
$window->set_size_request(300, 200);

//DECLARE A BUTTON WIDGET
$button = new GtkButton('Press');

/**
  * LINK THE BUTTON WIDGET TO THE SPECIFIED
  * SIGNAL HANDLER (CALL_BACK METHOD/FUNCTION)
  */
$button->connect('clicked', 'fileDialog');

/**
  * ADD THE BUTTON WIDGET TO THE
  * WINDOW WIDGET (WHICH NOW BECOMES
  * A CONTAINER OF WIDGETS)
  */
$window->add($button);

// CREATE THE INITIAL WINDOW

/* CREATE THE CALL_BACK FUNCTION
* FOR THE SIGNAL HANDLER
*/
function fileDialog() {
   
// OPEN THE FILE DIALOG BOX
   
$fileBox = new GtkFileSelection('File Box');
       
   
// CREATE THE OKAY BUTTON ON THE FILE DIALOG BOX
   
$ok_button = $fileBox->ok_button;
   
   
/**
     * LINK THE BUTTON WIDGET TO THE SPECIFIED SIGNAL
     * HANDLER (CALL_BACK METHOD/FUNCTION)
     */
   
$ok_button->connect('clicked', 'destroy');
           
   
// CREATE THE CANCEL BUTTON ON THE FILE DIALOG BOX
   
$cancel_button = $fileBox->cancel_button;
   
   
/**
     * LINK THE BUTTON WIDGET TO THE SPECIFIED
     * SIGNAL HANDLER (CALL_BACK METHOD/FUNCTION)
     */
   
$cancel_button->connect('clicked', 'destroy');
   
   
$fileBox->show();
}
/**
  * CREATE THE CALL_BACK FUNCTION FOR
  * THE SIGNAL HANDLER
  */
function destroy()  {
   
gtk::main_quit();
}

/**
* CREATE THE CALL_BACK FUNCTION
* FOR THE SIGNAL HANDLER
*/

/**
* SHOW THE WINDOW WIDGET
* (WHICH TECHNICALLY BECAME A CONTAINER
* AFTER WE ADDED THE BUTTON WIDGET)
*/
$window->show_all();

/**
* FOR LACK OF BETTER TERMINOLOGY; WE'RE
* TELLING THE SCRIPT TO STOP HERE AND
* MONITOR THE ACTIVE WIDGETS/CONTAINERS
* FOR SIGNALS TO PASS TO CALL_BACK
* FUNCTION AND/OR METHODS
*/

Gtk::main();
?>

Comments

about comments on "CREATE".

there is a probleme with comments here :

    // CREATE THE OKAY BUTTON ON THE FILE DIALOG BOX
    $ok_button = $fileBox->ok_button;

this is a reference to internal File Selection Dialog box. This is not a NEW button (create).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.