Creates a new instance of a GtkTree.
Because GtkTree extends GtkContainer, it may contain one or more children. These children should be GtkTreeItem widgets.
Ejemplo 49. Building a tree of a file structure.
<?php dl('php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so')); // Creates a tree representing a directory. function &createTreeFromDirectory($dir) { // Create a new tree $tree =& new GtkTree; // Make sure dir is a directory if (is_dir($dir)) { // Open directory and read in file names $dir_handle = opendir($dir); while (($file = readdir($dir_handle)) !== false) { // Create a new tree item for each file $treeItem = &new GtkTreeItem($file); $treeItem->show(); // Add the tree item to the tree $tree->append($treeItem); // If the file is a directory and not . or .. call // this function recursively if (is_dir($dir . '/' . $file) && strpos($file, '.') !== 0) { $treeItem->set_subtree(createTreeFromDirectory($dir . '/' . $file)); } } // Close the directory closedir($dir_handle); } // Return the tree return $tree; } // The directory to display $directory = '/path/to/some/directory'; // Create a window to display the file structure $window =& new GtkWindow; // Add a frame $frame =& new GtkFrame($directory); $window->add($frame); // Add the tree $tree = createTreeFromDirectory($directory); $frame->add($tree); $window->show_all(); gtk::main(); ?> |