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

From: Date: Sun, 01 Jul 2001 23:53:46 +0000
Subject: Re: I have some problems here... can anyone help me ?
References: 1 2  Groups: php.gtk 
Request: Send a blank email to php-gtk+get-2020@lists.php.net to get a copy of this message
& ps you can avoid the global with set_data() a lot of the time ----- Original Message ----- From: "Steph" <Steph.Fox@btinternet.com> To: "Mauro Ferreira" <mauroferreira@enersulnet.com.br>; <php-gtk@lists.php.net> Sent: Monday, July 02, 2001 12:48 AM Subject: Re: [PHP-GTK] I have some problems here... can anyone help me ? Take a look thru whatever samples you have for create_function() - may be a good place to start - ----- Original Message ----- From: "Mauro Ferreira" <mauroferreira@enersulnet.com.br> To: <php-gtk@lists.php.net> Sent: Monday, July 02, 2001 12:37 AM Subject: Re: [PHP-GTK] I have some problems here... can anyone help me ? Well, all problems solved, but a new emerged - a small one, i can live with it, but will very more comfortable if this can be fixed: As you can see in the code, i wrote 2 classes that completelly hidden all event handling and intermediate result buffering, and build all internals as a bonus, but i can't 'connect' a internal method, but just an external function. Because that i was forced to write cmbBoxChanged & radioButtonChanged as functions, and not internal methods. But this isn't a problem, if i can avoid the 'global' clauses inside this functions. Can you tell me how to: or declare internal methods in 'connect', or avoid the 'global' in the event handler functions ? Or maybe do something like: $this->cmbBoxList->connect('select-child','$this->index=$pos'); <? // 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();} // the comboBox & radioButton event handler hidding classes - still incomplete... class comboBox { var $cmbBox; var $cmbBoxEntry; var $cmbBoxList; var $colLength; function start($instance,$text,$default,$width){ $this->cmbInstance = $instance; $this->cmbBox = &new GtkCombo(); $this->cmbBox->set_popdown_strings($text); $this->cmbBoxEntry = $this->cmbBox->entry; $this->cmbBoxEntry->set_max_length($width); if(($this->colLength = 8*$width)<18) $this->colLength = 18; $this->cmbBoxEntry->set_usize($this->colLength,18); $this->cmbBoxList=$this->cmbBox->list; $this->cmbBoxList->set_selection_mode(GTK_SELECTION_BROWSE); $this->cmbBoxList->connect('select-child','cmbBoxChanged',$pos,$instance); $this->cmbBox->index = $default; $this->cmbBoxList->select_item($default); return($this->cmbBox); } } function cmbBoxChanged($list,$listItem,$pos,$instance){ global $comBox3; // the fail i can't solve $pos=$list->child_position($listItem); eval($instance.'->index='.$pos.';'); } class radioButton { var $button; var $buttonx; var $tmp; var $index; function start($instance,$text,$default,&$horBox){ $this->button = &new GtkRadioButton(NULL,$text[0]); $this->button->connect('clicked','buttonChanged',0,$instance); if(!$default) $button->set_active(TRUE); $horBox->pack_start($this->button,TRUE,TRUE,0); $this->button->show(); for($this->tmp=1;$this->tmp<count($text);$this->tmp++){ $this->buttonx = &new GtkRadioButton($this->button,$text[$this->tmp]); $this->buttonx->connect('clicked','buttonChanged',$this->tmp,$instance); if($this->tmp==$default) $this->buttonx->set_active(TRUE); $horBox->pack_start($this->buttonx,TRUE,TRUE,0); $this->buttonx->show(); } } } function buttonChanged($button,$pos,$instance){ global $button4; // the same fail again eval($instance.'->index='.$pos.';'); } $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(); $text = array("Tiny","Short","Normal","Long","Big"); $comBox3 = new comboBox; $comBox3 = $comBox3->start('$comBox3',$text,2,20); // hehehe...'see, mom ! no head !' $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(); $text = array('Autonumber','Signed','Unsigned'); $button4 = new radioButton; $button4->start('$button4',$text,1,$horBox); $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,$comBox3,$button4; $crlf = chr(13).chr(10); echo $crlf; echo 'Code:'.$entry0->get_text().$crlf; echo 'Short Description:'.$entry1->get_text().$crlf; echo 'Length:'.$comBox3->index.$crlf; echo 'Type:'.$button4->index.$crlf; } ?> -- PHP GTK Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-gtk-unsubscribe@lists.php.net For additional commands, e-mail: php-gtk-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.gtk (#2020) next »