IDL彈出介面事件響應示例程式,介面如下圖:
知識點:
1、介面框架結構與編寫實現;
2、介面事件響應與影像顯示;
3、彈出介面構建與事件響應;
4、JPEG檔案選擇、讀取與顯示;
原始碼:
PRO SELECTFILE_EVENT,ev
WIDGET_CONTROL,ev.TOP,get_UValue = pState
CASE WIDGET_INFO(ev.ID,/uname) OF
'select': BEGIN
;
file = DIALOG_PICKFILE(filter ='*.jpg')
IF QUERY_JPEG(file) EQ 1 THEN BEGIN
;
(*pState).RESULT = file
WIDGET_CONTROL,(*pState).WTEXT, set_Value = file
ENDIF
END
'ok' : WIDGET_CONTROL,ev.TOP,/destroy
ELSE:
ENDCASE
END
FUNCTION SELECTFILE
;
tlb = WIDGET_BASE(title ='選擇檔案',/row)
wText = WIDGET_TEXT(tlb,xsize =20)
wButton = WIDGET_BUTTON(tlb,value = '選擇JPG影像',uname ='select')
wButton = WIDGET_BUTTON(tlb,value = '確定',uname ='ok')
;
WIDGET_CONTROL,tlb,/realize
pState = PTR_NEW({wText:WTEXT,result:''})
WIDGET_CONTROL,tlb,set_UValue = pState
XMANAGER,'selectfile',tlb;,/no_block
r = (*pState).RESULT
PTR_FREE,pState
RETURN,r
END
PRO WTLB_EVENT,ev
WIDGET_CONTROL,ev.TOP,get_uvalue= pstate
CASE WIDGET_INFO(ev.ID,/uname) OF
'open': BEGIN
selectedFile = SELECTFILE()
IF QUERY_JPEG(selectedFile) EQ 1 THEN BEGIN
READ_JPEG,selectedFile,data,/true
TV,data,/true
ENDIF
END
ELSE:
ENDCASE
END
PRO DISPLAYIMAGE
; wbase -8
; / \ \
; menu toolbar draw
; open-11 open-13 -7
; ENVI,/restore_base_save_files
; ENVI_BATCH_INIT
;
wtlb = WIDGET_BASE(title='jpeg讀取顯示',$
mbar = wMenuBase,$
/column)
wFile = WIDGET_BUTTON(wMenuBase,value='檔案',/menu)
wOpen = WIDGET_BUTTON(wFile,value = '開啟',uname='open',$
EVENT_PRO = 'wMenuOpen')
;
wtool = WIDGET_BASE(wtlb,/frame)
wtoolOpen = WIDGET_BUTTON(wtool,value= '開啟',uname='open')
;
wDraw = WIDGET_DRAW(wtlb,xsize = 600,ysize =400)
;
WIDGET_CONTROL,wtlb,/real,set_uvalue={wDraw:WDRAW}
XMANAGER, 'wtlb', wtlb,/no_block
END