Re: gtk read result of combobox
| From: | kksou | Date: | Tue, 19 Sep 2006 03:02:16 +0000 |
| Subject: | Re: gtk read result of combobox | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-7254@lists.php.net to get a copy of this message | ||
jerik wrote:
>
> I just started to work with php-gtk. At the moment I work on version
> 1.0.2. And I have a problem reading the values from a combobox.
>
By the way, since you are starting with php-gtk, why don't you go straight
to php-gtk2. It's more powerful and has much more functions that would save
you tons of work if you want to do similar things using php-gtk1.
For example, php-gtk2 has GtkComboBoxEntry, in addition to GtkComboBox. The
main difference is that GtkComboBoxEntry allow users to enter values that
not present in the selection list. The user can choose and modify existing
value, or enter a completely new one. (This is very similar to that of a
browser in which you can type in a new url, or select from the list of urls
that you have entered before. or you can select then modify from there.)
Note that although the names are very similar, the setting up and processing
of GtkComboBox and GtkComboBoxEntry is surprisingly quite different! It's
much simplier for GtkComboBoxEntry.
For those who wish to try out GtkComboBoxEntry, here's a sample code to
produce the following output:
http://127.0.0.1/php-gtk2/gif/0025.gif
$window = &new GtkWindow();
$window->connect_simple('destroy', array( 'Gtk', 'main_quit'));
$window->set_size_request(400,150);
$window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Setup and read value from ComboBox");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$title->set_size_request(-1, 60);
$vbox->pack_start($title, 0, 0);
// the selection
$list = array('item 1', 'item 2', 'item 3', 'item 4');
$vbox->pack_start($hbox=new GtkHBox(), 0, 0);
$hbox->pack_start(new GtkLabel('Select: '), 0, 0);
// Create a new comboboxentry and populates it
$combobox = &GtkComboBoxEntry::new_text();
foreach($list as $choice) {
$combobox->append_text($choice);
}
$combobox->get_child()->set_text(''); // note 1
$hbox->pack_start($combobox, 0, 0);
// Set up the submit butotn
$hbox->pack_start($button = new GtkLabel(' '), 0, 0);
$hbox->pack_start($button = new GtkButton('Submit'), 0, 0);
$button->set_size_request(60, 24);
// Set up the event handler to respond to button click
$button->connect('clicked', "on_button", $combobox); //note 2
// The callback function that is called when user clicks the submit button
function on_button($button, $combobox) {
$selection = $combobox->get_child()->get_text(); // note 3
print "You have selected: $selection\n";
}
$window->show_all();
Gtk::main();
http://127.0.0.1/php-gtk2/articles/setup-and-process-GtkComboBoxEntry.php
More explanations here...
--
View this message in context: http://www.nabble.com/gtk-read-result-of-combobox-tf2290752.html#a6381161
Sent from the Php - GTK - General mailing list archive at Nabble.com.