Re: GtkMenu
| From: | Steph | Date: | Sat, 29 Dec 2001 02:40:27 +0000 |
| Subject: | Re: GtkMenu | ||
| References: | 1 2 3 4 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-943@lists.php.net to get a copy of this message | ||
oo-er, proper stuff :)
Where's that history? or is my isp playing up again?
Alan, GtkMenuFactory doesn't exist. You mean GtkItemFactory.
There are a lot of ways to approach the problem. Classes is a good one, cos in a pile-up like this
seems to be you'd need a ton of associative arrays to get it all into one neat callback
function.
----- Original Message -----
From: "Alan Knowles" <alan@akbkhome.com>
To: "Anson Rinesmith" <anson@lddcorp.com>; "php-gtk-general"
<php-gtk-general@lists.php.net>
Sent: Saturday, December 29, 2001 12:44 AM
Subject: Re: [PHP-GTK] GtkMenu
> Anson Rinesmith wrote:
>
> all this is done inside a php class
> $this is a reference to the instance of the class.
> $this->document->curnode->$l
> document and curnodes are class instances with class instances inside it.
> $l is expolated = to something like "name" -> which is a variable name
> in the class;
>
> the array(&$this,'methodname');
> ensures that the callback is sent to the current instance of the class rather than a copy.
>
> The class stuff is not really relivant to doing the gtkmenu stuff, but
> writing applications in classes is a good idea (TM) :)
>
> a simpler version would be something like.
>
> $menuitem = &new GtkMenuItem($title);
> $menuitem->connect('activate', 'myfunction', 'xxx selected');
>
> obviously the idea of the code I use is that it uses an associative array to build the menu
>
> $menu = array (
> "Title" => "value",
> "Title2" => "value2"
> );
>
> foreach ($menu as $title=>$value) {
> $menuitem = &new GtkMenuItem($title);
> $menuitem->connect('activate', 'myfunction', $value);
> $menuoption->append($menuitem);
> }
>
> function myfunction($widget,$value) {
> global $menu_current_setting
> $menu_current_setting=$value;
> }
>
> You could also do something similar with GtkMenuFactory I think, havent really looked at that
> though.
>
>
> >Okay, you just blew my mind with that, I've never been to familiar with the
> >$this idea.
> >Would you mind explaining where the $key and $node->id come from?
> >This might be getting way over my head.
> >All I really want, is the $title, is there a simplier way?
> >
>
> $key is a bit like the menu_current_setting in the example above -
> except it uses variable expolation again.
> $fred = "hello there";
> $a = "fred";
> echo $$a; - prints "hello there";
>
> on classes
> $object->fred = "hello there";
> $a="fred";
> echo $object->$a; prints "hello there";
>
> $node->id is related to another part of the application I copied this
> from ($node is an object)
> The code is generic for this dialog. and about 10 others
>
> http://www.akbkhome.com/attachment/e734103d46be96da3213acd005cf4bf1/e879dc5710deb3067ca4977b1ef2f3ce/midgard_host_edit.png
>
> >
> >>the key trick is connect each menu item to an event, and use the last
> >>paramter (extra) to send what was selected.
> >>- this way you can also send invisible information
> >>
> >> $menuitem = &new GtkMenuItem($title);
> >> $menuitem->connect('activate',
> >> array(&$this,'pulldown_select'),
> >>
> >array($key,$node->id));
> >
> >> // and the recieving function just stores the current value somewhere..
> >> function pulldown_select($widget,$b) {
> >> $l = $b[0];
> >> $this->document->curnode->$l = $b[1];
> >> }
> >>
> >>
> >>regards
> >>alan
> >>
> >>Anson Rinesmith wrote:
> >>
> >>>Using the same code
> >>> $omenu_action = &new GtkOptionMenu();
> >>> $omenu_action->set_usize(50,25);
> >>> $menu_action = &new GtkMenu();
> >>> $action_i1 = &new GtkMenuItem("Allow");
> >>> $action_i2 = &new GtkMenuItem("Deny");
> >>> $menu_action->append($action_i1);
> >>> $menu_action->append($action_i2);
> >>> $omenu_action->set_menu($menu_action);
> >>>
> >>> $box1_2->pack_start($omenu_action,false);
> >>>
> >>>If I pass $menu_action to a function, how do I get the string "Allow" or
> >>>
> >"Deny" back?
> >
> >>>I use get_active() I just get back the MenuItem.
> >>>
> >>
> >>
> >>
> >
>
>
>
>
> --
> PHP-GTK General Mailing List (http://gtk.php.net/)
> To unsubscribe, e-mail: php-gtk-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-gtk-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>