Home mail me! Syndicate this site using RSS

Archive for PHP-GTK


PHP-GTK Example: Splash

<?php
class splash {
	var $gui = null;
	var $times = null;
 
	function splash() {
		$this->gui = array(); // 初始化
		$this->times = 0;
	}
 
	/**
	* 运行主程序
	*/
	function run() {
		$this->gui['splash'] = &new GtkWindow(GTK_WINDOW_POPUP);
		$this->gui['splash']->set_position(GTK_WIN_POS_CENTER);
		$this->gui['splash']->set_usize(365, 221);
		$this->gui['vbox'] = &new GtkVbox(false, 0);
 
		// load pixmap
		list($pixmap, $mask) = Gdk::pixmap_create_from_xpm($this->gui['splash']->window, null, 'splash.xpm');
		$splash = &new GtkPixmap($pixmap, $mask);
 
		// add the image to the box
		$this->gui['vbox']->add($splash);
 
		// load loading label
		$this->gui['loading'] = &new GtkLabel();
 
		// add the loading label to the box
		$this->gui['vbox']->add($this->gui['loading']);
 
		// add the box to the window
		$this->gui['splash']->add($this->gui['vbox']);
		$this->gui['splash']->show_all();
		$this->loading();
		Gtk::main();
	}
 
	/**
	* Loging …
	*/
	function loading() {
		$this->times ++;
		$this->gui['loading']->set_text('Loading .' . str_repeat('.', $this->times));
		// 刷新屏幕
		while (gtk::events_pending()) gtk::main_iteration();
		$loadingid = Gtk::timeout_add(1000, array(&$this, 'loading'));
		// 运行4次退出
		if($this->times > 4) {
			Gtk::main_quit();
			Gtk::timeout_remove($loadingid);
		}
	}
}
 
$splash = &new splash();
$splash->run();
?>

php-gtk splash