This snippet loads all the XPM pictures it can find in its directory, and displays them horizontally in a scrolled window, as thumbnails.
<?php
/**
* pixmaps_example.php
*
* Loads all xpm pictures in the script directory
* and displays it horizontally in a scrolled window.
*
* (C) 2005 Joachim Werner
* joachim.werner@diggin-data.de
*/
if( !extension_loaded('gtk')) {
dl( 'php_gtk.' . PHP_SHLIB_SUFFIX);
}
$window = &new GtkWindow();
$window->connect('destroy', 'shutdown');
$window->connect('delete-event', 'delete_event');
$window->set_title( "XPM Viewer" );
// landscape window
$window->set_usize( 400, 150 );
$window->set_border_width( 10 );
$window->set_position(GTK_WIN_POS_CENTER);
$window->realize();
$sw = &new GtkScrolledWindow();
$hbox = &new GtkHBox();
// Make all xpm buttons within the HBox homogenous:
$hbox->set_homogeneous(TRUE);
// Add all xpm's in this script's directory
$counter = AddXPMs(dirname( __FILE__), $window, $hbox);
// Alert, if no xpm files were found
if( $counter==0 ) {
$label = &new GtkLabel( "$counter xpm's found in "
. dirname( __FILE__) );
$hbox->pack_start( $label );
}
$sw->add_with_viewport($hbox);
$window->add($sw);
$window->show_all();
gtk::main();
// {{{ AddXPMs
/**
* Adds all XPM files in $startdir to the $window's $hbox
*/
function AddXPMs ($startdir, &$window, &$hbox) {
$clTrans = &new GdkColor('#000000' );
// get an object to the start directory
$d = dir( $startdir );
$counter = 0;
// loop through all entries
while($entry=$d->read()) {
// if we found an XPM file
if( substr( $entry, -4) == ".xpm") {
$counter++;
echo "$entry\n";
$arPix = gdk::pixmap_create_from_xpm(
$window->window,
$clTrans,
$d->path . "/" . $entry );
// Create a pixmap
$pxmBdB = & new GtkPixmap( $arPix[0], $arPix[1] );
$pxmBdB->padding = 20;
// Create a button
$btn = &new GtkButton();
// Add pixmap to button
$btn->add($pxmBdB);
// Add button to the HBox
$hbox->pack_start($btn);
}
}
$d->close();
return $counter;
}
// }}}
function delete_event() {
return false;
}
function shutdown() {
print("Shutting down...\n");
gtk::main_quit();
}
?>
Commenti recenti
47 settimane 3 giorni fa
48 settimane 3 giorni fa
48 settimane 6 giorni fa
51 settimane 3 giorni fa
1 anno 19 settimane fa
1 anno 23 settimane fa
1 anno 27 settimane fa
1 anno 27 settimane fa
1 anno 27 settimane fa
1 anno 44 settimane fa