作者:fbysss
关键字:IDL
一、下拉菜单
pro menutest
base = WIDGET_BASE(MBAR=bar)
menu1 = WIDGET_BUTTON(bar, VALUE='MENU1', /MENU)
button1 = WIDGET_BUTTON(menu1, VALUE='ONE')
button2 = WIDGET_BUTTON(menu1, VALUE='TWO')
button3 = WIDGET_BUTTON(menu1, VALUE='THREE')
draw = WIDGET_DRAW(base, XSIZE=100, YSIZE=100)
WIDGET_CONTROL, base, /REALIZE end
子菜单:
pro submenutest
desc = REPLICATE({ flags:0, name:'' }, 6)
desc.flags = [ 1, 0, 1, 0, 2, 2 ]
desc.name = [ 'Operations', 'Predefined', 'Interpolate', $
'Linear', 'Spline', 'Quit' ]
base = WIDGET_BASE()
menu = CW_PDMENU(base, desc)
WIDGET_CONTROL, base, /REALIZE
end
二、右键菜单
IDL中右键菜单的例子,源码为IDL自带,在命令行中输入.EDIT ontext_tlbase_example.pro即可打开。
PRO CBE_FirstEvent, event
COMPILE_OPT hidden
PRINT, ' '
PRINT, 'Selection 1 Pressed'
END; Event handler routine for the "Selection 2" button on the context menu.
PRO CBE_SecondEvent, event
COMPILE_OPT hidden
PRINT, ' '
PRINT, 'Selection 2 Pressed'
END; Event handler routine for the "Done" button on the context menu.
PRO CBE_DoneEvent, event
COMPILE_OPT hidden
PRINT, ' '
PRINT, 'Done Pressed'
; Destroy the top level base.
WIDGET_CONTROL, event.TOP, /DESTROY
END; Event handler routine for the context menu itself. This routine
; is called when the user right-clicks on the base widget.
PRO context_tlbase_example_event, event COMPILE_OPT hidden
; Obtain the widget ID of the context menu base.
contextBase = WIDGET_INFO(event.ID, FIND_BY_UNAME = 'contextMenu') ; Display the context menu and send its events to the
; other event handler routines.
WIDGET_DISPLAYCONTEXTMENU, event.ID, event.X, event.Y, contextBase
END; Main Routine: create the GUI.
PRO context_tlbase_example ; Initialize the top level (background) base. This base
; is configured to generate context events, allowing the user
; to right-click on the base to display a context menu.
topLevelBase = WIDGET_BASE(/COLUMN, XSIZE = 100, YSIZE = 100, /CONTEXT_EVENTS) ; Initialize the base for the context menu.
contextBase = WIDGET_BASE(topLevelBase, /CONTEXT_MENU, UNAME = 'contextMenu') ; Initialize the buttons of the context menu.
firstButton = WIDGET_BUTTON(contextBase, $
VALUE = 'Selection 1', EVENT_PRO = 'CBE_FirstEvent')
secondButton = WIDGET_BUTTON(contextBase, $
VALUE = 'Selection 2', EVENT_PRO = 'CBE_SecondEvent')
doneButton = WIDGET_BUTTON(contextBase, VALUE = 'Done', $
/SEPARATOR, EVENT_PRO = 'CBE_DoneEvent') ; Display the GUI.
WIDGET_CONTROL, topLevelBase, /REALIZE ; Handle the events from the GUI.
XMANAGER, 'context_tlbase_example', topLevelBaseEND
代码比较简单,跟按钮的处理类似,关键注意黑体部分。
三、其他控件创建LABEL:WIDGET_LABELTEXT:WIDGET_TEXT