17 feb. 2010 : PHP-GTK Application descriptions can now be submitted in Brazilian Portuguese too. Thanks Bruno Bandeira !.

German and Italian still missing: who will contribute the translated categories for these languages ? Contact the team to offer your translations !

Fast starting with Glade 1

Firstly, in a oop style, we create an App class. In that class there are 2 methods, one for loading .glade files (your GUI), and one for getting widgets created .

Note: this article is for PHP-GTK 1, but has an equivalent for PHP-GTK 2. See Fast Starting with Glade 2

<?php

dl
('php_gtk.dll');

class
App {
  function
load_glade($file) {
   
$this->wnd = &new GladeXML($file);
   
$list_of_methods=get_class_methods($this);
    for (
$i=0 ; $i < sizeof($list_of_methods) ; $i++) {
      if (
strstr($list_of_methods[$i], "on_")) {
       
$this->wnd->signal_connect_object(
         
$list_of_methods[$i], array(&$this, $list_of_methods[$i]));
        }
      }
    }

  function
get_widget($widget) {
    return
$this->wnd->get_widget($widget);
  }
}
?>

In the load_glade method, we link all methods of that class (and the children of that class) to the glade signals (signals that we created into the glade interface).

An example

<?php
class App1 extends App {
  function
on_window1_destroy_event() {
   
$this->quit();
  }

  function
on_window1_delete_event() {
   
$this->quit();
  }

  function
quit() {
   
gtk::main_quit();
    }
  }

$a = new App1();
$a->load_glade("prog1.glade");
gtk::main();
?>

This simple app loads prog1.glade, links the signals of the window1 GtkWindow defined in Glade, and launchs the interface.

You can extend class App including all signals.

NOTE : to use this code, you must have glade support enabled in your php-gtk build.