Fanning Software Consulting

Default Widget Font

QUESTION: I understand how to change the default widget font. For example, if I want the buttons on my widget program to show up in Helvetica, I can do this:

    IDL> Widget_Control, DEFAULT_FONT='Helvetica' 

But, what I don't know, is how to set the default font back to the original font if I don't care for this selection. Is there some way to find out what the default font is currently set to before I change it, so I can change it back?

ANSWER: Yes, you can use Widget_Info for this purpose, in a fashion like this:

    thefont = Widget_Info(buttonWidgetID, /FONTNAME) 

Typically, what you do is write a little program that creates a button widget. If you use Widget_Info to check the font name of this button widget before it is realized, it will return the name of the default font. If you check the font name after the button widget is realized, it will return the name of the current font.

Here is a small program that performs this function for you.

     FUNCTION WidgetFont, DEFAULT=default     
       ; Build a small widget to determine the current 
       ; and default widget fonts.        base = Widget_Base(MAP=0)
       button = Widget_Button(base, Value='TEST')        
       ; Checking before realization gives default font.
       defaultFont = Widget_Info(button, /FONTNAME)        
       ; Checking after realization gives current font.
       Widget_Control, base, /REALIZE
       currentFont = Widget_Info(button, /FONTNAME)                ; Clean up.
       Widget_Control, base, /DESTROY             IF Keyword_Set(default) THEN $
            RETURN, defaultFont ELSE $             RETURN, currentFont         

And here is the record of an IDL session on a Windows machine after the widget font has been set to Helvetica using Widget_Control and the DEFAULT_FONT keyword.

    IDL> Print, Widgetfont()       HELVETICA
   IDL> Print, Widgetfont(/DEFAULT)       MS Shell Dlg*-11 

Naturally, font names on other machines are set differently. To determine what font names are avaialable on your machine, you can type something like this at the IDL command line.

    IDL> Device, GET_FONTNAMES=fontNames, SET_FONT='*' 

On my LINUX machine, the default font name is -Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1.

Version of IDL used to prepare this article: IDL 7.0.3.

Web Coyote's Guide to IDL Programming