| View previous topic :: View next topic |
| Author |
Message |
Osiris
Joined: 17 Dec 2005 Posts: 65
|
Posted: Fri Jan 06, 2006 7:14 pm Post subject: setting GtkComboBox values from php-file (glade2 way) |
|
|
Hello,
described in another topic in this forum, I'm in search of the solution, how to set values in a GTKComboBox (which was created from a glade file).
The values are defined in a php-file and should inserted into the GTKComboBox at runtime.
The described way in the documentation didn't worked, so how do I build this value-list?
Thanks a lot
Christian |
|
| Back to top |
|
 |
neters
Joined: 04 Jan 2006 Posts: 5
|
Posted: Fri Jan 06, 2006 7:58 pm Post subject: |
|
|
I found using this construct seems to work:
| Code: |
$gl = &new GladeXML('some.glade'); // widget mycombobox is in XML
$cb = $gl->get_widget('mycombobox');
$cb->append_text('New Text');
|
Niles |
|
| Back to top |
|
 |
Osiris
Joined: 17 Dec 2005 Posts: 65
|
Posted: Tue Jan 10, 2006 10:17 pm Post subject: |
|
|
Hello,
my construct is taken from version 1 of php-gtk (basic code was built with appwizard) and is extended
| Code: |
class mp3catalog extends GtkWindow
{
public function __construct()
{
parent::__construct();
$this->InitDialog();
}
function InitDialog()
{
$this->BuildDialog();
}
function BuildDialog()
{
$this->glMain_window =& new GladeXML( dirname( __FILE__) . $this->strPathSeparator . "mp3catalog.glade");
self::$arWidgets["file_genre"] = $this->glMain_window->get_widget( "file_genre");
foreach (self::$genrelist as $genre){
self::$arWidgets["file_genre"]->append_text($genre);
}
}
|
But no values in this combobox, while $genrelist is filled with many values.
So, I'm on a wrong way, rebuilding my app with gtk2?
Greetings
Christian |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Tue Jan 10, 2006 10:45 pm Post subject: |
|
|
That code works for me:
| Code: | <?php
$glade = new GladeXML(dirname(__FILE__) . '/combofill.glade');
$combo = $glade->get_widget('combo');
$combo->append_text('ten');
Gtk::main();
?> |
But beware, I already set some values in glade (that forces the combo to create the text model):
| Code: | <?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="window1">
<property name="visible">True</property>
<property name="title" translatable="yes">window1</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>
<child>
<widget class="GtkComboBoxEntry" id="combo">
<property name="visible">True</property>
<property name="items" translatable="yes">one
two
three</property>
</widget>
</child>
</widget>
</glade-interface> |
|
|
| Back to top |
|
 |
Osiris
Joined: 17 Dec 2005 Posts: 65
|
Posted: Sun Jan 15, 2006 12:20 pm Post subject: |
|
|
Thanks,Christian,
last hint was the right one
setting
| Code: |
<property name="items" translatable="yes"></property>
|
created the text model.
The property can be empty, initial values are optional
now all the values in there
Greetings
Christian |
|
| Back to top |
|
 |
ssiwek
Joined: 15 May 2006 Posts: 20
|
Posted: Tue May 16, 2006 1:58 pm Post subject: |
|
|
| Osiris wrote: | Thanks,Christian,
last hint was the right one
setting
| Code: |
<property name="items" translatable="yes"></property>
|
created the text model.
The property can be empty, initial values are optional
now all the values in there
Greetings
Christian |
How do I set that value in the glade-designer?
Sven |
|
| Back to top |
|
 |
squirrel
Joined: 02 May 2006 Posts: 10 Location: Switzerland
|
Posted: Tue May 16, 2006 2:19 pm Post subject: |
|
|
Hi Sven,
| Quote: | | How do I set that value in the glade-designer? |
In the glade-designer you just put in some values in the property 'Items', save the file, delete the items and save again. Then you will end up with an empty items-node in the glade-xml.
Regards
- Gerry |
|
| Back to top |
|
 |
Osiris
Joined: 17 Dec 2005 Posts: 65
|
Posted: Tue May 16, 2006 2:29 pm Post subject: |
|
|
other possible way:
use GtkListStore to add values to a combobox,
see GTK_IndexedComboBox from Christian at pear.php.net for key,value-paired version of ComboBox items. |
|
| Back to top |
|
 |
ssiwek
Joined: 15 May 2006 Posts: 20
|
Posted: Tue May 16, 2006 3:11 pm Post subject: |
|
|
Hi!
Again thx for the quick replies.
I want to fill the combox via database values, so as a work around I will put some items in save and delete them.
Maybe IŽll try to find a way to use the IndexedComboBox via glade-designer.
A first approach would be to use the "custom" widget I think.
Have a nice day
Sven |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Tue May 16, 2006 3:15 pm Post subject: |
|
|
| Quote: | Maybe IŽll try to find a way to use the IndexedComboBox via glade-designer.
A first approach would be to use the "custom" widget I think. |
No. The right way is to use a normal Combobox in Glade and just set the model. The latest version of Gtk2_IndexedComboBox provides a Gtk2_IndexedComboBox_Model class that was designed for use in already existing combo boxes.
The package contains an example how to use it on glade files. |
|
| Back to top |
|
 |
|