cvs: peardoc /en/package gtk2.xml /en/package/gtk2 gtk2-indexedcombobox.xml /en/package/gtk2/gtk2-indexedcombobox example.xml glade.xml
gtk2-indexedcombobox-model.xml gtk2-indexedcombobox.xml
| From: | Christian Weiske | Date: | Thu, 02 Nov 2006 17:21:48 +0000 |
| Subject: | cvs: peardoc /en/package gtk2.xml /en/package/gtk2 gtk2-indexedcombobox.xml /en/package/gtk2/gtk2-indexedcombobox example.xml glade.xml gtk2-indexedcombobox-model.xml gtk2-indexedcombobox.xml |
||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-8704@lists.php.net to get a copy of this message | ||
cweiske Thu Nov 2 17:21:48 2006 UTC
Added files:
/peardoc/en/package/gtk2 gtk2-indexedcombobox.xml
/peardoc/en/package/gtk2/gtk2-indexedcombobox example.xml glade.xml
gtk2-indexedcombobox-model.xml
gtk2-indexedcombobox.xml
Modified files:
/peardoc/en/package gtk2.xml
Log:
Gtk2_IndexedComboBox documentation
http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2.xml?r1=1.5&r2=1.6&diff_format=u Index: peardoc/en/package/gtk2.xml diff -u peardoc/en/package/gtk2.xml:1.5 peardoc/en/package/gtk2.xml:1.6 --- peardoc/en/package/gtk2.xml:1.5 Fri Oct 27 20:13:25 2006 +++ peardoc/en/package/gtk2.xml Thu Nov 2 17:21:47 2006 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <chapter id="package.gtk2"> @@ -15,6 +15,7 @@ &package.gtk2.entrydialog; &package.gtk2.exceptiondump; &package.gtk2.filedrop; + &package.gtk2.gtk2-indexedcombobox; &package.gtk2.vardump; </chapter> http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2/gtk2-indexedcombobox.xml?view=markup&rev=1.1 Index: peardoc/en/package/gtk2/gtk2-indexedcombobox.xml +++ peardoc/en/package/gtk2/gtk2-indexedcombobox.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <sect1 id="package.gtk2.gtk2-indexedcombobox"> <title>Gtk2_IndexedComboBox</title> <abstract> <para> <classname>Gtk2_IndexedComboBox</classname> is a Gtk2 widget similar to the HTML <literal>select</literal> box - it lets you not only store values as the normal <classname>GtkComboBox</classname>, but associated key/value pairs. </para> </abstract> <para> <classname>Gtk2_IndexedComboBox</classname> is meant to be as easy to use as possible, and to have an API similar to the combo boxes created with <function>GtkComboBox::new_text</function>. You can directly add key/value pairs to the widget instead of using the model (which is possible, too). Retrieving the currently selected key can be done with a single method call. </para> <para> Both keys and values can be strings, thus allowing integers implicitly. This is very useful if you need a widget to select some row ID from a database, but want to display some descriptive string. By default, a single <classname>GtkCellRendererText</classname> is used as cell renderer. </para> &package.gtk2.gtk2-indexedcombobox.example; &package.gtk2.gtk2-indexedcombobox.glade; &package.gtk2.gtk2-indexedcombobox.gtk2-indexedcombobox; &package.gtk2.gtk2-indexedcombobox.gtk2-indexedcombobox-model; </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2/gtk2-indexedcombobox/example.xml?view=markup&rev=1.1 Index: peardoc/en/package/gtk2/gtk2-indexedcombobox/example.xml +++ peardoc/en/package/gtk2/gtk2-indexedcombobox/example.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk2.gtk2-indexedcombobox.example"> <refnamediv> <refname>Simple example</refname> <refpurpose>To get started easily</refpurpose> </refnamediv> <refsect1> <title>Simple example</title> <para> In this example, we will create a combo box, add an array of key/value pairs and display the currently selected pair in a label. </para> <example> <title>Simple Gtk2_IndexedComboBox example</title> <programlisting role="php"><![CDATA[ <?php require_once 'Gtk2/IndexedComboBox.php'; //display this data $arData = array( 1 => 'Germany', 2 => 'United Kingdom', 3 => 'Spain', 4 => 'France' ); //Create combo and set the array $combo = new Gtk2_IndexedComboBox(); $combo->set_array($arData); //make #2 active $combo->set_active_key(2); //trace changes $combo->connect('changed', 'comboChanged', $lbl); function comboChanged($combo, $lbl) { $lbl->set_text( "Combo changed:\r\n" . 'Key: ' . $combo->get_active_key() . "\r\n" . 'Value: ' . $combo->get_active_text() ); } //some label to display changes $lbl = new GtkLabel("Status\r\n\r\n"); //standard stuff $vbox = new GtkVBox(); $vbox->pack_start($combo); $vbox->pack_start($lbl); $wnd = new GtkWindow(); $wnd->connect_simple('destroy', array('Gtk', 'main_quit')); $wnd->add($vbox); $wnd->show_all(); Gtk::main(); ?> ]]></programlisting> </example> <para> At first, we create a new combo widget object. You already could pass the array of data in the constructor if you wanted to, but here we use the <function>set_array</function> method to do this. After providing the data, entry with id <literal>2</literal> is made active/pre-selected. </para> <para> Whenever the selection changes, the example displays the selected key and value in a label below the combo box. We use <function>get_active_key</function> to retrieve the key, and <function>get_active_text</function> to retrieve the value. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2/gtk2-indexedcombobox/glade.xml?view=markup&rev=1.1 Index: peardoc/en/package/gtk2/gtk2-indexedcombobox/glade.xml +++ peardoc/en/package/gtk2/gtk2-indexedcombobox/glade.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk2.gtk2-indexedcombobox.glade"> <refnamediv> <refname>Conquering Glade combo boxes</refname> <refpurpose>How to use glade combos with this class</refpurpose> </refnamediv> <refsect1> <title>Conquering Glade combo boxes</title> <para> While designing your user interface with Glade is really convenient and easy, it doesn't allow you to use custom classes as this combo here. Thanks to the MVC model in Gtk2, you still can use this class's power by using the same model as <classname>Gtk2_IndexedComboBox</classname> uses internally: <classname>Gtk2_IndexedComboBox_Model</classname>. </para> <example> <title>Glade file to use</title> <programlisting role="xml"><![CDATA[ <?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> <glade-interface> <widget class="GtkWindow" id="wndTest"> <property name="visible">True</property> <property name="title" translatable="yes">Gtk2_IndexedComboBox_Model test</property> <property name="type">GTK_WINDOW_TOPLEVEL</property> <property name="window_position">GTK_WIN_POS_NONE</property> <property name="modal">False</property> <property name="resizable">True</property> <property name="destroy_with_parent">False</property> <property name="decorated">True</property> <property name="skip_taskbar_hint">False</property> <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <signal name="destroy" handler="Gtk::main_quit"/> <child> <widget class="GtkComboBox" id="cmbNormal"> <property name="visible">True</property> </widget> </child> </widget> </glade-interface> ]]></programlisting> </example> <example> <title>PHP code</title> <programlisting><![CDATA[ <?php require_once 'Gtk2/IndexedComboBox/Model.php'; $glade = new GladeXML(dirname(__FILE__) . '/glade.glade'); $glade->signal_autoconnect(); $combo = $glade->get_widget('cmbNormal'); $combo->connect('changed', 'comboChanged'); //show the second column only $renderer = new GtkCellRendererText(); $combo->pack_start($renderer); $combo->set_attributes($renderer, 'text', 1); $mod = new Gtk2_IndexedComboBox_Model(); $combo->set_model($mod); $mod->append(1, 'One'); $mod->append_array(array(2 => 'Two', 3 => 'Three')); $mod->prepend(4, 'Four'); function comboChanged($combo) { $nActive = $combo->get_active(); $iter = $combo->get_model()->get_iter($nActive); $key = $combo->get_model()->get_key($iter); $text = $combo->get_model()->get_text($iter); echo 'Selected: ' . $key . ' => ' . $text . "\r\n"; } Gtk::main(); ?> ]]></programlisting> </example> <para> The important thing to remember is that you need to setup your own cell renderer, and tell it which column in the model shall be displayed. Beside that, you just do the normal model-creation-and-setting via <function>set_model</function>. </para> <para> All data manipulation methods of <classname>Gtk2_IndexedComboBox</classname> you saw in the previous example are available in the model, <classname>Gtk2_IndexedComboBox_Model</classname>. Only <function>get_active_key</function> and <function>get_active_text</function> cannot be used on the model, since this doesn't know anything about selections. Retrieve the selected <classname>GtkTreeIter</classname> by combining the calls of <function>get_active</function> and <function>get_iter</function>, and pass this <literal>iter</literal> object to <function>get_key</function> and <function>get_text</function>. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox-model.xml?view=markup&rev=1.1 Index: peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox-model.xml +++ peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox-model.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk2.gtk2-indexedcombobox.gtk2-indexedcombobox-model"> <refnamediv> <refname>Gtk2_IndexedComboBox_Model</refname> <refpurpose>Model class behind the scenes</refpurpose> </refnamediv> <refsect1> <title>Gtk2_IndexedComboBox_Model</title> <para> The model class is the data storage for your key/value pairs. It contains two columns, both are of type <literal>Gtk::TYPE_STRING</literal> and can hold text and numbers. The first is used for the keys, the values are stored in the second column. </para> <para> The class has several method that allow you to store data in the model: The classis <function>set_array</function> takes an associative array of key/value pairs. Once set, you can use <function>append_array</function> and <function>prepend_array</function> to add new data after or before the current values. You also have the possibility to use <function>insert_array</function> that takes the position as first, and the data array as second parameter. </para> <para> Beside the <literal>*_array</literal> methods, you can add single key/value pairs by using <function>append</function> and <function>prepend</function> which take the key as first, and the value as second parameter. <function>insert</function> wants an additional position number as first parameter, and key/value as second and third. </para> <para> To delete data from the model, use <function>remove_key</function>. After finishing your data manipulation, you can retrieve the full associative array of key/value pairs via <function>get_array</function>. </para> <para> To obtain the key or value of a certain <classname>GtkTreeIter</classname> (that you got e.g. from the model by using <function>get_iter</function>), use <function>get_key</function> and <function>get_text</function>. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox.xml?view=markup&rev=1.1 Index: peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox.xml +++ peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk2.gtk2-indexedcombobox.gtk2-indexedcombobox"> <refnamediv> <refname>Gtk2_IndexedComboBox</refname> <refpurpose>The main class</refpurpose> </refnamediv> <refsect1> <title>Gtk2_IndexedComboBox</title> <para> <classname>Gtk2_IndexedComboBox</classname> automatically creates the model and sets up the cell renderer when instantiating the widget. You may pass an array of key/value pairs to the constructor if you like to, but also can set them later. </para> <para> The currently selected (active) key can be retrieved via <function>get_active_key</function>, the selected (active) value by using <function>get_active_text</function>. You can preselect a certain key with <function>set_active_key</function>. </para> <para> If you don't like the renderer or want to change it or its attributes, use <function>get_cell_renderer</function> and <function>set_cell_renderer</function>. </para> <para> All other methods to retrieve/store data are convenience methods that act as proxy to the model. For example, <classname>Gtk2_IndexedComboBox</classname>' method <function>set_array</function> internally calls the same method on the model, <classname>Gtk2_IndexedComboBox_Model</classname>. This allows you to quickly add some data to the combo without getting the model first and acting on it. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2.xml?r1=1.5&r2=1.6&diff_format=u Index: peardoc/en/package/gtk2.xml diff -u peardoc/en/package/gtk2.xml:1.5 peardoc/en/package/gtk2.xml:1.6 --- peardoc/en/package/gtk2.xml:1.5 Fri Oct 27 20:13:25 2006 +++ peardoc/en/package/gtk2.xml Thu Nov 2 17:21:47 2006 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <chapter id="package.gtk2"> @@ -15,6 +15,7 @@ &package.gtk2.entrydialog; &package.gtk2.exceptiondump; &package.gtk2.filedrop; + &package.gtk2.gtk2-indexedcombobox; &package.gtk2.vardump; </chapter> http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2/gtk2-indexedcombobox.xml?view=markup&rev=1.1 Index: peardoc/en/package/gtk2/gtk2-indexedcombobox.xml +++ peardoc/en/package/gtk2/gtk2-indexedcombobox.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <sect1 id="package.gtk2.gtk2-indexedcombobox"> <title>Gtk2_IndexedComboBox</title> <abstract> <para> <classname>Gtk2_IndexedComboBox</classname> is a Gtk2 widget similar to the HTML <literal>select</literal> box - it lets you not only store values as the normal <classname>GtkComboBox</classname>, but associated key/value pairs. </para> </abstract> <para> <classname>Gtk2_IndexedComboBox</classname> is meant to be as easy to use as possible, and to have an API similar to the combo boxes created with <function>GtkComboBox::new_text</function>. You can directly add key/value pairs to the widget instead of using the model (which is possible, too). Retrieving the currently selected key can be done with a single method call. </para> <para> Both keys and values can be strings, thus allowing integers implicitly. This is very useful if you need a widget to select some row ID from a database, but want to display some descriptive string. By default, a single <classname>GtkCellRendererText</classname> is used as cell renderer. </para> &package.gtk2.gtk2-indexedcombobox.example; &package.gtk2.gtk2-indexedcombobox.glade; &package.gtk2.gtk2-indexedcombobox.gtk2-indexedcombobox; &package.gtk2.gtk2-indexedcombobox.gtk2-indexedcombobox-model; </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2/gtk2-indexedcombobox/example.xml?view=markup&rev=1.1 Index: peardoc/en/package/gtk2/gtk2-indexedcombobox/example.xml +++ peardoc/en/package/gtk2/gtk2-indexedcombobox/example.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk2.gtk2-indexedcombobox.example"> <refnamediv> <refname>Simple example</refname> <refpurpose>To get started easily</refpurpose> </refnamediv> <refsect1> <title>Simple example</title> <para> In this example, we will create a combo box, add an array of key/value pairs and display the currently selected pair in a label. </para> <example> <title>Simple Gtk2_IndexedComboBox example</title> <programlisting role="php"><![CDATA[ <?php require_once 'Gtk2/IndexedComboBox.php'; //display this data $arData = array( 1 => 'Germany', 2 => 'United Kingdom', 3 => 'Spain', 4 => 'France' ); //Create combo and set the array $combo = new Gtk2_IndexedComboBox(); $combo->set_array($arData); //make #2 active $combo->set_active_key(2); //trace changes $combo->connect('changed', 'comboChanged', $lbl); function comboChanged($combo, $lbl) { $lbl->set_text( "Combo changed:\r\n" . 'Key: ' . $combo->get_active_key() . "\r\n" . 'Value: ' . $combo->get_active_text() ); } //some label to display changes $lbl = new GtkLabel("Status\r\n\r\n"); //standard stuff $vbox = new GtkVBox(); $vbox->pack_start($combo); $vbox->pack_start($lbl); $wnd = new GtkWindow(); $wnd->connect_simple('destroy', array('Gtk', 'main_quit')); $wnd->add($vbox); $wnd->show_all(); Gtk::main(); ?> ]]></programlisting> </example> <para> At first, we create a new combo widget object. You already could pass the array of data in the constructor if you wanted to, but here we use the <function>set_array</function> method to do this. After providing the data, entry with id <literal>2</literal> is made active/pre-selected. </para> <para> Whenever the selection changes, the example displays the selected key and value in a label below the combo box. We use <function>get_active_key</function> to retrieve the key, and <function>get_active_text</function> to retrieve the value. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2/gtk2-indexedcombobox/glade.xml?view=markup&rev=1.1 Index: peardoc/en/package/gtk2/gtk2-indexedcombobox/glade.xml +++ peardoc/en/package/gtk2/gtk2-indexedcombobox/glade.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk2.gtk2-indexedcombobox.glade"> <refnamediv> <refname>Conquering Glade combo boxes</refname> <refpurpose>How to use glade combos with this class</refpurpose> </refnamediv> <refsect1> <title>Conquering Glade combo boxes</title> <para> While designing your user interface with Glade is really convenient and easy, it doesn't allow you to use custom classes as this combo here. Thanks to the MVC model in Gtk2, you still can use this class's power by using the same model as <classname>Gtk2_IndexedComboBox</classname> uses internally: <classname>Gtk2_IndexedComboBox_Model</classname>. </para> <example> <title>Glade file to use</title> <programlisting role="xml"><![CDATA[ <?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> <glade-interface> <widget class="GtkWindow" id="wndTest"> <property name="visible">True</property> <property name="title" translatable="yes">Gtk2_IndexedComboBox_Model test</property> <property name="type">GTK_WINDOW_TOPLEVEL</property> <property name="window_position">GTK_WIN_POS_NONE</property> <property name="modal">False</property> <property name="resizable">True</property> <property name="destroy_with_parent">False</property> <property name="decorated">True</property> <property name="skip_taskbar_hint">False</property> <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <signal name="destroy" handler="Gtk::main_quit"/> <child> <widget class="GtkComboBox" id="cmbNormal"> <property name="visible">True</property> </widget> </child> </widget> </glade-interface> ]]></programlisting> </example> <example> <title>PHP code</title> <programlisting><![CDATA[ <?php require_once 'Gtk2/IndexedComboBox/Model.php'; $glade = new GladeXML(dirname(__FILE__) . '/glade.glade'); $glade->signal_autoconnect(); $combo = $glade->get_widget('cmbNormal'); $combo->connect('changed', 'comboChanged'); //show the second column only $renderer = new GtkCellRendererText(); $combo->pack_start($renderer); $combo->set_attributes($renderer, 'text', 1); $mod = new Gtk2_IndexedComboBox_Model(); $combo->set_model($mod); $mod->append(1, 'One'); $mod->append_array(array(2 => 'Two', 3 => 'Three')); $mod->prepend(4, 'Four'); function comboChanged($combo) { $nActive = $combo->get_active(); $iter = $combo->get_model()->get_iter($nActive); $key = $combo->get_model()->get_key($iter); $text = $combo->get_model()->get_text($iter); echo 'Selected: ' . $key . ' => ' . $text . "\r\n"; } Gtk::main(); ?> ]]></programlisting> </example> <para> The important thing to remember is that you need to setup your own cell renderer, and tell it which column in the model shall be displayed. Beside that, you just do the normal model-creation-and-setting via <function>set_model</function>. </para> <para> All data manipulation methods of <classname>Gtk2_IndexedComboBox</classname> you saw in the previous example are available in the model, <classname>Gtk2_IndexedComboBox_Model</classname>. Only <function>get_active_key</function> and <function>get_active_text</function> cannot be used on the model, since this doesn't know anything about selections. Retrieve the selected <classname>GtkTreeIter</classname> by combining the calls of <function>get_active</function> and <function>get_iter</function>, and pass this <literal>iter</literal> object to <function>get_key</function> and <function>get_text</function>. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox-model.xml?view=markup&rev=1.1 Index: peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox-model.xml +++ peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox-model.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk2.gtk2-indexedcombobox.gtk2-indexedcombobox-model"> <refnamediv> <refname>Gtk2_IndexedComboBox_Model</refname> <refpurpose>Model class behind the scenes</refpurpose> </refnamediv> <refsect1> <title>Gtk2_IndexedComboBox_Model</title> <para> The model class is the data storage for your key/value pairs. It contains two columns, both are of type <literal>Gtk::TYPE_STRING</literal> and can hold text and numbers. The first is used for the keys, the values are stored in the second column. </para> <para> The class has several method that allow you to store data in the model: The classis <function>set_array</function> takes an associative array of key/value pairs. Once set, you can use <function>append_array</function> and <function>prepend_array</function> to add new data after or before the current values. You also have the possibility to use <function>insert_array</function> that takes the position as first, and the data array as second parameter. </para> <para> Beside the <literal>*_array</literal> methods, you can add single key/value pairs by using <function>append</function> and <function>prepend</function> which take the key as first, and the value as second parameter. <function>insert</function> wants an additional position number as first parameter, and key/value as second and third. </para> <para> To delete data from the model, use <function>remove_key</function>. After finishing your data manipulation, you can retrieve the full associative array of key/value pairs via <function>get_array</function>. </para> <para> To obtain the key or value of a certain <classname>GtkTreeIter</classname> (that you got e.g. from the model by using <function>get_iter</function>), use <function>get_key</function> and <function>get_text</function>. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox.xml?view=markup&rev=1.1 Index: peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox.xml +++ peardoc/en/package/gtk2/gtk2-indexedcombobox/gtk2-indexedcombobox.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.gtk2.gtk2-indexedcombobox.gtk2-indexedcombobox"> <refnamediv> <refname>Gtk2_IndexedComboBox</refname> <refpurpose>The main class</refpurpose> </refnamediv> <refsect1> <title>Gtk2_IndexedComboBox</title> <para> <classname>Gtk2_IndexedComboBox</classname> automatically creates the model and sets up the cell renderer when instantiating the widget. You may pass an array of key/value pairs to the constructor if you like to, but also can set them later. </para> <para> The currently selected (active) key can be retrieved via <function>get_active_key</function>, the selected (active) value by using <function>get_active_text</function>. You can preselect a certain key with <function>set_active_key</function>. </para> <para> If you don't like the renderer or want to change it or its attributes, use <function>get_cell_renderer</function> and <function>set_cell_renderer</function>. </para> <para> All other methods to retrieve/store data are convenience methods that act as proxy to the model. For example, <classname>Gtk2_IndexedComboBox</classname>' method <function>set_array</function> internally calls the same method on the model, <classname>Gtk2_IndexedComboBox_Model</classname>. This allows you to quickly add some data to the combo without getting the model first and acting on it. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->