Re: Can I make entries in CW_PDMENU insensitive? [message #14380] |
Thu, 25 February 1999 00:00 |
Nigel Wade
Messages: 286 Registered: March 1998
|
Senior Member |
|
|
Steffen Luesse wrote:
>
> Dear all,
>
> I am using IDL 5.2 on solaris 2.6. I want to use the CW_PDMENU routine
> to create a pull-down menu in my widget programs. In principle,
> everything works well. However, I am wondering if it is possible to make
> some menu entries insensitive like I can do it with buttons or sliders
> when they should not be used. I did not find any information about my
> problem in the IDL documentation and would appreciate if anybody could
> give me a hint.
>
> Thanks in advance,
>
> Steffen
Yes, they can be made insensitive just like any other widget. The trick
is to know the widget id to make insensitive.
There is a keyword IDS to the CW_PDMENU routine which will return the
ids of every menu button created. They are created in the order they are
specified in the menu description. All you then have to do is match the
id in the returned ids to the menu item you want to make insensitive.
Of course, if the menu description changes you need to alter the
indexing
into the returned ids to get the same button. A bug waiting to happen...
E.g given the following description :
menu_labels = [ {CW_PDMENU_S, 1, 'File'}, $
{CW_PDMENU_S, 0, 'New data...'}, $
{CW_PDMENU_S, 0, 'Data def...'}, $
{CW_PDMENU_S, 0, 'Properties...'}, $
{CW_PDMENU_S, 2, 'Exit'}, $
{CW_PDMENU_S, 1, 'Windows'}, $
{CW_PDMENU_S, 0, 'Load...'}, $
{CW_PDMENU_S, 0, 'Save...'}, $
{CW_PDMENU_S, 2, 'Edit...'}, $
{CW_PDMENU_S, 1, 'Find'}, $
{CW_PDMENU_S, 2, 'Time...'}, $
{CW_PDMENU_S, 1, 'Print'}, $
{CW_PDMENU_S, 1, 'File'}, $
{CW_PDMENU_S, 0, 'Laser...'}, $
{CW_PDMENU_S, 2, 'Colour...'}, $
{CW_PDMENU_S, 1, 'Device'},$
{CW_PDMENU_S, 0, 'Laser'}, $
{CW_PDMENU_S, 2, 'Colour'} ]
menu = CW_PDMENU(parent, menu_labels, IDS=menu_ids)
the variable menu_ids contains the widget ids of each menu item.
I can de-sensitize the Windows menu by :
WIDGET_CONTROL, menu_ids(5), SENSITIVE=0
There are ways to reduce the potential for getting the wrong widget id.
But I'll leave that as an exercise for the student... ;-).
--
-----------------------------------------------------------
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523568, Fax : +44 (0)116 2523555
|
|
|
Re: Can I make entries in CW_PDMENU insensitive? [message #14385 is a reply to message #14380] |
Wed, 24 February 1999 00:00  |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
Steffen Luesse wrote:
>
> Dear all,
>
> I am using IDL 5.2 on solaris 2.6. I want to use the CW_PDMENU routine
> to create a pull-down menu in my widget programs. In principle,
> everything works well. However, I am wondering if it is possible to make
> some menu entries insensitive like I can do it with buttons or sliders
> when they should not be used. I did not find any information about my
> problem in the IDL documentation and would appreciate if anybody could
> give me a hint.
Steffen -
I believe you can just use the IDS=wids keyword to return a lonarr of
the widget IDs, and then use WIDGET_CONTROL, wids[i], sensitive=0
Dave
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|
Re: Can I make entries in CW_PDMENU insensitive? [message #14391 is a reply to message #14385] |
Wed, 24 February 1999 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Liam Gumley (Liam.Gumley@ssec.wisc.edu) is good enough to
expand on my rather flippant comments with this:
> The following example expands a little on the excellent tip by David
> Fanning. Here I've tried to replicate part of the menu bar of a well
> known word processor. I think it demonstrates the concepts that are of
> interest in this case.
I would just add the XSIZE keyword to the first line of
this code for those of you who want to see this on a Windows
machine. :-)
base = widget_base( title = 'Menu Test', mbar=menu_bar, XSIZE=200 )
I'm not a fan of XSIZE keywords at all, but Windows will make a
very *tiny* window in the upper left corner of your display if
the top-level base doesn't have a size or (at least) something
inside it.
> Does anyone know how to include a separator line between menu items,
> e.g. between 'Close' and 'Send To'?
You are not going to believe this, but you could add a SEPARATOR
keyword to the "Send To" button. :-)
file_but4 = widget_button( file_menu, value='Send To', /menu, $
/Separator)
Ya just gotta love IDL sometimes!
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: Can I make entries in CW_PDMENU insensitive? [message #14392 is a reply to message #14385] |
Wed, 24 February 1999 00:00  |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
Steffen Luesse wrote:
> I am using IDL 5.2 on solaris 2.6. I want to use the CW_PDMENU routine
> to create a pull-down menu in my widget programs. In principle,
> everything works well. However, I am wondering if it is possible to make
> some menu entries insensitive like I can do it with buttons or sliders
> when they should not be used. I did not find any information about my
> problem in the IDL documentation and would appreciate if anybody could
> give me a hint.
The following example expands a little on the excellent tip by David
Fanning. Here I've tried to replicate part of the menu bar of a well
known word processor. I think it demonstrates the concepts that are of
interest in this case.
Does anyone know how to include a separator line between menu items,
e.g. between 'Close' and 'Send To'?
Cheers,
Liam.
;---cut here---
PRO MENU_TEST
;- Create top level base with menu bar
base = widget_base( title = 'Menu Test', mbar=menu_bar )
;- Create File menu
file_menu = widget_button( menu_bar, value='File', /menu )
file_but1 = widget_button( file_menu, value='New... Ctrl+N' )
file_but2 = widget_button( file_menu, value='Open... Ctrl+O' )
file_but3 = widget_button( file_menu, value='Close' )
file_but4 = widget_button( file_menu, value='Send To', /menu )
send_but1 = widget_button( file_but4, value='Mail Recipient...' )
send_but2 = widget_button( file_but4, value='Routing Recipient...' )
send_but3 = widget_button( file_but4, value='Exchange Folder...' )
send_but4 = widget_button( file_but4, value='Fax Recipient...' )
file_but5 = widget_button( file_menu, value='Exit' )
;- Create Edit menu
edit_menu = widget_button( menu_bar, value='Edit', /menu )
edit_but1 = widget_button( edit_menu, value='Cut Ctrl+X' )
edit_but2 = widget_button( edit_menu, value='Copy Ctrl+C' )
edit_but3 = widget_button( edit_menu, value='Paste Ctrl+V' )
edit_but4 = widget_button( edit_menu, value='Paste Special...' )
;- Make Cut and Copy items insensitive
widget_control, edit_but1, sensitive=0
widget_control, edit_but2, sensitive=0
;- Realize widgets
widget_control, base, /realize
END
;---cut here---
---
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
|
|
|
Re: Can I make entries in CW_PDMENU insensitive? [message #14396 is a reply to message #14385] |
Wed, 24 February 1999 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Steffen Luesse (luesse@rad.uni-kiel.de) writes:
> I am using IDL 5.2 on solaris 2.6. I want to use the CW_PDMENU routine
> to create a pull-down menu in my widget programs. In principle,
> everything works well. However, I am wondering if it is possible to make
> some menu entries insensitive like I can do it with buttons or sliders
> when they should not be used. I did not find any information about my
> problem in the IDL documentation and would appreciate if anybody could
> give me a hint.
CW_PDMENU sounds like a good idea until you actually start
writing a widget program. Then you find you want to make
a button insensitive, or you want to assign a special event
handler to a button, or you want to put something in the
user value of a button, or whatever it is, and CW_PDMENU
doesn't let you do it.
At this point you can either hack the CW_PDMENU code (ugh!), or
you can do what I do and use the trivially easy solution of
setting the MENU keyword on button widgets to create your
own pull-down menus.
With the newfangled cut and paste capability found on most
modern computers, it's even easy to build a whole stack of
buttons quickly and easily. :-)
lev1 = Widget_Button(tlb, Value='Pull Down Menu', /Menu)
button = Widget_Button(lev1, Value='Level 1a')
button = Widget_Button(lev1, Value='Level 1b')
lev2 = Widget_Button(menuID, Value='Level 1c', /Menu)
button = Widget_Button(lev2, Value='Level 2a')
button = Widget_Button(lev2, Value='Level 2b')
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|