Código PHP:
<?php
$app = new App();
$app->main();
class App {
function App() {
$this->modules = array("main", "entel", "softswitch"); // names of the modules
}
function main() {
foreach($this->modules as $module) {
$this->apps[$module] = new $module($this);
$this->apps[$module]->dialog->connect('delete-event', array( &$this, "on_delete_event"), $module);
$this->apps[$module]->dialog->connect('key-press-event', array( &$this, "on_key"), $module);
}
$this->apps['main']->dialog->show_all(); // show the first module
$this->apps['main']->dialog->run(); // let's go!
}
// process button click
function on_clicked($button, $activated_module) {
print "button_clicked: $activated_module\n";
$this->apps[$activated_module]->dialog->show_all(); // show the activated module
foreach($this->modules as $module) {
if ($module!=$activated_module) $this->apps[$module]->dialog->hide_all(); // hide all others
}
$this->apps[$activated_module]->dialog->run();
}
function on_delete_event($widget, $event, $module) {
if ($module=='main') {
$this->apps['main']->dialog->destroy();
} else {
$this->apps[$module]->dialog->hide();
$this->apps['main']->dialog->show_all(); // show the main menu
$this->apps['main']->dialog->run();
}
return true;
}
function on_key($widget, $event, $module) {
global $apps;
if ($event->keyval==Gdk::KEY_F12) {
if ($module=='main') {
$this->apps['main']->dialog->destroy();
} else {
$this->apps[$module]->dialog->hide();
$this->apps['main']->dialog->show_all(); // show the main menu
$this->apps['main']->dialog->run();
}
}
}
// process menu item selection
function on_menu_select($menu_item) {
$item = $menu_item->child->get_label();
echo "menu selected: $item\n";
if ($item=='_Quit') {
$this->apps['main']->dialog->destroy();
} else {
$module = strtolower($item);
print "module = $module\n";
$this->apps['main']->dialog->hide();
$this->apps[$module]->dialog->show_all();
$this->apps[$module]->dialog->run(); // let's go!
}
}
}
class base_module {
function base_module($obj) {
$this->main = $obj; // keep a copy of the module names
$module = get_class($this);
print "base_module::module = $module\n";
$dialog = new GtkDialog($module, null, Gtk::DIALOG_MODAL);
$dialog->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
$dialog->set_size_request(800, 600);
$top_area = $dialog->vbox;
$this->dialog = $dialog; // keep a copy of the dialog ID
// run the setup for each module
$this->setup($top_area);
$top_area->pack_start(new GtkLabel()); // used to "force" the button to stay at bottom
$this->show_buttons($top_area); // shows the buttons at bottom of windows
$dialog->set_has_separator(false);
}
function show_buttons($vbox) {}
}
function display_table($vbox, $data) {
// Set up a scroll window
$scrolled_win = new GtkScrolledWindow();
$scrolled_win->set_policy( Gtk::POLICY_AUTOMATIC,
Gtk::POLICY_AUTOMATIC);
$vbox->pack_start($scrolled_win);
// Creates the list store
if (defined("GObject::TYPE_STRING")) {
$model = new GtkListStore(GObject::TYPE_STRING, GObject::TYPE_STRING,
GObject::TYPE_STRING); // note 2
} else {
$model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING,
GObject::TYPE_STRING); // note 2
}