gnope php gtk gui gnope.org  

setting GtkComboBox values from php-file (glade2 way)

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
Osiris



Joined: 17 Dec 2005
Posts: 65

PostPosted: Fri Jan 06, 2006 7:14 pm    Post subject: setting GtkComboBox values from php-file (glade2 way) Reply with quote

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

PostPosted: Fri Jan 06, 2006 7:58 pm    Post subject: Reply with quote

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

PostPosted: Tue Jan 10, 2006 10:17 pm    Post subject: Reply with quote

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

PostPosted: Tue Jan 10, 2006 10:45 pm    Post subject: Reply with quote

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

PostPosted: Sun Jan 15, 2006 12:20 pm    Post subject: Reply with quote

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 Smile

Greetings

Christian
Back to top
ssiwek



Joined: 15 May 2006
Posts: 20

PostPosted: Tue May 16, 2006 1:58 pm    Post subject: Reply with quote

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 Smile

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

PostPosted: Tue May 16, 2006 2:19 pm    Post subject: Reply with quote

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

PostPosted: Tue May 16, 2006 2:29 pm    Post subject: Reply with quote

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

PostPosted: Tue May 16, 2006 3:11 pm    Post subject: Reply with quote

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

PostPosted: Tue May 16, 2006 3:15 pm    Post subject: Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.