很多時候程式啟動時需要花一定的時間進行介面初始化、配置檔案讀取等操作,需要使用者等待,此時如果有個帶漂亮圖片或程式版權資訊的介面在那放著會讓人感覺程式啟動中,馬上就起來了。
從IDL實現上講,無非就是顯示一個不帶選單,不帶標題欄的widget_base,裡面顯示了一張圖片。
下面以一個常規的介面程式為例,注意程式碼中的呼叫部分。
啟動介面
程式主介面
程式碼如下:
;$Id: show_splash_screen.pro 4 2008-01-30 21:13:44Z mpiper $
;+
; Shows an image without a window border on the screen.
;
; @returns widget identifier of top-level base
; @param image {in}{type=2 or 3 dimensional array} an image to
; display
; @keyword true {in}{optional}{type=integer, 0-3}{default=0} order of
; bands, 0 if 8-bit image
; @keyword order {in}{optional}{type=boolean} orientation of image
; @keyword title {in}{optional}{type=string} title of window to
; display in icon
;-
;啟動介面
function show_splash_screen, image, true=true, order=order
compile_opt idl2
on_error, 2
true_local = n_elements(true) eq 0 ? 0 : true
sz = size(image, /structure)
if (true_local eq 0 and sz.n_dimensions ne 2) then $
message, 'TRUE keyword must be set to 1, 2, 3 ' $
+ 'for 24-bit image'
if (true_local ne 0 and sz.n_dimensions ne 3) then $
message, 'TRUE keyword must be set to 0 for 8-bit image'
xind = (true_local ne 1) ? 0 : 1
yind = ((true_local eq 0) or (true_local eq 3)) ? 1 : 2
;螢幕解析度計算
device, get_screen_size=screen_size
;介面偏移量
xoffset = (screen_size[0] - sz.dimensions[xind]) / 2
yoffset = (screen_size[1] - sz.dimensions[yind]) / 2
tlb = widget_base(tlb_frame_attr=4, /column, $
xpad=0, ypad=0, xoffset=xoffset, yoffset=yoffset)
draw = widget_draw(tlb, xsize=sz.dimensions[xind], $
ysize=sz.dimensions[yind])
widget_control, tlb, /realize
widget_control, draw, get_value=win_id
wset, win_id
tv, image, true=true_local, order=keyword_set(order)
return, tlb
end
;啟動介面示例程式碼
;
pro splash_example
;讀取啟動介面要顯示的資料
file = filepath('rose.jpg', SUBDIRECTORY=['examples','data'])
data = read_image(file)
;開始啟動介面***
splash_base = show_splash_screen(data,/true)
;
;建立程式內容,初始化介面、程式、資料等,注意,程式介面的tlb先是要隱藏的
tlb = WIDGET_BASE($
/column, $
map = 0,$ ;隱藏
mbar =result,$
title ='test_button')
;
WIDGET_CONTROL,tlb,/realize
menu = WIDGET_BUTTON(result, value ='檔案(&F)')
fmenu = WIDGET_BUTTON(menu, value ='√開啟')
;menu關鍵字
mMenu = WIDGET_BUTTON(menu, value ='進入',/menu)
tMenu = WIDGET_BUTTON(mMenu, value ='二級',/menu)
;separator關鍵字
eMenu = WIDGET_BUTTON(menu, value ='退出',/SEPARATOR)
ubase = WIDGET_BASE(tlb,/row)
dbase = WIDGET_BASE(tlb,/row,/frame)
;
b = WIDGET_BUTTON(ubase,value = '按鈕',tooltip = '建立的button')
b = WIDGET_BUTTON(ubase,value = '選單', $
tooltip = '選單加對號')
h = WIDGET_BUTTON(ubase,value = BINDGEN(2,40))
;
bit =WIDGET_BUTTON(ubase,value =filepath('colorbar.bmp', SUBDIRECTORY=['resource','bitmaps']),/bitmap)
;單選button'
exbase = WIDGET_BASE(dbase,/EXCLUSIVE,/column,/frame)
eb1 = WIDGET_BUTTON(exbase,value ='對',uName = 'right',/NO_RELEASE )
eb2 = WIDGET_BUTTON(exbase,value ='錯',uName = 'error',/NO_RELEASE )
;選擇第一個按鈕
widget_control,eb1,/SET_BUTTOn
;複合選擇button
nexbase = WIDGET_BASE(dbase,/NONEXCLUSIVE,/column)
eb1 = WIDGET_BUTTON(nexbase,value ='envi')
eb2 = WIDGET_BUTTON(nexbase,value ='idl')
;選擇第一個按鈕
widget_control,eb1,/SET_BUTTOn
;建立顯示元件
wDraw = Widget_Draw(tlb,xsize = 600,ysize = 400)
;等待2秒
wait,2
;銷燬啟動介面***
Widget_control, splash_base,/destroy
;計算介面居中
;螢幕解析度計算
device, get_screen_size=screen_size
geoInfo = widget_info(tlb,/geo)
;介面偏移量
xoffset = (screen_size[0] - geoInfo.xSize) / 2
yoffset = (screen_size[1] - geoInfo.ySize) /2
Widget_Control,tlb, xoffset = xoffset, $
yoffset = yoffset
;顯示程式主介面
widget_control,tlb,/map
;後面其他功能程式碼
;.....
end
知識點總結:
1、介面元件佈局
2、選單、按鈕(單選、複選)按鈕
3、啟動介面