>А по сабжу никто не ответил? Жаль... Я написал эту кнопочку))))
Листинг tcl-скрипта
##!/usr/bin/wish -f
package require Tcl
package require Tk
proc doNotHide {lgeom} {
wm geometry . $lgeom
wm attributes . -topmost 1
wm withdraw .
wm override . 1
update idletasks
wm deiconify .
}
proc takeGeometry {lW lH lX lY} {
set s1 "x"
set s2 "+"
return $lW$s1$lH$s2$lX$s2$lY
}
proc takeOptions {lKeyWord lStr lNumber lMode} {
set s1 \(
set s2 \)
set s3 \{
set s4 \}
set s5 \&
set s6 " "
set s7 \<
set s8 \>
set strName ""
set strComm ""
set ImgName ""
set baseCom "eval exec "
set nameFlag 0
set commFlag 0
set imgFlag 0
set endStr [expr [string length $lStr] - 1]
set keyLen [expr [expr [string length $lKeyWord] + $lNumber] +1 ]
for {set j $keyLen} {$j <= $endStr} {incr j} {
set strTmp [string index $lStr $j]
if {$strTmp == $s1} { set nameFlag 1 }
if {$strTmp == $s2} { set nameFlag 2 }
if {($strTmp != $s1)&&($strTmp != $s2)&&($nameFlag == 1)} {
set strName $strName$strTmp
}
if {$strTmp == $s3} { set commFlag 1 }
if {$strTmp == $s4} { set commFlag 2 }
if {($strTmp != $s3)&&($strTmp != $s4)&&($commFlag == 1)&&($nameFlag == 2)} {
set strComm $strComm$strTmp
}
if {$strTmp == $s7} { set imgFlag 1 }
if {$strTmp == $s8} { set imgFlag 2 }
if {($strTmp != $s7)&&($strTmp != $s8)&&($imgFlag == 1)&&($commFlag == 2)} {
set ImgName $ImgName$strTmp
}
}
if {$lMode == "CommandMode"} {
set strComm $baseCom$s3$strComm$s6$s5$s4
}
return [list $strName $strComm $ImgName]
}
## Определяем рабочий каталог скрипта
if {[file exists "~/.tkStartButton/"] == 0} {
if {[file exists "/usr/local/share/tkStartButton/"] == 0} {
set optPath ""
} else {set optPath "/usr/local/share/tkStartButton/"}
} else {set optPath "~/.tkStartButton/"}
## Определяем место положения скрипта
if {[file exists "/usr/local/bin/tkStartButton.tcl"] == 0} {
set progPath ""
} else {set progPath "/usr/local/bin/"}
set progName "tkStartButton.tcl"
## Делаем картинку кнопки
set tkStartButtonImg "tkStartButton.gif"
image create photo startImg -file [file join $optPath$tkStartButtonImg]
## Устанавливаем шрифт по умолчанию
set menuFnt [font create fixedFont -family Tahoma -size 9]
## Устанавливаем цвета и прозрачность по умолчанию
set transColor #000000
set windowAlfa 1.0
set menuAlfa 1.0
set menuBgColor #333333
set menuABgColor #000000
set menuTextColor #cccccc
set menuATextColor #cccccc
## Устанавливаем ширину "бордюра" меню
set menuBW 0
set menuABW 0
## Устанавливаем прозрачность кнопки и прозрачный фон
wm attributes . -alpha $windowAlfa -transparent $transColor -transparentcolor $transColor
. configure -bg $transColor -borderwidth 0
##Устанавливаем размер по умолчанию
set bW 65
set bH 35
set bX 0
set bY 0
set geom [takeGeometry $bW $bH $bX $bY]
##Убираем область заголовка в окне, делаем его поверх всех др. окон, устанавливаем размер по умолчанию
wm geometry . $geom
wm attributes . -topmost 1
wm withdraw .
wm override . 1
update idletasks
wm deiconify .
bind . Expose [doNotHide $geom]
## Делаем стартовую кнопку
menubutton .startBtn -direction flush -image startImg -borderwidth 0 -background $transColor -foreground $transColor\
-activeforeground $transColor -activebackground $transColor -relief solid
pack .startBtn -side top -fill both -expand true
## Делаем главное меню
menu .startBtn.mMenu -borderwidth $menuBW -background $menuBgColor -foreground $menuTextColor\
-activeborderwidth $menuABW -activeforeground $menuATextColor -activebackground $menuABgColor\
-relief solid -tearoff 0 -font $menuFnt
wm attributes .startBtn.mMenu -alpha $menuAlfa -transparent $transColor -transparentcolor $transColor
## Присобачиваем меню к кнопке
.startBtn configure -menu .startBtn.mMenu
## Начинаем парсить файлик
set tkStartButtonFl "tkStartButton.cfg"
set filename $optPath$tkStartButtonFl
if [catch {open $filename r} fileid] {
puts stderr "Cannot open $filename : $fileid"
destroy .
} else {
seek $fileid 0 start
## Устанавливаем начальные значения
set menuHnd .startBtn.mMenu
set parentHnd .startBtn.mMenu
set mainMenu .startBtn.mMenu
set sMenuCounter 0
##Перебираем строки
while {[gets $fileid str] != -1} {
set sMenuCounter [expr $sMenuCounter + 1]
##Проверяем строку на комментарий
if {[string index $str 0] == "#"} { continue }
##Проверяем строку на наличие в ней ключевого слова
set btnW [string first ButtonWidth $str 0]
set btnH [string first ButtonHeight $str 0]
set btnX [string first ButtonX $str 0]
set btnY [string first ButtonY $str 0]
set trsColr [string first TransparentColor $str 0]
set winAlf [string first WindowAlfa $str 0]
set menuAlf [string first MenuAlfa $str 0]
set menuBG [string first MenuBgColor $str 0]
set menuABG [string first MenuActiveBgColor $str 0]
set menuTC [string first MenuTextColor $str 0]
set menuATC [string first menuActiveTextColor $str 0]
set menBW [string first MenuBorderWidth $str 0]
set menABW [string first MenuActiveBorderWidth $str 0]
set menFnt [string first MenuFont $str 0]
set smb [string first submenu $str 0]
set sme [string first end $str 0]
set spr [string first separator $str 0]
set exe [string first \exec $str 0]
set btnres [string first ButtonReset $str 0]
set btnoff [string first ButtonOFF $str 0]
if {$btnres != -1} {
set optList [takeOptions ButtonReset $str $btnres ""]
set imgStrName [lindex $optList 2]
if {$imgStrName != ""} {
image create photo ImgBtnres -file [file join $optPath$imgStrName]
$menuHnd add command -label [lindex $optList 0] -image ImgBtnres -compound left -command "eval exec {$progPath$progName}; destroy ."
} else {
$menuHnd add command -label [lindex $optList 0] -command "eval exec {$progPath$progName}; destroy ."
}
} elseif {$btnoff != -1} {
set optList [takeOptions ButtonOFF $str $btnoff ""]
set imgStrName [lindex $optList 2]
if {$imgStrName != ""} {
image create photo ImgBtnOFF -file [file join $optPath$imgStrName]
$menuHnd add command -label [lindex $optList 0] -image ImgBtnOFF -compound left -command "destroy ."
} else {
$menuHnd add command -label [lindex $optList 0] -command "destroy ."
}
} elseif {$btnW != -1} {
set bW [lindex [takeOptions ButtonWidth $str $btnW ""] 0]
set geom [takeGeometry $bW $bH $bX $bY]
wm geometry . $geom
} elseif {$btnH != -1} {
set bH [lindex [takeOptions ButtonHeight $str $btnH ""] 0]
set geom [takeGeometry $bW $bH $bX $bY]
wm geometry . $geom
} elseif {$btnX != -1} {
set bX [lindex [takeOptions ButtonX $str $btnX ""] 0]
set geom [takeGeometry $bW $bH $bX $bY]
wm geometry . $geom
} elseif {$btnY != -1} {
set bY [lindex [takeOptions ButtonY $str $btnY ""] 0]
set geom [takeGeometry $bW $bH $bX $bY]
wm geometry . $geom
} elseif {$trsColr != -1} {
set transColor [lindex [takeOptions TransparentColor $str $trsColr ""] 0]
wm attributes . -transparent $transColor
wm attributes .startBtn.mMenu -transparent $transColor
. configure -bg $transColor
} elseif {$winAlf != -1} {
set windowAlfa [lindex [takeOptions WindowAlfa $str $winAlf ""] 0]
wm attributes . -alpha $windowAlfa
} elseif {$menuAlf != -1} {
set menuAlfa [lindex [takeOptions MenuAlfa $str $menuAlf ""] 0]
wm attributes .startBtn.mMenu -alpha $menuAlfa
} elseif {$menuBG != -1} {
set menuBgColor [lindex [takeOptions MenuBgColor $str $menuBG ""] 0]
.startBtn.mMenu configure -background $menuBgColor
} elseif {$menuABG != -1} {
set menuABgColor [lindex [takeOptions MenuActiveBgColor $str $menuABG ""] 0]
.startBtn.mMenu configure -activebackground $menuABgColor
} elseif {$menuTC != -1} {
set menuTextColor [lindex [takeOptions MenuTextColor $str $menuTC ""] 0]
.startBtn.mMenu configure -foreground $menuTextColor
} elseif {$menuATC != -1} {
set menuATextColor [lindex [takeOptions menuActiveTextColor $str $menuATC ""] 0]
.startBtn.mMenu configure -activeforeground $menuATextColor
} elseif {$menBW != -1} {
set menuBW [lindex [takeOptions MenuBorderWidth $str $menBW ""] 0]
.startBtn.mMenu configure -borderwidth $menuBW
} elseif {$menABW != -1} {
set menuABW [lindex [takeOptions MenuActiveBorderWidth $str $menABW ""] 0]
.startBtn.mMenu configure -activeborderwidth $menuABW
} elseif {$menFnt != -1} {
set optList [takeOptions MenuFont $str $menFnt ""]
set menuFnt [font create fixedFont$sMenuCounter -family [lindex $optList 0] -size [lindex $optList 1]]
.startBtn.mMenu configure -font $menuFnt
} elseif {$smb != -1} {
set menuHnd [menu $parentHnd.sMenu$sMenuCounter -borderwidth $menuBW -background $menuBgColor -foreground $menuTextColor\
-activeborderwidth $menuABW -activeforeground $menuATextColor -activebackground $menuABgColor\
-relief solid -tearoff 0 -font $menuFnt]
wm attributes $menuHnd -alpha $menuAlfa -transparent $transColor -transparentcolor $transColor
set optList [takeOptions submenu $str $smb ""]
set imgStrName [lindex $optList 2]
if {$imgStrName != ""} {
image create photo Img$sMenuCounter -file [file join $optPath$imgStrName]
$parentHnd add cascade -label [lindex $optList 0] -image Img$sMenuCounter -compound left -menu $menuHnd
} else {
$parentHnd add cascade -label [lindex $optList 0] -menu $menuHnd
}
set parentHnd $menuHnd
} elseif {$sme != -1} {
if {[winfo parent $menuHnd] != $mainMenu} {
set menuHnd [winfo parent $menuHnd]
set parentHnd $menuHnd
} else {
set menuHnd .startBtn.mMenu
set parentHnd $menuHnd
}
} elseif {$spr != -1} {
$menuHnd add separator
} elseif {$exe != -1} {
set optList [takeOptions \exec $str $exe CommandMode]
set imgStrName [lindex $optList 2]
if {$imgStrName != ""} {
image create photo Img$sMenuCounter -file [file join $optPath$imgStrName]
$menuHnd add command -label [lindex $optList 0] -image Img$sMenuCounter -compound left -command [lindex $optList 1]
} else {
$menuHnd add command -label [lindex $optList 0] -command [lindex $optList 1]
}
}
}
close $fileid
#Покажем консоль
console show
}
А это пример конфиг-файла - расширенный синтаксис файла меню флакс-бокса (тэги иконок и пр.)
[ButtonWidth] (65)
[ButtonHeight] (40)
[ButtonX] (0)
[ButtonY] (760)
[TransparentColor] (#000000)
[WindowAlfa] (1.0)
[MenuAlfa] (1.0)
[MenuBgColor] (#333333)
[MenuActiveBgColor] (#333333)
[MenuTextColor] (#cccccc)
[menuActiveTextColor] (#ffffff)
[MenuBorderWidth] (0)
[MenuActiveBorderWidth] (0)
[MenuFont] (Tahoma) {9}
[exec] (Блокнот) {notepad} <>
[separator] () {} <>
# [separator] () {} <>
[submenu] (Power) {} <>
[exec] (Выключение) {} <Shutdown.gif>
[exec] (Перезагрузка) {} <Reboot.gif>
[exec] (Сон) {} <Hibernate.gif>
[end]
[separator] () {} <>
[submenu] (Сервис) {} <>
[ButtonReset] (Перезапустить кнопку) {} <BtnReset.gif>
[ButtonOFF] (Выключить кнопку) {} <BtnOFF.gif>
[end]
[endencoding] () {} <>