Re: [PHP-GTK] Touble clearing GtkComboBoxEntry text list, some Glade related problems
[email protected] (kksou)
| Newsgroups | php.gtk.general |
|---|---|
| Message-ID | <[email protected]> |
Bernard Fouché wrote:
> Unfortunately, since my layout is done with Glade-2, such examples do
> not help me much.
>
Glade is a wonderful tool that helps one layout the widget. But no matter
how good Glade is, it won't do the programming part for you.
Anyway, below is the Glade version of the same example:
http://www.kksou.com/php-gtk2/articles/change-options-of-pulldown-menu-on-the-fly-using-GtkComboBoxEntry.php
Just wanted to show you that Glade merely "simplifies" the GUI portion. The
core php-gtk2 codes (that's does the signal handling and re-populating of
combobox entries) are exactly the same.
Also, as you work on more combobox/comboboxentry, you will find that
eventually you will need to resort to handling models directly. It's cleaner
and more powerful. For example, using insert_text(), you can only store one
column of data. With models, you could store and display more than one
columns of data in the pulldown menu. You could also use GtkTreeModelFilter
and GtkTreeModelSort for comboboxes.
Regards,
/kksou
<?php
// How to change options of pulldown menu on the fly
// using GtkComboBoxEntry
// same as http://www.kksou.com/php-gtk2/articles/
// change-options-of-pulldown-menu-on-the-fly-using-GtkComboBoxEntry.php
// but using glade
$glade = new GladeXML('0297.glade');
// the options for pulldown menu
$list['US'] = array('US-1', 'US-2', 'US-3', 'US-4');
$list['Europe'] = array('Europe-1', 'Europe-2', 'Europe-3',
'Europe-4', 'Europe-5', 'Europe-6');
// setup model
$model = new GtkListStore(Gtk::TYPE_STRING);
$combobox = $glade->get_widget('comboboxentry1');
$combobox->clear();
$combobox->set_model($model);
$cell_renderer = new GtkCellRendererText();
$combobox->pack_start($cell_renderer);
$combobox->set_attributes($cell_renderer, 'text', 0);
populate('Europe');
$glade->signal_autoconnect();
Gtk::main();
function on_submit($button) {
global $combobox;
$selection = $combobox->get_child()->get_text();
echo "You have selected: $selection!\n";
}
function on_button($button) {
$continent = $button->get_label();
echo "continent: $continent\n";
populate($continent);
}
function populate($continent) {
global $model, $list;
$model->clear();
foreach($list[$continent] as $choice) {
$model->append(array($choice));
}
}
?>
<?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="width_request">400</property>
<property name="height_request">180</property>
<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="default_width">400</property>
<property name="default_height">180</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>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label1">
<property name="height_request">40</property>
<property name="visible">True</property>
<property name="label" translatable="yes"><span font_desc="Times
New Roman Italic 10" foreground="#0000ff">Change
GtkComboBoxEntry options on the fly</span></property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="label" translatable="yes">Continent: </property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button1">
<property name="width_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">US</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button"
last_modification_time="Wed, 01 Aug 2007 05:15:18 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button2">
<property name="width_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Europe</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button"
last_modification_time="Wed, 01 Aug 2007 05:15:26 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox2">
<property name="height_request">10</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">Select: </property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkComboBoxEntry" id="comboboxentry1">
<property name="visible">True</property>
<property name="items" translatable="yes">
</property>
<property name="add_tearoffs">False</property>
<property name="has_frame">True</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="label" translatable="yes"> </property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Submit</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_submit"
last_modification_time="Wed, 01 Aug 2007 05:16:14 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
--
View this message in context: http://www.nabble.com/Touble-clearing-GtkComboBoxEntry-text-list-tf4152109.html#a11940325
Sent from the Php - GTK - General mailing list archive at Nabble.com.