HyperMesh二次开发技术—插件界面开发(一)

1.代码实例

#新建过程subWindow

proc subWindow {} {
    toplevel .subWindow -background {black}
    wm overrideredirect .subWindow true
    wm attribute .subWindow -topmost true
    wm geometry .subWindow 296x120+300+250
    frame .subWindow.f -relief flat
    label .subWindow.f.label01 -text "" -width 1 -height 5 -background {black}
    grid .subWindow.f.label01 -column 0 -row 0 -padx 2 -sticky ew
    labelframe .subWindow.f.part01 -text "workPath" -width 25 -height 100
    label .subWindow.f.part01.label00 -text "HomeDir"  -font {arial 8 bold} -width 8
    label .subWindow.f.part01.label10 -text "" -width 20 -height 2 -relief groove -borderwidth 4
    button .subWindow.f.part01.button -text "Select" -width 5  -font {arial 8 bold}
    grid .subWindow.f.part01.label00 -column 0 -row 0 -pady 18 -padx 2 -sticky ew 
    grid .subWindow.f.part01.label10 -column 1 -row 0 -pady 18 -padx 2 -sticky ew
    grid .subWindow.f.part01.button -column 1 -row 1 -pady 5 -padx 4 -sticky e
    grid .subWindow.f.part01 -column 1 -row 0 -padx 3 -pady 1 -sticky ew
          
    labelframe .subWindow.f.part02 -text "Import/Export" -width 23 -height 100
    button .subWindow.f.part02.button00 -text "Import" -width 5 -font {arial 8 bold} 
    button .subWindow.f.part02.button01 -text "Export" -width 5 -font {arial 8 bold}
    button .subWindow.f.part02.button02 -text "-Back-" -width 5 -font {arial 8 bold} -command {destroy .subWindow}
    grid .subWindow.f.part02.button00 -column 0 -row 0 -pady 5 -padx 2 -sticky ew
    grid .subWindow.f.part02.button01 -column 0 -row 1 -pady 5 -padx 2 -sticky ew
    grid .subWindow.f.part02.button02 -column 0 -row 2 -pady 5 -padx 2 -sticky ew
    grid .subWindow.f.part02 -column 2 -row 0 -padx 3 -pady 1 -sticky ew
    pack .subWindow.f -padx 0 -pady 1
}

#调用subWindow过程
subWindow

2.代码解析

(1) toplevel .subWindow -background {black}

在HyperMesh主界面下定义目录名为".subWindow"的子窗口,背景色为 {black}。

(2) wm overrideredirect .subWindow true

其参数为"true",使窗口管理器彻底忽略一个顶层窗口:没有装饰,没有窗口管理器对窗口交互式操作,没有图标化。

(3) wm attribute .subWindow -topmost true

其"-topmost"参数为"true",设置子窗口".subWindow"总显示在最前面。

(4) wm geometry .subWindow 296x120+300+250

设置子窗口".subWindow"宽296字符,高120字符;

设置子窗口".subwindow"左上角位置为显示器坐标(300,250)像素点。

(5) frame .subWindow.f -relief flat

在子窗口下建立目录名为".subWindow.f"的框架,-relief决定框架外观,其值:raised、sunken、flat、groove、ridge。

应用"pack .subWindow.f -padx 0 -pady 1"将框架加载到子窗口上,-padx:X方向距离边界,-pady:Y方向距离边界。

(6) labelframe .subWindow.f.part01 -text "workPath" -width 25 -height 100

在框架".subWindow.f"下添加目录名为".subWindow.f.part01"的带标题框架,标题名"workPath",-width:框架宽度,-height:框架高度。

应用"grid .subWindow.f.part02 -column 2 -row 0 -padx 3 -pady 1 -sticky ew"将带标题子框架加载到框架".subWindow.f"的第2列,第0行位置。

(7) button .subWindow.f.part02.button02 -text "-Back-" -width 5 -font {arial 8 bold} -command {destroy .subWindow}

在带标题框架".subWindow.f.part02"下添加目录名为".subWindow.f.part02.button02"的button按钮,按钮标题名"-Back-",-width:按钮宽度,-font:标题字体大小,-command:点击button后执行的脚本。

应用"grid .subWindow.f.part02.button02 -column 0 -row 2 -pady 5 -padx 2 -sticky ew"将button添加到".subWindow.f.part02"框架下。

(8) subWindow

调用"subWindow"过程。

3.启动名称为"subWindow"插件

HyperMesh二次开发技术—插件界面开发(一)