Home > Archive > Ruby > August 2005 > Tk menu
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Bart Masschelein 2005-08-29, 7:02 pm |
| Hello there,
I started experimenting with Tk, out of the box, with the basic
examples, and I loved the way to implement menus:
menu_spec_1 =
[ [ ['main 1', 0],
['1 sub', 0]
],
[ ['main 2', 0],
['2 sub', 0]
]
]
and then calling
TkMenubar.new(root, menu_spec_2, 'tearoff'=>false).pack('fill'=>'x',
'side'=>'top')
However, I wanted to have a submenu under a menu item, so I tried
menu_spec_2 =
[ [ ['main 1', 0],
['1 sub', 0]
],
[ ['main 2', 0],
[ ['2 sub', 0],
['2 sub sub', 0]
]
]
]
This doesn't work, Ruby gives me an error. So apparently this is not
supported. Has sbdy already extended the menuspec.rb file to support
this behaviour, or would this straightforward to do, or even feasible
(I'm just starting with Ruby)?
I want to avoid the 'hassle' of creating each menu item itself, and then
structuring them. Been there, done that, in other languages.
happy Rubying,
Bart
| |
| Joe Van Dyk 2005-08-29, 7:02 pm |
| On 8/29/05, Bart Masschelein <bart.masschelein@skynet.be> wrote:
> Hello there,
>=20
> I started experimenting with Tk, out of the box, with the basic
> examples, and I loved the way to implement menus:
>=20
> menu_spec_1 =3D
> [ [ ['main 1', 0],
> ['1 sub', 0]
> ],
> [ ['main 2', 0],
> ['2 sub', 0]
> ]
> ]
>=20
> and then calling
>=20
> TkMenubar.new(root, menu_spec_2, 'tearoff'=3D>false).pack('fill'=3D>'x',
> 'side'=3D>'top')
>=20
> However, I wanted to have a submenu under a menu item, so I tried
>=20
> menu_spec_2 =3D
> [ [ ['main 1', 0],
> ['1 sub', 0]
> ],
> [ ['main 2', 0],
> [ ['2 sub', 0],
> ['2 sub sub', 0]
> ]
> ]
> ]
>=20
> This doesn't work, Ruby gives me an error. So apparently this is not
> supported. Has sbdy already extended the menuspec.rb file to support
> this behaviour, or would this straightforward to do, or even feasible
> (I'm just starting with Ruby)?
>=20
> I want to avoid the 'hassle' of creating each menu item itself, and then
> structuring them. Been there, done that, in other languages.
Yeah, the menu spec thing is sorta confusing for submenus. From the
TkMenuSpec docs (found at http://www.ruby-doc.org):
The format of the menu_spec is:
[ menu_info, menu_info, ... ]
And the format of the menu_info is:
[
[text, underline, configs], # menu button/entry (*1)
[label, command, underline, accelerator, configs], # command entry
[label, TkVar_obj, underline, accelerator, configs], # checkbutton ent=
ry
[label, [TkVar_obj, value],
underline, accelerator, configs], # radiobutton ent=
ry
[label, [[...menu_info...], [...menu_info...], ...],
underline, accelerator, configs], # cascade entry
'---', # separator
...
]
underline, accelerator, and configs are optional pearameters. Hashes
are OK instead of Arrays. Then the entry type ('command',
'checkbutton', 'radiobutton' or 'cascade') is given by 'type' key
(e.g. :type=3D>'cascade'). When type is 'cascade', an array of menu_info
is acceptable for 'menu' key (then, create sub-menu).
| |
| Bart Masschelein 2005-08-29, 7:02 pm |
| I love this list!! The response time is almost like asking your
next-cubicle colleague! Anyway, if sbdy is still dazzled by how to do
submenu-ing, here is an example, using the previous reply:
menu_spec_2 =
[ [ ['main 1', 0],
['1 sub', 0]
],
[ ['main 2', 0],
['2 sub 1', [ ['2 sub sub 1', 0], ['2 sub sub 2', 0] ] ],
['2 sub 2', 0]
]
]
Thanks!
gr.b.
Joe Van Dyk wrote:
>On 8/29/05, Bart Masschelein <bart.masschelein@skynet.be> wrote:
>
>
>
>Yeah, the menu spec thing is sorta confusing for submenus. From the
>TkMenuSpec docs (found at http://www.ruby-doc.org):
>
>The format of the menu_spec is:
>
> [ menu_info, menu_info, ... ]
>
>And the format of the menu_info is:
>
> [
> [text, underline, configs], # menu button/entry (*1)
> [label, command, underline, accelerator, configs], # command entry
> [label, TkVar_obj, underline, accelerator, configs], # checkbutton entry
> [label, [TkVar_obj, value],
> underline, accelerator, configs], # radiobutton entry
> [label, [[...menu_info...], [...menu_info...], ...],
> underline, accelerator, configs], # cascade entry
> '---', # separator
> ...
> ]
>
>underline, accelerator, and configs are optional pearameters. Hashes
>are OK instead of Arrays. Then the entry type ('command',
>'checkbutton', 'radiobutton' or 'cascade') is given by 'type' key
>(e.g. :type=>'cascade'). When type is 'cascade', an array of menu_info
>is acceptable for 'menu' key (then, create sub-menu).
>
>
>
>
>
>
>
| |
| Berger, Daniel 2005-08-29, 7:02 pm |
| > -----Original Message-----
> From: Bart Masschelein [mailto:bart.masschelein@skynet.be]=20
> Sent: Monday, August 29, 2005 1:01 PM
> To: ruby-talk ML
> Subject: Re: Tk menu
>=20
>=20
> I love this list!! The response time is almost like asking your=20
> next-cubicle colleague!
Sometimes it works out that way. It can work even better on IRC, if the
right person is on and willing to help you. :)
Regards,
Dan
|
|
|
|
|