PHP-GTK GtkFileSelection function

From Code Trash
Jump to: navigation, search

GtkFileSelection

Example 1

<?php
//Creating and initialising the file selection prompt
$filePrompt = new GtkFileSelection('GtkFileSelection Demo');
$filePrompt->connect_simple(
    'destroy',
    array('Gtk', 'main_quit')
);
 
//Adding a quit button that destroys the prompt
$filePrompt->cancel_button->set_label('Quit');
$filePrompt->cancel_button->connect_simple(
    'clicked',
    array($filePrompt, 'destroy')
);
 
//Add an OK button that displays the file selected on click
$filePrompt->ok_button->set_label('Show the file');
$filePrompt->ok_button->connect('clicked', 'showFile');
 
//Callback function that displays the file name
function showFile($okbutton)
{
    $filePrompt = $okbutton->get_toplevel();
    $fileName = $filePrompt->get_filename();
    $message = new GtkMessageDialog(
        null,
        0,
        Gtk::MESSAGE_INFO,
        Gtk::BUTTONS_OK,
        'You selected: ' . $fileName
    );
    $message->run();
    $message->destroy();
}
 
//Show the prompt and start the main loop
$filePrompt->show();
Gtk::main();
?>

Referred from : http://gtk.php.net/manual/en/gtk.gtkfileselection.constructor.php


Example 2

<?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();
?>

Referred from http://php-gtk.eu/widgets/gtkfileselection - You can find more information from this site.


Inspecting class methods