比如最早都是些基本语法相关的问题,格式输出、变量的使用、数组函数、混编调用等问题,现在已经开始有框架类问题了。如何构建一个大的程序,如何在各个组件中进行组件的调度或事件的响应。这个特别是对没有编程经验的人很难用一句话两句话说明白的,同时限于工作原因,业余还得忙论坛、QQ群和 IDL教程等,没太多的时间思考,期待下CG、HuHu、QQZ有空能整点这方面的文章
。举一个简单的例子吧,在IDL自带的例子上修改的,实现的是tree组件控制对象属性,双击那个叶子可以修改多边形颜色。
先看效果图:

再瞅代码
; $Id: //depot/idl/releases/IDL_80/idldir/examples/doc/widgets/tree_widget_example.pro#1 $
; Copyright (c) 2005-2010, ITT Visual Information Solutions. All
; rights reserved.
;
; This program is used as an example in the "Widget Application Techniques"
; chapter of the _Building IDL Applications_ manual.
;
; This example creates a simple tree widget. Clicking on a leaf node
; toggles the text of the display to read either 'On' or 'Off'. This
; is not particularly useful, but serves as an example of how you
; might accomplish something more complicated.
; Event handler routine.
; Modified By DYQ ,2010-8-25
; Add the control tree of polygon Objects
;
PRO tree_widget_example_event, ev
COMPILE_OPT hidden
; We use widget user values to determine what action to take.
; First retrieve the user value (if any) from the widget that
; generated the event.
WIDGET_CONTROL, ev.ID, GET_UVALUE=uName
; If the widget that generated the event has a user value, check
; its value and take the appropriate action.
IF (N_ELEMENTS(uName) NE 0) THEN BEGIN
;Modified By DYQ
;响应鼠标事件
;如果uName是指针的话就修改颜色
IF Size(uName,/type) eq 10 then begin
IF (ev.CLICKS EQ 2) THEN TWE_ToggleObject, ev.ID
endif ELSe begin
IF (uName EQ 'LEAF') THEN BEGIN
; Make sure the value does not change when the leaf node
; is selected with a single click.
IF (ev.CLICKS EQ 2) THEN TWE_ToggleValue, ev.ID
ENDIF
IF (uName EQ 'DONE') THEN WIDGET_CONTROL, ev.TOP, /DESTROY
endElse
ENDIF
END
;修改叶子节点对象的属性
pro TWE_ToggleObject, widID
;先修改叶子标识
WIDGET_CONTROL, widID, GET_VALUE=curVal
full_string = STRSPLIT(curVal, ':', /EXTRACT)
;根据是否开关来修改对象颜色
Widget_Control,widID,get_UValue = pState
if (full_string[1] EQ ' On')then begin
(*pState).oPoly->SetProperty,color = [0,0,0]
endif ELSE begin
(*pState).oPoly->SetProperty,color = [255,0,0]
endelse
(*pState).oWin->Draw
full_string[1] = (full_string[1] EQ ' Off') ? ': On' : ': Off'
; Reset the value of the leaf node's text.
WIDGET_CONTROL, widID, SET_VALUE=STRJOIN(full_string)
END
; Routine to change the value of a leaf node's text.
PRO TWE_ToggleValue, widID
COMPILE_OPT hidden
; Get the current value.
WIDGET_CONTROL, widID, GET_VALUE=curVal
; Split the string at the colon character.
full_string = STRSPLIT(curVal, ':', /EXTRACT)
; Check the value of the text after the colon, and toggle
; to the new value.
full_string[1] = (full_string[1] EQ ' Off') ? ': On' : ': Off'
; Reset the value of the leaf node's text.
WIDGET_CONTROL, widID, SET_VALUE=STRJOIN(full_string)
END
; Widget creation routine.
PRO tree_widget_example
; Start with a base widget.
wTLB = WIDGET_BASE(/COLUMN, TITLE='Tree Example')
; The first tree widget has the top-level base as its parent.
; The visible tree widget branches and leaves will all be
; descendants of this tree widget.
wBase1 = Widget_Base(wtlb)
wBase2 = Widget_Base(wtlb)
wTree = WIDGET_TREE(wBase1,xsize =300)
; Place a folder at the root level of the visible tree.
wtRoot = WIDGET_TREE(wTree, VALUE='Root', /FOLDER, /EXPANDED)
; Create leaves and branches. Note that we set the user value of
; every leaf node (tree widgets that do not have the FOLDER keyword
; set) equal to 'LEAF'. We use this in the event handler to determine
; whether or not to change the text value.
wtLeaf11 = WIDGET_TREE(wtRoot, VALUE='Setting 1-1: Off', $
UVALUE='LEAF')
wtBranch12 = WIDGET_TREE(wtRoot, VALUE='Branch 1-2', $
/FOLDER, /EXPANDED)
wtLeaf121 = WIDGET_TREE(wtBranch12, VALUE='Setting 1-2-1: Off', $
UVALUE='LEAF')
wtLeaf122 = WIDGET_TREE(wtBranch12, VALUE='Setting 1-2-2: Off', $
UVALUE='LEAF')
wtLeaf13 = WIDGET_TREE(wtRoot, VALUE='Setting 1-3: Off', $
UVALUE='LEAF')
wtLeaf14 = WIDGET_TREE(wtRoot, VALUE='Setting 1-4: Off', $
UVALUE='LEAF')
;
;Add By DYQ
;建立显示对象
wDraw = Widget_Draw(wBase2,xSize =300,ySize =200,Graphics_level =2)
; Create a 'Done' button, setting its user value for use in the
; event handler.
wDone = WIDGET_BUTTON(wTLB, VALUE="Done", UVALUE='DONE')
; Realize the widgets and run XMANAGER to manage them.
WIDGET_CONTROL, wTLB, /REALIZE
;建立对象体系结构
Widget_Control,wDraw,get_value = oWin
oView = Obj_New('IDLgrView',viewPlane_Rect = [-1,-1,3,3],color = [255,255,255])
oModel = Obj_New('IDLgrModel')
oPoly = Obj_New('IDLgrPolygon',[[0,0],[1,0],[1,1],[0,1]],color = [0,0,0])
oView->Add,oModel
oModel->Add,oPoly
oWin->SetProperty, Graphics_tree = oView
;绘制
oWin->Draw
;创建叶子节点,控制对象颜色修改
wtLeaf14 = WIDGET_TREE(wtRoot, VALUE='多边形红 1-5: Off',uvalue = Ptr_New({oWin:oWin,oPoly:oPoly}))
XMANAGER, 'tree_widget_example', wTLB, /NO_BLOCK
END
0 件のコメント:
コメントを投稿