Internal: Changing the colors of Widgets in XWindows
Help Article Update 2
Anonym
The question is commonly asked as to how to change the text and background colors of widgets within IDL. Another version of this question is how to change the gray looking IDE to something more appealing. This is only possible when using the 'X' device on Xwindows.
In Xwindows, the .Xdefaults file can be edited to either change the color for all widgets created by IDL or to change the color for only a particular widget. Once the .Xdefaults file is edited, the RESOURCE_NAME keyword can be used when defining the widgets that are to reflect the alternate colors. The required changes to the .Xdefaults file and the IDL widget definition routines are demonstrated in the examples below.
.Xdefaults file changes:
- To change the color of all widgets, use IDL*background and IDL*foreground settings. For example:
Idl*background: goldenrod
Idl*foreground: deepskyblue4
- To change the color of only a particular widget (in this case, the second widget button in the example code listed below):
Idl*test*item1*background: red
Note on Specifying Color Resources (from IDL online help):
If you wish to specify unique colors for your widgets, it is generally a good idea to use a color name (e.g., "red" or "lightblue") rather than specifying an exact color match with a color string (such as "#b1b122222020"). If IDL is not able to allocate an exact color, the entire operation may fail. Specifying a named color implies "closest color match," an operation which rarely fails.
If you need an exact color match and IDL fails to allocate the color, try modifying the Idl.colors resource in the $IDL_DIR/resource/X11/lib/app-defaults/Idl file.
Helpful UNIX hints:
- Both the IDL code and .Xdefaults code must be altered.
- Once you have made the changes to the .Xdefaults file , you can apply them to your session by typing the following at the UNIX command prompt:
Alternatively, you can start a new console session to apply the color changes.
- To see a listing of colors available, type the following at the UNIX command prompt:
this will return the location of the 'rgb' executable file (e.g., '/usr/openwin/bin/rgb'). If you then do a more on /usr/openwin/lib/rgb.txt, a listing of all of the available colors and their corresponding RGB triplets will be displayed.
Solution:
PRO test_event, ev
END
PRO test
tlb = WIDGET_BASE(RESOURCE_NAME = 'test')
widmenu = WIDGET_BUTTON(tlb, VALUE='Menu', /MENU)
widbut = WIDGET_BUTTON(widmenu, VALUE='Item 1', RESOURCE_NAME='item1')
WIDGET_CONTROL, /REALIZE, tlb
XMANAGER, 'test', tlb
END