Linux GUI脚本zenity

来源:互联网 发布:程序员很难找女朋友吗 编辑:程序博客网 时间:2024/06/05 08:24

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主题的安装脚本的例子:

Java代码  收藏代码
  1. #!/bin/bash  
  2.   
  3. 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"  
  4.   
  5. 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")  
  6.   
  7. (  
  8.   
  9. gksudo "add-apt-repository ppa:elementaryart/ppa"   
  10. gksudo "apt-get update"  
  11.   
  12. DOIT=$(echo $OPTIONS | grep "Engine")  
  13. if [ -n "$DOIT" ] ; then  
  14.     gksudo apt-get install gtk2-engines-murrine  
  15. fi  
  16.   
  17. DOIT=$(echo $OPTIONS | grep "Theme")  
  18. if [ -n "$DOIT" ] ; then  
  19.         gksudo apt-get install elementary-theme  
  20. fi  
  21.   
  22. DOIT=$(echo $OPTIONS | grep "Icons")  
  23. if [ -n "$DOIT" ] ; then  
  24.         gksudo apt-get install elementary-icon-theme  
  25. fi  
  26.   
  27. gconftool-2 --type string --set /desktop/gnome/interface/gtk_theme "elementary"  
  28. gconftool-2 --type string --set /apps/metacity/general/theme "elementary"  
  29. gconftool-2 --type string --set /desktop/gnome/interface/icon_theme "elementary"  
  30.   
  31. ) | zenity --progress --width 370 --height 180 --pulsate --title "Installing selected components" --text "Installing...\nBe patient please." --auto-close  
  32.   
  33. zenity --info --text "elementary theme successfully installed!\n\nScript made by: Nookie^\n\nVisit: elementary-project.com\nIRC: #elementary on irc.freenode.org" 


转自:http://fuliang.iteye.com/blog/666057
原创粉丝点击