INTERNAL/REVIEW: How to Use Shortcut or Context Menu Widgets
Anonym
[Needs to be reviewed for Compliance and IP issues (i.e. .pro file included)]
This Help Article provides a simple routine that demonstrates using an IDL widget shortcut menu (also called a context menu).
Discussion
See the example code below for a simple demonstration of how to use the IDL widget shortcut menus (also called context menus, added in IDL 5.5). Note: This code has been tested and works with IDL 5.5 and IDL 5.6.
Download 'test_context_menu.pro'
pro test_context_menu_event, event
; Getting the id of the context base
contextbase = widget_info(event.id, $
find_by_uname = 'contextmenu')
; Displaying the context base
widget_displaycontextmenu, event.id, event.x, $
event.y, contextbase
end
pro button_event, event
; Button events.
widget_control, event.id, get_uvalue = uval
case uval of
'b1': print, 'You pressed Button #1'
'b2': print, 'You pressed Button #2'
else:
endcase
end
pro test_context_menu
tlb = widget_base(/column, xsize = 100, $
ysize = 50, /context_events)
; Building the context menu.
contextbase = widget_base(tlb, /context_menu, $
uname = 'contextmenu')
b0 = widget_button(contextbase, $
value = 'TEST', event_pro = 'button_event', /menu)
b1 = widget_button(b0, value = 'Button #1', uvalue = 'b1')
b2 = widget_button(b0, value = 'Button #2', uvalue = 'b2')
widget_control, tlb, /realize
xmanager, 'test_context_menu', tlb
end