Fw: Fw: [PHP-GTK-DEV] messy hack and stability

From: Date: Wed, 07 Sep 2005 23:15:29 +0000
Subject: Fw: Fw: [PHP-GTK-DEV] messy hack and stability
Groups: php.gtk.dev 
Request: Send a blank email to php-gtk-dev+get-1605@lists.php.net to get a copy of this message
OK, attachment didn't make it. Trying again as .txt. ----- Original Message ----- From: "Steph" <steph@zend.com> To: "Christian Weiske" <cweiske@cweiske.de> Cc: "PHP-GTK Dev list" <php-gtk-dev@lists.php.net> Sent: Thursday, September 08, 2005 12:12 AM Subject: Re: Fw: [PHP-GTK-DEV] messy hack and stability > I have a version of phpgtk2-demo.php that doesn't crash on scrolling > anything. Attached. > > (Can't remember what other files I may have changed, let me know if it fails > & if so, where so.) > > I removed the TODO entry about this on that basis.. sorry, there wasn't > anyone to ask at the time. But I really don't think it's a PHP-GTK 2 issue. > > ----- Original Message ----- > From: "Christian Weiske" <cweiske@cweiske.de> > To: "Steph" <steph@zend.com> > Cc: "PHP-GTK Dev list" <php-gtk-dev@lists.php.net> > Sent: Wednesday, September 07, 2005 10:30 PM > Subject: Re: Fw: [PHP-GTK-DEV] messy hack and stability > > > > Steph, > > > > > BTW I had to delete all the object-caching code in phpgtk2-demo.php to > get > > > it to work here... > > I noted this behavior as well when I recompiled it from the source > > lately - don't know why it doesn't work any more, but once it did. > > > > -- > > Regards/MfG, > > Christian Weiske > > > > -- > > PHP-GTK Development Mailing List (http://gtk.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > ---------------------------------------------------------------------------- ---- > -- > PHP-GTK Development Mailing List (http://gtk.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

<?php /* * The use of dl() is no longer encouraged in PHP 5 */ if (!class_exists('gtk')) { die('Please load the php-gtk2 module in your php.ini' . "\r\n"); } class PHPGTK2Demo extends GtkWindow { protected $demos = array(); protected $description_buffer; protected $demobox; protected static $highStrings = array( '(' => '<blue>(</blue>', ')' => '<blue>)</blue>' ); protected static $highTypes = array( T_COMMENT => '<green>%s</green>' ); function __construct() { parent::__construct(); $this->connect_object('destroy', array('gtk', 'main_quit')); $this->set_title('PHP-GTK 2 Demos'); $this->set_default_size(800, 400); $hbox = new GtkHBox(false, 3); $this->add($hbox); $treeview = $this->__create_treeview(); $hbox->pack_start($treeview, false, false); $notebook = new GtkNotebook(); $hbox->pack_start($notebook, true); $notebook->append_page($this->__create_text(), new GtkLabel('Info')); $demobox = new GtkVBox(); $this->demobox = $demobox; $notebook->append_page($this->demobox, new GtkLabel('Demo')); // $scroll_demo = new GtkScrolledWindow(); // $scroll_demo->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); // $this->demobox = $scroll_demo; // $page = $notebook->append_page($this->demobox, new GtkLabel('Demo')); list($text, $this->sourcebuffer) = $this->__create_source(); $notebook->append_page($text, new GtkLabel('Source')); $this->show_all(); }//function __construct() function __create_treeview() { $this->load_demos(); $model = new GtkListStore(Gtk::TYPE_PHP_VALUE, Gtk::TYPE_STRING); foreach ($this->demos as $demo) { $iter = $model->append(); $model->set($iter, 0, $demo); } $treeview = new GtkTreeView($model); $cell_renderer = new GtkCellRendererText(); $treeview->insert_column_with_data_func(-1, 'Demos', $cell_renderer, array(&$this, 'label_setter')); $selection = $treeview->get_selection(); $selection->set_mode(Gtk::SELECTION_SINGLE); $selection->connect('changed', array($this, 'demo_selected')); return $treeview; }//function __create_treeview() function __create_source() { $scrolled_window = new GtkScrolledWindow(); $scrolled_window->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); $scrolled_window->set_shadow_type(Gtk::SHADOW_IN); $text_view = new GtkTextView(); $scrolled_window->add($text_view); $buffer = new GtkTextBuffer(); $text_view->set_buffer($buffer); $text_view->set_editable(false); $text_view->set_cursor_visible(false); return array($scrolled_window, $buffer); } function label_setter($column, $cell, $model, $iter) { $info = $model->get_value($iter, 0); $cell->set_property('text', $info->classname); } function demo_selected($selection) { list($model, $iter) = $selection->get_selected(); if (!$iter) { return; } $info = $model->get_value($iter, 0); $text = $info->classname . "\r\n\r\n" . $info->description; $this->description_buffer->set_text($text, strlen($text)); //source code highlighting $this->highlightSource($info->file, false); //remove demobox child $children = $this->demobox->get_children(); if (!empty($children)) { $this->demobox->remove($children[0]); } $classname = $info->classname; if ($classname) { $scroll_demo = new GtkScrolledWindow(); $scroll_demo->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); $obj = new $classname(); $subobj = $obj->__create_box(); $scroll_demo->add_with_viewport($subobj); $this->demobox->add($scroll_demo); $this->demobox->show_all(); } } function __create_text() { $scrolled_window = new GtkScrolledWindow(); $scrolled_window->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); $scrolled_window->set_shadow_type(Gtk::SHADOW_IN); $text_view = new GtkTextView(); $scrolled_window->add($text_view); $this->description_buffer = new GtkTextBuffer(); $text_view->set_buffer($this->description_buffer); $text_view->set_editable(false); $text_view->set_cursor_visible(false); $text_view->set_wrap_mode(Gtk::WRAP_WORD); return $scrolled_window; } protected function load_demos() { define('DIR_SEPARATOR', strstr(PHP_OS, 'WIN') ? '\\' : '/'); /* keep an array of the files we're actually using - there are more exceptions than there are rules! */ $target_files = array('buttonbox', 'colorselector', 'combobox', 'dialogmessage', 'entrycompletion', 'expander', 'gtkiconview', 'sizegroup', 'stock-browser2', ); $files = glob(dirname(__FILE__).DIR_SEPARATOR.'*.php'); foreach ($files as $id => $file) { $GLOBALS['class'] = null; $check = substr($file, strrpos($file, DIR_SEPARATOR) + 1, -4); if (in_array($check, $target_files)) { if (!@include_once($file)) { continue; } $this->demos[$file] = null; $this->demos[$file]->classname = $GLOBALS['class']; $this->demos[$file]->description = $GLOBALS['description']; $this->demos[$file]->file = $file; } } }//protected function load_demos() protected function highlightSource($filename, $highlighting) { $filecontents = file_get_contents($filename); $tokens = token_get_all($filecontents); $highlighted = ''; if ($highlighting) { foreach ($tokens as $token) { if (is_string($token)) { //single string if (isset(self::$highStrings[$token])) { $highlighted .= self::$highStrings[$token]; } else { $highlighted .= $token; } } else { list($type, $value) = $token; if (isset(self::$highTypes[$type])) { $highlighted .= sprintf(self::$highTypes[$type], $value); } else { $highlighted .= $value; } } } $this->sourcebuffer->set_text($highlighted, strlen($highlighted)); } else { $this->sourcebuffer->set_text($filecontents, strlen($filecontents)); } }//protected function highlightSource($filename, $highlighting) }//class PHPGTK2Demo extends GtkWindow $GLOBALS['framework'] = true; new PHPGTK2Demo(); gtk::main(); ?>
« previous php.gtk.dev (#1605) next »