cvs: php-gtk /test gtk.php

From: Date: Wed, 28 Feb 2001 04:47:06 +0000
Subject: cvs: php-gtk /test gtk.php
Groups: php.gtk 
Request: Send a blank email to php-gtk+get-60@lists.php.net to get a copy of this message
andrei Tue Feb 27 20:47:06 2001 EDT Modified files: /php-gtk/test gtk.php Log: Started porting testgtk.c to PHP. Window destruction is screwed up, need to fix. Index: php-gtk/test/gtk.php diff -u php-gtk/test/gtk.php:1.3 php-gtk/test/gtk.php:1.4 --- php-gtk/test/gtk.php:1.3 Sat Feb 3 16:08:49 2001 +++ php-gtk/test/gtk.php Tue Feb 27 20:47:06 2001 @@ -1,55 +1,151 @@ <?php -/* $Id: gtk.php,v 1.3 2001/02/04 00:08:49 andrei Exp $ */ +/* $Id: gtk.php,v 1.4 2001/02/28 04:47:06 andrei Exp $ */ -if ($OS == 'Windows_NT') +if (strtoupper(substr(PHP_OS, 1, 3)) == 'WIN') dl('php_gtk.dll'); else dl('php_gtk.so'); +$windows = array(); + function delete_event($window, $event) +{ + $window->hide(); + return true; +} + +function close_window($widget) { - return false; + $window = $widget->get_toplevel(); + $window->hide(); } -function shutdown() { - print("Shutting down.\n"); +function destroy($window) +{ Gtk::main_quit(); } + + +function create_buttons() +{ + global $windows; + + if (!isset($windows['buttons'])) { + $window = &new GtkWindow; + $windows['buttons'] = $window; + $window->connect('delete-event', delete_event); + $window->set_title('GtkButton'); + + $box1 = &new GtkVBox(); + $window->add($box1); + $box1->show(); + + $table = &new GtkTable(3, 3); + $table->set_row_spacings(5); + $table->set_col_spacings(5); + $table->set_border_width(10); + $box1->pack_start($table); + $table->show(); + + $buttons = range(0, 8); + array_walk($buttons, create_function('&$x', '$x = new GtkButton("button".($x+1));')); + + function toggle_show($b) + { + if ($b->flags() & GTK_VISIBLE) + $b->hide(); + else + $b->show(); + } + + for ($i = 0; $i < 9; $i++) { + $buttons[$i]->connect('clicked', + create_function('$b, $b2', 'toggle_show($b2);'), + $buttons[($i+1)%9]); + $x = (int)($i / 3); + $y = $i % 3; + $table->attach($buttons[$i], $x, $x + 1, $y, $y + 1); + $buttons[$i]->show(); + } + + $separator = &new GtkHSeparator(); + $box1->pack_start($separator, false); + $separator->show(); + + $box2 = &new GtkVBox(false, 10); + $box2->set_border_width(10); + $box1->pack_start($box2, false); + $box2->show(); + + $button = &new GtkButton('close'); + $button->connect('clicked', close_window); + $box2->pack_start($button); + $button->set_flags(GTK_CAN_DEFAULT); + $button->grab_default(); + $button->show(); + } + $windows['buttons']->show(); +} + -function clicked() +function create_main_window() { - var_dump(func_get_args()); + $buttons = array( + 'buttons' => create_buttons, + 'labels' => null, + ); + + $window = &new GtkWindow(); + $window->set_policy(false, false, false); + $window->set_name('main window'); + $window->set_usize(200, 400); + $window->set_uposition(20, 20); + + $window->connect('destroy', destroy); + $window->connect('delete-event', destroy); + + $box1 = &new GtkVBox(); + $window->add($box1); + + $scrolled_window = &new GtkScrolledWindow(); + $scrolled_window->set_border_width(10); + $scrolled_window->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + $box1->pack_start($scrolled_window); + + $box2 = &new GtKVBox(); + $box2->set_border_width(10); + $scrolled_window->add_with_viewport($box2); + $box2->set_focus_vadjustment($scrolled_window->get_vadjustment()); + $box2->show(); + + ksort($buttons); + foreach ($buttons as $label => $function) { + $button = &new GtkButton($label); + if ($function) + $button->connect('clicked', $function); + else + $button->set_sensitive(false); + $box2->pack_start($button); + } + + $separator = &new GtkHSeparator(); + $box1->pack_start($separator, false); + + $box2 = &new GtkVBox(false, 10); + $box2->set_border_width(10); + $box1->pack_start($box2, false); + + $button = &new GtkButton('close'); + $button->connect('clicked', destroy); + $box2->pack_start($button); + $button->set_flags(GTK_CAN_DEFAULT); + $button->grab_default(); + + $window->show_all(); } -$window = &new GtkWindow(); -$window->connect('destroy', 'shutdown'); -$window->connect('delete-event', 'delete_event', 'foo'); -$window->set_border_width(0); - -$box = &new GtkVBox(FALSE, 0); -$table = &new GtkTable(2, 1, FALSE); -$table->set_row_spacings(10); -$table->set_col_spacings(10); -$table->set_border_width(10); -$box->pack_start($table, TRUE, TRUE, 0); - -$button = &new GtkButton("Press Me"); -$button->connect('clicked', 'clicked'); - -$table->attach($button, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - -$label = &new GtkLabel("PHP Rules!\nPHP is simply the coolest scripting language!"); -$label->set_justify(GTK_JUSTIFY_LEFT); -//$label->set_uposition(0,0); - -$table->attach($label, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - -$window->set_title("PHP Rules!"); -$window->set_name("MainWindow"); -$window->set_uposition(100,200); -$window->set_usize(600,150); -$window->add($box); -$window->show_all(); +create_main_window(); Gtk::main(); ?>

« previous php.gtk (#60) next »