IDL学习笔记(5)-IDL中菜单的创建方法

作者:fbysss
msn:jameslastchina@hotmail.com 
blog:blog.csdn.net/fbysss
声明:本文由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', topLevelBase

END
代码比较简单,跟按钮的处理类似,关键注意黑体部分。
三、其他控件创建
LABEL:WIDGET_LABEL
TEXT:WIDGET_TEXT

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值