Example

Example – How to use Gtk_FileDrop

Using Gtk_FileDrop

General setup

<?php
$accepted_types 
= array(
    
'text/html',
    
'text/plain',
    
'.dat'
);
Gtk_FileDrop::attach($widget$accepted_types);
?>

Here we set up the array of accepted file types: The widget shall accept files with MIME-Type text/html, text/plain and files ending with .dat. After this we set up the $widget to accept this files.

Accepting directories

<?php
$accepted_types 
= array(
    
'inode/directory',
);
?>

The MIME type inode/directory has to be used if the widget shall accept directories.

When a file is dropped over a widget which accepts directories only, the directory of the filename is used.

Setup with callback

<?php
function filesDropped($widget$arFiles) {
    foreach(
$arFiles as $strFile) {
        echo 
"The file \"$strFile\" has been dropped\r\n";
    }
}

$accepted_types = array(
    
'text/html',
    
'text/plain',
    
'.dat'
);
Gtk_FileDrop::attach($widget$accepted_types'filesDropped'false);
?>

In this example we use a callback function to print out all dropped files to the console. Further we determine the fourth parameter as false which means that the widget's value is not changed automatically.

To use the callback with objects, you pass an array with the reference of the object:

Using a callback

<?php
Gtk_FileDrop
::attach($widget$accepted_types, array( &$this'filesDropped'));
?>

Working example

<?php
if (!extension_loaded('gtk')) {    
    
dl('php_gtk.' PHP_SHLIB_SUFFIX);
}
require_once(
'Gtk/FileDrop.php');

$window = &new GtkWindow();
$window->set_default_size(30030);
$window->connect_object('destroy', array('gtk''main_quit'));
$window->show();

$entry =& new GtkEntry();
$window->add($entry);
$entry->set_text('drop text files on me');
Gtk_FileDrop::attach($entry, array('text/plain'));
    
$window->show_all();
gtk::main();
?>
Drops handled on different widget types (Previous) Gtk_ScrollingLabel (Next)
Last updated: Tue, 21 Oct 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.