Tcl/Tk开发HyperWork目录树结构

Tcl/Tk开发HyperWork目录树

HyperWork的二次开发主要是HyperMesh(前处理)和HyperView(后处理的开发),用到的语言是Tcl/Tk和大量的API函数,HyperMeshHyperView的二次开发形式多样,在HyperMesh里面比较简单的是利用宏文件开发按钮,然后利用按钮实现一系列的功能,当然虽然只是简单的按钮,却也可以实现很强大的功能,甚至是整个完整的分析过程。还有一种是利用Process Studio开发流程树。

除了自带的这个开发工具,Tk本身也可以直接开发具有目录树结构的系统,主要用到treeview组件,下面就以一个简单的例子实现这个功能。

set title "Example"

set alltabs [hm_framework getalltabs]

 

#创建一个frame

set f [frame .fr -padx 5 -pady 5]

#添加一个tab,名称为Example

hm_framework addtab "$title" $f 358

 

#创建treeview组件

#然后根据需要添加节点,一个节点即时一个入口

#可以在该入口进行进程绑定,实现一系列的功能

#每个节点有一个独特的id,该id用于识别该节点,可以随意命名

ttk::treeview $f.tree

#end 表示节点的位置,可以用数字表示,也可以用end表示,也就是在结尾处

$f.tree insert {} end -id root -text "contents"

$f.tree insert root end -id node1 -text "chapter 1"

$f.tree insert node1 end -id node11 -text "1-1section"

$f.tree insert node1 end -id node12 -text "1-2section"

$f.tree insert node1 end -id node13 -text "1-3section"

 

$f.tree insert root end -id node2 -text "chapter 2"

$f.tree insert node2 end -id node21 -text "2-1section"

$f.tree insert node2 end -id node22 -text "2-2section"

$f.tree insert node2 end -id node23 -text "2-3section"

 

$f.tree insert root end -id node3 -text "chapter 3"

$f.tree insert node3 end -id node31 -text "3-1section"

$f.tree insert node3 end -id node32 -text "3-2section"

$f.tree insert node3 end -id node33 -text "3-3section"

 

$f.tree insert root end -id node4 -text "Summary"

 

#利用tagtag bind进行进程绑定,后面的进程自定义,一旦点击该节点即允许该进程

$f.tree item node11 -tags {"1-1section"}

$f.tree tag bind "1-1section" <ButtonPress-1> {Proc1_1}

$f.tree item node12 -tags {"1-2section"}

$f.tree tag bind "1-2section" <ButtonPress-1> {Proc1_2}

$f.tree item node13 -tags {"1-3section"}

$f.tree tag bind "1-3section" <ButtonPress-1> {Proc1_3}

 

pack $f.tree -side left -anchor w -fill both

pack $f

 

#下面定义几个进程

#进程均只有一条命令,通过HyperMeshAPI函数弹出对应的panel

proc Proc1_1 {} {

       hm_setpanelproc {hm_callpanel "lines"}

}

 

proc Proc1_2 {} {

       hm_setpanelproc {hm_callpanel "surfaces"}

}

 

proc Proc1_3 {} {

       hm_setpanelproc {hm_callpanel "solids"}

}

 

脚本完成后放在工作目录下,运行后即可看到如下,完成了一个目录树的程序,并且给其中的三个节点绑定了进程,分别弹出lines,surfacessolids面板。

1.png


1

点击1-1section后,弹出如下所示的面板:

2.png

2

同样的,点击1-2section弹出的面板如下:

3.png

3

点击1-3section弹出的面板如下:

4.png

4

 

登录后免费查看全文
立即登录
App下载
技术邻APP
工程师必备
  • 项目客服
  • 培训客服
  • 平台客服

TOP

15
2
6