Re: I have some problems here... can anyone help me ?

From: Date: Sun, 01 Jul 2001 02:51:24 +0000
Subject: Re: I have some problems here... can anyone help me ?
Groups: php.gtk 
Request: Send a blank email to php-gtk+get-2010@lists.php.net to get a copy of this message
I do all i know and can understand until now - i agree, it's a better way, i don't need to search nothing to get the index at end, but i'm still handling events and storing intermediate results in comboBox like i did in radioButtom, instead of just directly getting the results inside showMe, as i think to be the right way. If this isn't possible, i think the only way to get a more readable code will be creating a class for combo boxes and another for radio buttons, encapsulating this event handling with the purpose of hidding this dirty thing. The program is now: <? // standard header if(strtoupper(substr(PHP_OS,0,3))=='WIN') dl('php_gtk.dll'); else dl('php_gtk.so'); function closeWindow($widget){$window=$widget->get_toplevel();$window->destroy();} function shutdown(){Gtk::main_quit();} $window=&new GtkWindow; $window->connect('destroy','shutdown'); $window->set_title('form'); $window->set_border_width(0); $verBox = &new GtkVBox(FALSE,0); $verBox->set_border_width(0); $window->add($verBox); $verBox->show(); $table = &new GtkTable(3,5,FALSE); $table->set_row_spacings(2); $table->set_col_spacings(2); $table->set_border_width(5); $verBox->pack_start($table,FALSE,FALSE,0); $table->show(); $align = &new GtkAlignment(0.0,0.5,0.0,0.0); // result from a global search for 'align' $table->attach($align,0,1,0,1,GTK_FILL); // in all gtk manual... $align->show(); // and then a look in 'Hitchhiker's Guide' $label = &new GtkLabel('Code '); $label->set_justify(GTK_JUSTIFY_LEFT); // thanks twice, Steph ! Problem 1 solved ! $align->add($label); $label->show(); $align = &new GtkAlignment(0.0,0.5,0.0,0.0); $table->attach($align,1,2,0,1,GTK_FILL); $align->show(); $colLength = 5; $entry0 = &new GtkEntry(); $entry0->set_max_length($colLength); if(($entryLength = 8*$colLength)<18) $entryLength = 18; $entry0->set_usize($entryLength,18); $align->add($entry0); $entry0->show(); $align = &new GtkAlignment(0.0,0.5,0.0,0.0); $table->attach($align,0,1,1,2,GTK_FILL); $align->show(); $label = &new GtkLabel('Short Description '); $label->set_justify(GTK_JUSTIFY_LEFT); $align->add($label); $label->show(); $align = &new GtkAlignment(0.0,0.5,0.0,0.0); $table->attach($align,1,2,1,2,GTK_FILL); $align->show(); $colLength = 30; $entry1 = &new GtkEntry(); $entry1->set_max_length($colLength); if(($entryLength = 8*$colLength)<18) $entryLength = 18; $entry1->set_usize($entryLength,18); $align->add($entry1); $entry1->show(); $align = &new GtkAlignment(0.0,0.5,0.0,0.0); $table->attach($align,0,1,2,3,GTK_FILL); $align->show(); $label = &new GtkLabel('Length '); $label->set_justify(GTK_JUSTIFY_LEFT); $align->add($label); $label->show(); $align = &new GtkAlignment(0.0,0.5,0.0,0.0); $table->attach($align,1,2,2,3,GTK_FILL); $align->show(); $item0 = &new GtkListItem('Tiny'); $item0->connect('select','comBox3Changed',0); $item0->show(); $item1 = &new GtkListItem('Small'); $item1->connect('select','comBox3Changed',1); $item1->show(); $item2 = &new GtkListItem('Normal'); $item2->connect('select','comBox3Changed',2); $item2->show(); $item3 = &new GtkListItem('Long'); $item3->connect('select','comBox3Changed',3); $item3->show(); $item4 = &new GtkListItem('Big'); $item4->connect('select','comBox3Changed',4); $item4->show(); $array = array($item0,$item1,$item2,$item3,$item4); $comBox3 = &new GtkCombo(); $comBox3_entry = $comBox3->entry; $colLength = 20; $comBox3_entry->set_max_length($colLength); if(($entryLength = 8*$colLength)<18) $entryLength = 18; $comBox3_entry->set_usize($entryLength,18); $comBox3_list=$comBox3->list; $comBox3_list->append_items($array); $comBox3_list->set_selection_mode(GTK_SELECTION_BROWSE); $index3 = 2; $comBox3_list->select_item($index3); function comBox3Changed($listItem,$value){ global $index3; $index3 = $value; } $align->add($comBox3); $comBox3->show(); $align = &new GtkAlignment(0.0,0.5,0.0,0.0); $table->attach($align,0,1,3,4,GTK_FILL); $align->show(); $label = &new GtkLabel('Type '); $label->set_justify(GTK_JUSTIFY_LEFT); $align->add($label); $label->show(); $align = &new GtkAlignment(0.0,0.5,0.0,0.0); $table->attach($align,1,2,3,4,GTK_FILL); $align->show(); $horBox = &new GtkHBox(FALSE,0); $horBox->set_border_width(0); $align->add($horBox); $horBox->show(); $index4 = 1; $button4=&new GtkRadioButton(null,'Autonumber'); $button4->connect('clicked','button4Changed',0); function button4Changed($button,$value){ global $index4; $index4 = $value; echo '['.$index4.']'; } $horBox->pack_start($button4,TRUE,TRUE,0); $button4->show(); $button=&new GtkRadioButton($button4,'Signed'); $button->set_active(TRUE); $button->connect('clicked','button4Changed',1); $horBox->pack_start($button,TRUE,TRUE,0); $button->show(); $button=&new GtkRadioButton($button4,'Unsigned'); $button->connect('clicked','button4Changed',2); $horBox->pack_start($button,TRUE,TRUE,0); $button->show(); $horBox = &new GtkHBox(FALSE,0); $horBox->set_border_width(0); $verBox->pack_start($horBox,FALSE,FALSE,0); $horBox->show(); $button=&new GtkButton('Show me'); $button->connect('clicked','showMe'); $horBox->pack_start($button); $button->show(); $button=&new GtkButton('Close'); $button->connect('clicked','shutdown'); $horBox->pack_start($button); $button->show(); $window->show(); Gtk::main(); function showMe($button) { global $entry0,$entry1,$index3,$index4; $crlf = chr(13).chr(10); echo $crlf; echo 'Code:'.$entry0->get_text().$crlf; echo 'Short Description:'.$entry1->get_text().$crlf; echo 'Length:'.$index3.$crlf; echo 'Type:'.$index4.$crlf; } ?>

« previous php.gtk (#2010) next »