Linux GUI脚本zenity

zentiy可以帮助你使用脚本创建常用的gtk+对话框。
1、使用日历控件:

szDate=$(zenity --calendar --text "Pick a day" --title "Medical Leave" --day 13 --month 5
--year 2010); echo $szDate


2、创建一个Entry对话框:

szAnswer=$(zenity --entry --text "where are you?" --entry-text "at home"); echo $szAnswer


3、创建一个错误对话框:

zenity --error --text "Installation failed! "


4、创建一个Info对话框:

zenity --info --text "Join us at irc.freenode.net #lbe."


5、创建一个文件选择对话框:

szSavePath=$(zenity --file-selection --save --confirm-overwrite);echo $szSavePath


6、创建一个通知对话框:

zenity  --notification  --window-icon=update.png  --text "Please update your system."


7、创建一个进度对话框:

gksudo lsof | tee >(zenity --progress --pulsate) >lsof.txt


8、创建一个question对话框:

zenity --question --text "Are you sure you want to shutdown?"; echo $?


9、创建一个警告对话框:

zenity --warning --text "This will kill, are you sure?";echo $?


10、创建一个滑动scale对话框:

ans=$(zenity --scale --text "pick a number" --min-value=2 --max-value=100 --value=2
--step 2);echo $ans


11、创建一个文本信息对话框:

gksudo lsof | zenity --text-info --width 530


12、创建一个列表对话框:
radiolist:

ans=$(zenity  --list  --text "Is linux.byexamples.com helpful?" --radiolist  --column "Pick"
--column "Opinion" TRUE Amazing FALSE Average FALSE "Difficult to follow" FALSE "Not helpful");
echo $ans


checklist:

ans=$(zenity  --list  --text "How linux.byexamples can be improved?" --checklist 
--column "Pick" --column "options" TRUE "More pictures" TRUE "More complete post" FALSE "
Includes Installation guidelines" FALSE "Create a forum for question queries"
--separator=":"); echo $ans


一个linux elementary主题的安装脚本的例子:

#!/bin/bash

zenity --info --text "This is an installation file for elementary theme.\nIt will download latest packages and install them\nand aswell apply the elementary theme.\n\nVisit us at: www.elementary-project.com\nIRC: #elementary on irc.freenode.org\n\nBest Regards\nElementary Team"

OPTIONS=$(zenity --list --width=370 --height=350 --title="elementary installation" --text="Please select elementary components you\nwould like to have installed." --checklist  --column "Option" --column  "Description" TRUE "Elementary Theme" TRUE "Elementary Icons" TRUE "GTK Murrine Engine")

(

gksudo "add-apt-repository ppa:elementaryart/ppa" 
gksudo "apt-get update"

DOIT=$(echo $OPTIONS | grep "Engine")
if [ -n "$DOIT" ] ; then
	gksudo apt-get install gtk2-engines-murrine
fi

DOIT=$(echo $OPTIONS | grep "Theme")
if [ -n "$DOIT" ] ; then
        gksudo apt-get install elementary-theme
fi

DOIT=$(echo $OPTIONS | grep "Icons")
if [ -n "$DOIT" ] ; then
        gksudo apt-get install elementary-icon-theme
fi

gconftool-2 --type string --set /desktop/gnome/interface/gtk_theme "elementary"
gconftool-2 --type string --set /apps/metacity/general/theme "elementary"
gconftool-2 --type string --set /desktop/gnome/interface/icon_theme "elementary"

) | zenity --progress --width 370 --height 180 --pulsate --title "Installing selected components" --text "Installing...\nBe patient please." --auto-close

zenity --info --text "elementary theme successfully installed!\n\nScript made by: Nookie^\n\nVisit: elementary-project.com\nIRC: #elementary on irc.freenode.org"

 

 

你可能感兴趣的:(linux,.net,脚本,bash)