01 May 2013 - After the site upgrade, all passwords were reset and you will need to ask the site for a login reset on your first connection.
This examples shows how to discover on your own what the
methods for a given widget are, from the actual current
implementation, instead of relying on documentation. You can
obviously use it to examine other classes, but this sample code
shows the methods of classes Gtk and
GtkWindow.
In addition, this example shows how to line up vertically
by the top the contents of panes in a GtkHBox,
just like vertical-align does in CSS. In this
example, we use it to align the two lists because they are of
very different lengths.
<?php
/**
* Author: Martin Fasani [ www.movil.be ]
* 2006-11-06 Revisited by FG Marand
* to demo vertical alignment too
*
* The example demonstrates this type of layout.
* +----------------------+
* | Hello ... |
* +----------------------+
* | text11 text21 |
* | text12 text22 |
* | text23 |
* | text24 |
* +----------------------+
*
*/
if (!class_exists('gtk')) {
die("Please load the php-gtk2 module in your php.ini\r\n");
}
$gtk = new Gtk();
$wnd = new GtkWindow();
$wnd->set_title('Hello world');
$wnd->set_size_request(480, 600 );
$wnd->connect_simple('destroy', array('gtk', 'main_quit'));
// Main container
$vb = new GtkVBox();
// Upper pane
$out = "HELLO PHP-GTK2. This is version ".$gtk->get_version();
$lblHello = new GtkLabel($out);
$vb->add($lblHello);
// Scrollable lower pane
$sw = new GtkScrolledWindow(); // Create a scrolled window
$hb = new GtkHBox(); // Create a HBox
$sw->add_with_viewport($hb); // Fit the HBox into the SW
$vb->add($sw); // And add the SW to the VBox
/**
* Now prepare the two subpanes in the lower pane
*/
// Gtk methods go into the leftmost subpane
$gtkmain_methods = get_class_methods(get_class($gtk));
$out = '';
foreach ($gtkmain_methods as $name => $value) {
$out .= "$name : $value\n";
}
$lblGtk = new GtkLabel($out);
$lblGtk->set_alignment(0,0);
$frameGtk = new GtkFrame('Gtk methods');
$frameGtk->add($lblGtk);
$hb->add($frameGtk);
// GtkWindow methods go into the rightmost subpane
$gtkwin_methods = get_class_methods(get_class($wnd) );
$out = '';
foreach ($gtkwin_methods as $name => $value) {
$out.= "$name : $value\n";
}
$lblGtkWindow = new GtkLabel($out);
$frameGtkWindow = new GtkFrame('GtkWindow methods');
$frameGtkWindow->add($lblGtkWindow);
$hb->add($frameGtkWindow);
// Now pack the widgets to optimize geometry
$vb->set_child_packing($lblHello, FALSE, FALSE, FALSE,
Gtk::PACK_START);
// Insert to VBox into the main window
$wnd->add($vb);
// We're good to go
$wnd->show_all();
Gtk::main();
?>When inserting the GtkHBox in the GtkScrolledWindow, we used add_with_viewport() instead of just add.
Now why not just add() ? What happens if we
replace add_with_viewport() by it ? And why ?
Hint
For deeper inspection of the PHP-GTK 2 widgets, the Dev_Inspector by Christian Weiske is your next stop. It uses the PHP5 Reflection API.
Commenti recenti
43 settimane 20 ore fa
44 settimane 49 min fa
44 settimane 3 giorni fa
47 settimane 1 ora fa
1 anno 15 settimane fa
1 anno 19 settimane fa
1 anno 23 settimane fa
1 anno 23 settimane fa
1 anno 23 settimane fa
1 anno 40 settimane fa