Tcl/Tk開發(fā)HyperWork目錄樹結(jié)構(gòu)
Tcl/Tk開發(fā)HyperWork目錄樹
HyperWork的二次開發(fā)主要是HyperMesh(前處理)和HyperView(后處理的開發(fā)),用到的語言是Tcl/Tk和大量的API函數(shù),HyperMesh和HyperView的二次開發(fā)形式多樣,在HyperMesh里面比較簡單的是利用宏文件開發(fā)按鈕,然后利用按鈕實現(xiàn)一系列的功能,當然雖然只是簡單的按鈕,卻也可以實現(xiàn)很強大的功能,甚至是整個完整的分析過程。還有一種是利用Process Studio開發(fā)流程樹。
除了自帶的這個開發(fā)工具,Tk本身也可以直接開發(fā)具有目錄樹結(jié)構(gòu)的系統(tǒng),主要用到treeview組件,下面就以一個簡單的例子實現(xiàn)這個功能。
set title "Example"
set alltabs [hm_framework getalltabs]
#創(chuàng)建一個frame
set f [frame .fr -padx 5 -pady 5]
#添加一個tab,名稱為Example
hm_framework addtab "$title" $f 358
#創(chuàng)建treeview組件
#然后根據(jù)需要添加節(jié)點,一個節(jié)點即時一個入口
#可以在該入口進行進程綁定,實現(xiàn)一系列的功能
#每個節(jié)點有一個獨特的id,該id用于識別該節(jié)點,可以隨意命名
ttk::treeview $f.tree
#end 表示節(jié)點的位置,可以用數(shù)字表示,也可以用end表示,也就是在結(jié)尾處
$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"
#利用tag和tag bind進行進程綁定,后面的進程自定義,一旦點擊該節(jié)點即允許該進程
$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
#下面定義幾個進程
#進程均只有一條命令,通過HyperMesh的API函數(shù)彈出對應的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"}
}
腳本完成后放在工作目錄下,運行后即可看到如下,完成了一個目錄樹的程序,并且給其中的三個節(jié)點綁定了進程,分別彈出lines,surfaces和solids面板。

圖1
點擊1-1section后,彈出如下所示的面板:

圖2
同樣的,點擊1-2section彈出的面板如下:

圖3
點擊1-3section彈出的面板如下:

圖4
工程師必備
- 項目客服
- 培訓客服
- 平臺客服
TOP




















