I have some problems here... can anyone help me ?
| From: | Mauro Ferreira | Date: | Sat, 30 Jun 2001 17:19:54 +0000 |
| Subject: | I have some problems here... can anyone help me ? | ||
| Groups: | php.gtk | ||
| Request: | Send a blank email to php-gtk+get-2004@lists.php.net to get a copy of this message | ||
I wrote this code to explain what are my problems:
<?
// 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();
$label = &new GtkLabel('Code');
$table->attach($label,0,1,0,1,GTK_SHRINK);
$label->show();
$colLength = 5;
$entry0 = &new GtkEntry();
$entry0->set_max_length($colLength);
if(($entryLength = 8*$colLength)<18) $entryLength = 18;
$entry0->set_usize($entryLength,18);
$table->attach($entry0,1,2,0,1,GTK_SHRINK);
$entry0->show();
$label = &new GtkLabel('Short Description');
$table->attach($label,0,1,1,2,GTK_SHRINK);
$label->show();
$colLength = 30;
$entry1 = &new GtkEntry();
$entry1->set_max_length($colLength);
if(($entryLength = 8*$colLength)<18) $entryLength = 18;
$entry1->set_usize($entryLength,18);
$table->attach($entry1,1,2,1,2,GTK_SHRINK);
$entry1->show();
$label = &new GtkLabel('Length');
$table->attach($label,0,1,2,3,GTK_SHRINK);
$label->show();
$typeText[0]="Tiny";
$typeText[1]="Short";
$typeText[2]="Normal";
$typeText[3]="Long";
$typeText[4]="Big";
$comBox3 = &new GtkCombo();
$comBox3->set_popdown_strings($typeText);
$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->set_selection_mode(GTK_SELECTION_BROWSE);
$index3 = 2;
$comBox3_list->select_item($index3);
$comBox3_list->connect('select_child','comBox3Changed');
function comBox3Changed($whatIsThis){ // i don't know what goes here...
global $comBox3,$typeText,$index3;
$text = $comBox3->entry;
for($index3=0;$index3<count($typeText) &&
$text->get_text()!=$typeText[$index3];$index3++);
echo '['.$index3.']';
}
$table->attach($comBox3,1,2,2,3,GTK_SHRINK);
$comBox3->show();
$label = &new GtkLabel('Type');
$table->attach($label,0,1,3,4,GTK_SHRINK);
$label->show();
$horBox = &new GtkHBox(FALSE,0);
$horBox->set_border_width(0);
$table->attach($horBox,1,2,3,4,GTK_SHRINK);
$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;
}
?>
Ugly ! With a terrible, indirect logic ! - i agree, and need help to fix it...
First, presentation stetic: how to define the alignment of the table cells inside ? In this specific
case, i need all cells left-justified, but in others i need mixed alignments;
Second, in the comboBox3, how to get the indexes, and not the text values (i.e., i need 0,1,2 and
not 'Tiny','Small','Normal'; without this ridiculous comBox3Changed ?
Third, exists a way to get the index of the selected button without this ugly button4Changed ?
Fourth, my english; i'm reading tech docs for 20 years, but never learned to write or
talk...sorry
Mauro Ferreira
'If you can understand what C programmers are talking about, or you're a C programmer too
or they aren't....' - from one of my customers after a few minutes hearing a talk between
me and his internal support...