Re: connect() and connect_object() question

From: Date: Tue, 05 Mar 2002 16:55:29 +0000
Subject: Re: connect() and connect_object() question
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-1442@lists.php.net to get a copy of this message
connect_object() will pass the object given (why 1?!) as the first parameter. As opposed to connect() which will pass the calling object as the first parameter. any 'event' signal will pass the event to the callback function as its second parameter, i.e. you need to pick that up with the function eg $menuitem1->connect('button-press-event', 'myfunction', $number); needs to connect to function myfunction($menuitem1, $event, $number) { //do stuff } or $menuitem1->connect_object('button-press-event', 'myfunction', $button, $number); needs to connect to function myfunction($button, $event, $number) { //do stuff } HTH ----- Original Message ----- From: "Michael Waples" <michaelwaples@dingoblue.net.au> To: <php-gtk-general@lists.php.net> Sent: Wednesday, March 06, 2002 8:49 AM Subject: [PHP-GTK] connect() and connect_object() question > Im using in a script - > $menuitem1->connect_object('button-release-event', 'radiomenu_activate', > 1); > > I thought this shouldn't work as connect_object() required an object for the > argument but it's the only way I could get the script to get the $number > variable correctly. > > I thought just using connect() was the right way as I'm not using any other > object in the function. > > I'm just wondering what I'm missing. Is there something different about > 'button-release-event'. ? > > Here's the script > > <?php > if (!class_exists('gtk')) { > if (strtoupper(substr(PHP_OS, 0,3) == 'WIN')) > dl('php_gtk.dll'); > else > dl('php_gtk.so'); > } > > function delete_Event() > { > return false; > } > > function shutdown() > { > print("Shutting down...\n"); > gtk::main_quit(); > } > > function radiomenu_activate($menuitem, $number) { > echo "radio menu $number is checked\n\n"; > } > > $window = &new GtkWindow(); > $window->connect("destroy", "shutdown"); > > $vbox = &new GtkVBox(); > $window->add($vbox); > > $menu = &new GtkMenu; > > $menuitem1 = &new GtkRadioMenuItem(null, "Menu item 1"); > $menuitem2 = &new GtkRadioMenuItem($menuitem1, "Menu item 2"); > $menuitem1->connect_object('button-release-event', 'radiomenu_activate', > 1); > $menuitem2->connect_object('button-release-event', 'radiomenu_activate', > 2); > > $menu->append($menuitem1); > $menu->append($menuitem2); > > $menubar = &new GtkMenuBar(); > $filemenu_label = &new GtkMenuItem("Menu"); > $filemenu_label->set_submenu($menu); > $menubar->append($filemenu_label); > > $vbox->pack_start($menubar); > > $window->show_all(); > echo $testing; > gtk::main(); > > > ?> > > > -- > PHP-GTK General Mailing List (http://gtk.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.gtk.general (#1442) next »