分享

idl显示启动界面

 昵称14236700 2013-10-15

IDL显示启动界面

     很多时候程序启动时需要花一定的时间进行界面初始化、配置文件读取等操作,需要用户等待,此时如果有个带漂亮图片或程序版权信息的界面在那放着会让人感觉程序启动中,马上就起来了。
     从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、启动界面;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多