cvs: pear /Gtk2_IndexedComboBox package.xml /Gtk2_IndexedComboBox/Gtk2 IndexedComboBox.php /Gtk2_IndexedComboBox/examples normal.php
| From: | Christian Weiske | Date: | Mon, 20 Mar 2006 08:22:54 +0000 |
| Subject: | cvs: pear /Gtk2_IndexedComboBox package.xml /Gtk2_IndexedComboBox/Gtk2 IndexedComboBox.php /Gtk2_IndexedComboBox/examples normal.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-39201@lists.php.net to get a copy of this message | ||
cweiske Mon Mar 20 08:22:54 2006 UTC
Added files:
/pear/Gtk2_IndexedComboBox package.xml
/pear/Gtk2_IndexedComboBox/Gtk2 IndexedComboBox.php
/pear/Gtk2_IndexedComboBox/examples normal.php
Log:
Initial import
http://cvs.php.net/viewcvs.cgi/pear/Gtk2_IndexedComboBox/package.xml?view=markup&rev=1.1 Index: pear/Gtk2_IndexedComboBox/package.xml +++ pear/Gtk2_IndexedComboBox/package.xml <?xml version="1.0"?> <package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>Gtk2_IndexedComboBox</name> <channel>pear.php.net</channel> <summary>Indexed Gtk2 combo box similar to the HTML select box.</summary> <description> Indexed Gtk2 combo box similar to the HTML select box. Lets you not only store values as the normal GtkComboBox, but associated key/value pairs as well. The active key can be easily received with get_active_key. </description> <lead> <name>Christian Weiske</name> <user>cweiske</user> <email>cweiske@php.net</email> <active>yes</active> </lead> <date>2006-03-10</date> <version> <release>0.0.2</release> <api>0.0.2</api> </version> <stability> <release>beta</release> <api>beta</api> </stability> <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> - Added set_active_key - Added camelCase method names as PEAR-compatible aliases </notes> <contents> <dir name="/" baseinstalldir="/"> <dir name="Gtk2"> <file name="IndexedComboBox.php" role="php"/> </dir> <dir name="examples"> <file name="normal.php" role="doc"/> </dir> </dir> </contents> <dependencies> <required> <php> <min>5.1</min> <max>6.0.0</max> </php> <pearinstaller> <min>1.4.1</min> </pearinstaller> <extension> <name>php-gtk</name> <min>2.0.0dev</min> </extension> </required> </dependencies> <phprelease/> <changelog> <release> <version> <release>0.0.2</release> <api>0.0.2</api> </version> <stability> <release>beta</release> <api>beta</api> </stability> <date>2006-03-10</date> <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> - Added set_active_key - Added camelCase method names as PEAR-compatible aliases </notes> </release> <release> <version> <release>0.0.1</release> <api>0.0.1</api> </version> <stability> <release>beta</release> <api>beta</api> </stability> <date>2006-03-04</date> <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> First version </notes> </release> </changelog> </package> http://cvs.php.net/viewcvs.cgi/pear/Gtk2_IndexedComboBox/Gtk2/IndexedComboBox.php?view=markup&rev=1.1 Index: pear/Gtk2_IndexedComboBox/Gtk2/IndexedComboBox.php +++ pear/Gtk2_IndexedComboBox/Gtk2/IndexedComboBox.php <?php /** * Indexed Gtk2 combo box similar to the HTML select box. * Lets you not only store values as the normal GtkComboBox, * but associated keys as well. The active key can be easily * received with get_active_key. * * It imitates the convenience methods of a text-based GtkComboBox * that is constructed with GtkComboBox::new_text(). * * Both key and values can be strings or integers. * * Method names aren't camelCase but with underscores to be close * the naming of the original Gtk2 methods. * * @category Gtk2 * @package Gtk2_IndexedComboBox * @author Christian Weiske <cweiske@php.net> * @license LGPL * @version CVS: $Id: IndexedComboBox.php,v 1.1 2006/03/20 08:22:54 cweiske Exp $ */ class Gtk2_IndexedComboBox extends GtkComboBox { public function __construct($arData = null) { parent::__construct(); $model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING); $this->set_model($model); //show the second column only $renderer = new GtkCellRendererText(); $this->pack_start($renderer); $this->set_attributes($renderer, 'text', 1); if ($arData !== null) { $this->set_array($arData); } }//public function __construct($arData = null) /** * Appends a single key/value pair to the list. * * @param string $strId The id to append * @param string $strValue The value to append */ public function append($strId, $strValue) { $this->get_model()->append(array($strId, $strValue)); }//public function append_array($strId, $strValue) /** * Appends an array (key and value) as data to the store. * * @param array $arData The array to append */ public function append_array($arData) { $model = $this->get_model(); foreach ($arData as $strId => &$strValue) { $model->append(array($strId, $strValue)); } }//public function append_array($arData) /** * Returns the id of the active entry * * @return string The id/key of the selected entry */ public function get_active_key() { //workaround bug in php-gtk2: get_active_iter wants a parameter instead of giving one return $this->get_model()->get_value($this->get_model()->get_iter($this->get_active()), 0); //That's the better one (that doesn't work as of 2006-03-04) return $this->get_model()->get_value($this->get_active_iter(), 0); }//public function get_active_key() /** * Returns the string of the active entry. * * @return string The string value of the selected entry */ public function get_active_text() { //workaround bug in php-gtk2: get_active_iter wants a parameter instead of giving one return $this->get_model()->get_value($this->get_model()->get_iter($this->get_active()), 1); //That's the better one (that doesn't work as of 2006-03-04) return $this->get_model()->get_value($this->get_active_iter(), 1); }//public function get_active_text() /** * Inserts a single key/value pair at a certain position into the list. * * @param string $strId The id to append * @param string $strValue The value to append */ public function insert($nPosition, $strId, $strValue) { $this->get_model()->insert($nPosition, array($strId, $strValue)); }//public function insert($nPosition, $strId, $strValue) /** * Inserts an array (key and value) at a certain position into the list. * * @param int $nPosition The position to insert the array at * @param array $arData The array to append */ public function insert_array($nPosition, $arData) { $model = $this->get_model(); foreach ($arData as $strId => &$strValue) { $model->insert($nPosition++, array($strId, $strValue)); } }//public function insert_array($nPosition, $arData) /** * Prepends a single key/value pair to the list. * * @param string $strId The id to append * @param string $strValue The value to append */ public function prepend($strId, $strValue) { $this->get_model()->prepend(array($strId, $strValue)); }//public function prepend($strId, $strValue) /** * Prepends an array (key and value) at the beginning of the store * * @param array $arData The array to append */ public function prepend_array($arData) { $nPosition = 0; $model = $this->get_model(); foreach ($arData as $strId => &$strValue) { $model->insert($nPosition++, array($strId, $strValue)); } }//public function prepend_array($arData) /** * Removes the first entry with the given key from the list. * * @param string $strId The key of the entry to remove * * @return boolean True if an entry has been deleted */ public function remove_key($strId) { $model = $this->get_model(); $iter = $model->get_iter_first(); do { if ($model->get_value($iter, 0) == $strId) { break; } } while (($iter = $model->iter_next($iter)) !== null); if ($iter !== null) { $model->remove($iter); return true; } return false; }//public function remove_key($strId) /** * Sets the model row with the given key as active. * * @param string $strId The key of the entry to be made active * * @return boolean True if an entry has been set active */ public function set_active_key($strId) { $model = $this->get_model(); $iter = $model->get_iter_first(); do { if ($model->get_value($iter, 0) == $strId) { break; } } while (($iter = $model->iter_next($iter)) !== null); if ($iter !== null) { $this->set_active_iter($iter); return true; } return false; }//public function set_active_key($strId) /** * Sets an array (key and value) as data into the store. * Clears any previous entries. * * @param array $arData The array to set */ public function set_array($arData) { $this->get_model()->clear(); return $this->append_array($arData); }//public function set_array($arData) /* * PEAR-style camelCaseNamed method aliases */ public function appendArray($arData) { return $this->append_array($arData); } public function getActiveKey() { return $this->get_active_key(); } public function getActiveText() { return $this->get_active_text(); } public function insertArray($nPosition, $arData) { return $this->insert_array($nPosition, $arData); } public function prependArray($arData) { return $this->prepend_array($arData); } public function removeKey($strId) { return $this->remove_key($strId); } public function setActiveKey($strId) { return $this->set_active_key($strId); } public function setArray($arData) { return $this->set_array($arData); } }//class Gtk2_IndexedComboBox extends GtkMessageDialog ?> http://cvs.php.net/viewcvs.cgi/pear/Gtk2_IndexedComboBox/examples/normal.php?view=markup&rev=1.1 Index: pear/Gtk2_IndexedComboBox/examples/normal.php +++ pear/Gtk2_IndexedComboBox/examples/normal.php <?php /** * Simple Gtk2_IndexedComboBox example * * @author Christian Weiske <cweiske@php.net> */ require_once 'Gtk2/IndexedComboBox.php'; $arData = array('key' => 'constructor', 2 => 'c02', 3 => 'c03'); $arPrepend = array('prepend' => 'prepend', 10 => 'p10', 11 => 'p11', 12 => 'p12'); $arInsert = array('insert' => 'insert' , 20 => 'i20', 21 => 'i21', 22 => 'i22'); $arAppend = array('append' => 'append' , 30 => 'a30', 31 => 'a31', 32 => 'a32'); $cmb = array(); $cmb['empty'] = new Gtk2_IndexedComboBox(); $cmb['constructor'] = new Gtk2_IndexedComboBox($arData); $cmb['append'] = new Gtk2_IndexedComboBox(); $cmb['append']->append_array($arAppend); $cmb['append+c'] = new Gtk2_IndexedComboBox($arData); $cmb['append+c']->append_array($arAppend); $cmb['prepend'] = new Gtk2_IndexedComboBox(); $cmb['prepend']->prepend_array($arPrepend); $cmb['prepend+c'] = new Gtk2_IndexedComboBox($arData); $cmb['prepend+c']->prepend_array($arPrepend); $cmb['insert'] = new Gtk2_IndexedComboBox(); $cmb['insert']->insert_array(2, $arInsert); $cmb['insert+c'] = new Gtk2_IndexedComboBox($arData); $cmb['insert+c']->insert_array(2, $arInsert); $cmb['normal'] = new Gtk2_IndexedComboBox(); $cmb['normal']->append('append', 'append'); $cmb['normal']->prepend('prepend', 'prepend'); $cmb['normal']->insert(1, 'insert', 'insert on #1'); $cmb['normal']->append('append2', 'append#2'); $cmb['normal']->set_active_key('append'); $lbl = new GtkLabel("Status\r\n\r\n"); $tbl = new GtkTable(2, count($cmb)); $nPos = 0; foreach ($cmb as $id => $combo) { $tbl->attach(new GtkLabel($id), 0, 1, $nPos, $nPos + 1); $tbl->attach($combo, 1, 2, $nPos, $nPos + 1); $combo->connect('changed', 'comboChanged', $id, $lbl); ++$nPos; } function comboChanged($combo, $comboId, $lbl) { $lbl->set_text( 'Combo "' . $comboId . "\" changed:\r\n" . 'Key: ' . $combo->get_active_key() . "\r\n" . 'Value: ' . $combo->get_active_text() ); } $vbox = new GtkVBox(); $vbox->pack_start($tbl); $vbox->pack_start($lbl); $wnd = new GtkWindow(); $wnd->connect_simple('destroy', array('Gtk', 'main_quit')); $wnd->add($vbox); $wnd->show_all(); Gtk::main(); ?>
http://cvs.php.net/viewcvs.cgi/pear/Gtk2_IndexedComboBox/package.xml?view=markup&rev=1.1 Index: pear/Gtk2_IndexedComboBox/package.xml +++ pear/Gtk2_IndexedComboBox/package.xml <?xml version="1.0"?> <package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>Gtk2_IndexedComboBox</name> <channel>pear.php.net</channel> <summary>Indexed Gtk2 combo box similar to the HTML select box.</summary> <description> Indexed Gtk2 combo box similar to the HTML select box. Lets you not only store values as the normal GtkComboBox, but associated key/value pairs as well. The active key can be easily received with get_active_key. </description> <lead> <name>Christian Weiske</name> <user>cweiske</user> <email>cweiske@php.net</email> <active>yes</active> </lead> <date>2006-03-10</date> <version> <release>0.0.2</release> <api>0.0.2</api> </version> <stability> <release>beta</release> <api>beta</api> </stability> <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> - Added set_active_key - Added camelCase method names as PEAR-compatible aliases </notes> <contents> <dir name="/" baseinstalldir="/"> <dir name="Gtk2"> <file name="IndexedComboBox.php" role="php"/> </dir> <dir name="examples"> <file name="normal.php" role="doc"/> </dir> </dir> </contents> <dependencies> <required> <php> <min>5.1</min> <max>6.0.0</max> </php> <pearinstaller> <min>1.4.1</min> </pearinstaller> <extension> <name>php-gtk</name> <min>2.0.0dev</min> </extension> </required> </dependencies> <phprelease/> <changelog> <release> <version> <release>0.0.2</release> <api>0.0.2</api> </version> <stability> <release>beta</release> <api>beta</api> </stability> <date>2006-03-10</date> <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> - Added set_active_key - Added camelCase method names as PEAR-compatible aliases </notes> </release> <release> <version> <release>0.0.1</release> <api>0.0.1</api> </version> <stability> <release>beta</release> <api>beta</api> </stability> <date>2006-03-04</date> <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license> <notes> First version </notes> </release> </changelog> </package> http://cvs.php.net/viewcvs.cgi/pear/Gtk2_IndexedComboBox/Gtk2/IndexedComboBox.php?view=markup&rev=1.1 Index: pear/Gtk2_IndexedComboBox/Gtk2/IndexedComboBox.php +++ pear/Gtk2_IndexedComboBox/Gtk2/IndexedComboBox.php <?php /** * Indexed Gtk2 combo box similar to the HTML select box. * Lets you not only store values as the normal GtkComboBox, * but associated keys as well. The active key can be easily * received with get_active_key. * * It imitates the convenience methods of a text-based GtkComboBox * that is constructed with GtkComboBox::new_text(). * * Both key and values can be strings or integers. * * Method names aren't camelCase but with underscores to be close * the naming of the original Gtk2 methods. * * @category Gtk2 * @package Gtk2_IndexedComboBox * @author Christian Weiske <cweiske@php.net> * @license LGPL * @version CVS: $Id: IndexedComboBox.php,v 1.1 2006/03/20 08:22:54 cweiske Exp $ */ class Gtk2_IndexedComboBox extends GtkComboBox { public function __construct($arData = null) { parent::__construct(); $model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING); $this->set_model($model); //show the second column only $renderer = new GtkCellRendererText(); $this->pack_start($renderer); $this->set_attributes($renderer, 'text', 1); if ($arData !== null) { $this->set_array($arData); } }//public function __construct($arData = null) /** * Appends a single key/value pair to the list. * * @param string $strId The id to append * @param string $strValue The value to append */ public function append($strId, $strValue) { $this->get_model()->append(array($strId, $strValue)); }//public function append_array($strId, $strValue) /** * Appends an array (key and value) as data to the store. * * @param array $arData The array to append */ public function append_array($arData) { $model = $this->get_model(); foreach ($arData as $strId => &$strValue) { $model->append(array($strId, $strValue)); } }//public function append_array($arData) /** * Returns the id of the active entry * * @return string The id/key of the selected entry */ public function get_active_key() { //workaround bug in php-gtk2: get_active_iter wants a parameter instead of giving one return $this->get_model()->get_value($this->get_model()->get_iter($this->get_active()), 0); //That's the better one (that doesn't work as of 2006-03-04) return $this->get_model()->get_value($this->get_active_iter(), 0); }//public function get_active_key() /** * Returns the string of the active entry. * * @return string The string value of the selected entry */ public function get_active_text() { //workaround bug in php-gtk2: get_active_iter wants a parameter instead of giving one return $this->get_model()->get_value($this->get_model()->get_iter($this->get_active()), 1); //That's the better one (that doesn't work as of 2006-03-04) return $this->get_model()->get_value($this->get_active_iter(), 1); }//public function get_active_text() /** * Inserts a single key/value pair at a certain position into the list. * * @param string $strId The id to append * @param string $strValue The value to append */ public function insert($nPosition, $strId, $strValue) { $this->get_model()->insert($nPosition, array($strId, $strValue)); }//public function insert($nPosition, $strId, $strValue) /** * Inserts an array (key and value) at a certain position into the list. * * @param int $nPosition The position to insert the array at * @param array $arData The array to append */ public function insert_array($nPosition, $arData) { $model = $this->get_model(); foreach ($arData as $strId => &$strValue) { $model->insert($nPosition++, array($strId, $strValue)); } }//public function insert_array($nPosition, $arData) /** * Prepends a single key/value pair to the list. * * @param string $strId The id to append * @param string $strValue The value to append */ public function prepend($strId, $strValue) { $this->get_model()->prepend(array($strId, $strValue)); }//public function prepend($strId, $strValue) /** * Prepends an array (key and value) at the beginning of the store * * @param array $arData The array to append */ public function prepend_array($arData) { $nPosition = 0; $model = $this->get_model(); foreach ($arData as $strId => &$strValue) { $model->insert($nPosition++, array($strId, $strValue)); } }//public function prepend_array($arData) /** * Removes the first entry with the given key from the list. * * @param string $strId The key of the entry to remove * * @return boolean True if an entry has been deleted */ public function remove_key($strId) { $model = $this->get_model(); $iter = $model->get_iter_first(); do { if ($model->get_value($iter, 0) == $strId) { break; } } while (($iter = $model->iter_next($iter)) !== null); if ($iter !== null) { $model->remove($iter); return true; } return false; }//public function remove_key($strId) /** * Sets the model row with the given key as active. * * @param string $strId The key of the entry to be made active * * @return boolean True if an entry has been set active */ public function set_active_key($strId) { $model = $this->get_model(); $iter = $model->get_iter_first(); do { if ($model->get_value($iter, 0) == $strId) { break; } } while (($iter = $model->iter_next($iter)) !== null); if ($iter !== null) { $this->set_active_iter($iter); return true; } return false; }//public function set_active_key($strId) /** * Sets an array (key and value) as data into the store. * Clears any previous entries. * * @param array $arData The array to set */ public function set_array($arData) { $this->get_model()->clear(); return $this->append_array($arData); }//public function set_array($arData) /* * PEAR-style camelCaseNamed method aliases */ public function appendArray($arData) { return $this->append_array($arData); } public function getActiveKey() { return $this->get_active_key(); } public function getActiveText() { return $this->get_active_text(); } public function insertArray($nPosition, $arData) { return $this->insert_array($nPosition, $arData); } public function prependArray($arData) { return $this->prepend_array($arData); } public function removeKey($strId) { return $this->remove_key($strId); } public function setActiveKey($strId) { return $this->set_active_key($strId); } public function setArray($arData) { return $this->set_array($arData); } }//class Gtk2_IndexedComboBox extends GtkMessageDialog ?> http://cvs.php.net/viewcvs.cgi/pear/Gtk2_IndexedComboBox/examples/normal.php?view=markup&rev=1.1 Index: pear/Gtk2_IndexedComboBox/examples/normal.php +++ pear/Gtk2_IndexedComboBox/examples/normal.php <?php /** * Simple Gtk2_IndexedComboBox example * * @author Christian Weiske <cweiske@php.net> */ require_once 'Gtk2/IndexedComboBox.php'; $arData = array('key' => 'constructor', 2 => 'c02', 3 => 'c03'); $arPrepend = array('prepend' => 'prepend', 10 => 'p10', 11 => 'p11', 12 => 'p12'); $arInsert = array('insert' => 'insert' , 20 => 'i20', 21 => 'i21', 22 => 'i22'); $arAppend = array('append' => 'append' , 30 => 'a30', 31 => 'a31', 32 => 'a32'); $cmb = array(); $cmb['empty'] = new Gtk2_IndexedComboBox(); $cmb['constructor'] = new Gtk2_IndexedComboBox($arData); $cmb['append'] = new Gtk2_IndexedComboBox(); $cmb['append']->append_array($arAppend); $cmb['append+c'] = new Gtk2_IndexedComboBox($arData); $cmb['append+c']->append_array($arAppend); $cmb['prepend'] = new Gtk2_IndexedComboBox(); $cmb['prepend']->prepend_array($arPrepend); $cmb['prepend+c'] = new Gtk2_IndexedComboBox($arData); $cmb['prepend+c']->prepend_array($arPrepend); $cmb['insert'] = new Gtk2_IndexedComboBox(); $cmb['insert']->insert_array(2, $arInsert); $cmb['insert+c'] = new Gtk2_IndexedComboBox($arData); $cmb['insert+c']->insert_array(2, $arInsert); $cmb['normal'] = new Gtk2_IndexedComboBox(); $cmb['normal']->append('append', 'append'); $cmb['normal']->prepend('prepend', 'prepend'); $cmb['normal']->insert(1, 'insert', 'insert on #1'); $cmb['normal']->append('append2', 'append#2'); $cmb['normal']->set_active_key('append'); $lbl = new GtkLabel("Status\r\n\r\n"); $tbl = new GtkTable(2, count($cmb)); $nPos = 0; foreach ($cmb as $id => $combo) { $tbl->attach(new GtkLabel($id), 0, 1, $nPos, $nPos + 1); $tbl->attach($combo, 1, 2, $nPos, $nPos + 1); $combo->connect('changed', 'comboChanged', $id, $lbl); ++$nPos; } function comboChanged($combo, $comboId, $lbl) { $lbl->set_text( 'Combo "' . $comboId . "\" changed:\r\n" . 'Key: ' . $combo->get_active_key() . "\r\n" . 'Value: ' . $combo->get_active_text() ); } $vbox = new GtkVBox(); $vbox->pack_start($tbl); $vbox->pack_start($lbl); $wnd = new GtkWindow(); $wnd->connect_simple('destroy', array('Gtk', 'main_quit')); $wnd->add($vbox); $wnd->show_all(); Gtk::main(); ?>