How to add Greek letters (or other special characters) into an IDL widget button

The IDLDE Editor supports some UTF-8 characters, but the IDL Console and Widgets do not, so you may see differences in the way some characters are displayed in different areas of IDL. Widgets can be especially tricky since they use device (system) fonts. You will be at the mercy of the available fonts on your operating system as to what shows up in your widget. This can be challenging for developers hoping to get a consistent multi-platform experience with their widget application. 
One indirect work-around is to skip system fonts and instead just apply a bitmap texture to the widget button. The below approach will do the trick, though it's not ideal. The main drawback is slowdown. On MacOS at least, initializing new graphics the first time will have a ~5 second penalty. On Windows and Linux, it will be almost instantaneous. Another option would be to include the generated bitmap files in your application itself, and thus not have to generate them on the fly. However, you could run into a situation where the background/text colors don't match the rest of the widget on a specific platform or specific machine.
Find more information about IDL function graphics HERE
Here is some IDL PRO code that demonstrates how to add a Greek letter to a widget button: 

;Make new graphics version of bitmap

;Draw a hidden widget to retrieve the system default colors

Base = Widget_Base(/Row)

Widget_Control, Base, Map = 0

Colors = Widget_Info(Base, /System_Colors)

ForegroundColor = N_elements(Foreground_Color) ne 3 ? $

  Colors.Button_Text : $


BackgroundColor = N_elements(Background_Color) ne 3 ? $

  Colors.Face_3D : $


      ;Draw a hidden graphics window with the needed character

w=window(/buffer, dimensions=[200,200],background_color=BackgroundColor)



;Draw the real widget and include a copy of the hidden graphics window as an image for the button

t = widget_base(/row)

b2=widget_button(t,value='S',font='symbol') ;This method works on Windows, but may fail on other platforms

b3=widget_button(t,value=transpose(w.CopyWindow(border=3),[1,2,0])) ;This is the work-around which is cross-platform








Created by BC-US 12/15/2022, Reviewed by JU 12/27/2022

Please login or register to post comments.


Sign up to receive the latest news, events, technologies and special offers.