slitaz-tools rev 199
tazdialog: fix checklist, add radiolist and fselect
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon May 19 15:29:55 2008 +0000 (2008-05-19) |
parents | 23334267b435 |
children | c5bcea9f5099 |
files | tinyutils/tazdialog |
line diff
1.1 --- a/tinyutils/tazdialog Sat May 17 20:58:11 2008 +0200 1.2 +++ b/tinyutils/tazdialog Mon May 19 15:29:55 2008 +0000 1.3 @@ -36,7 +36,8 @@ 1.4 checklist="" 1.5 menu="" 1.6 textbox="" 1.7 - args="" 1.8 + radiolist="" 1.9 + fselect="" 1.10 while [ -n "$1" ]; do 1.11 case "$1" in 1.12 --title) title="$2"; shift 2;; 1.13 @@ -59,12 +60,17 @@ 1.14 inputbox="1"; break;; 1.15 1.16 --checklist) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5" 1.17 - buttonok="1"; checklist="1"; shift 5; args="$@"; break;; 1.18 + buttonok="1"; checklist="1"; shift 5; break;; 1.19 --menu) msgbox="$2"; lines="$3"; cols="$4"; inlines="$5" 1.20 buttonok="1"; buttoncancel="1" 1.21 - menu="1"; shift 5; args="$@"; break;; 1.22 + menu="1"; shift 5; break;; 1.23 --textbox) textbox="$2"; lines="$3"; cols="$4" 1.24 buttonok="1"; break;; 1.25 + --radiolist) textbox="$2"; lines="$3"; cols="$4"; inlines="$5" 1.26 + buttonok="1"; buttoncancel="1" 1.27 + radiolist="1"; shift 5; break;; 1.28 + --fselect) fselect="$2"; lines="$3"; cols="$4" 1.29 + buttonok="1"; buttoncancel="1"; break;; 1.30 *) echo "Unknown arg $1"; return 255;; 1.31 esac 1.32 done 1.33 @@ -74,48 +80,103 @@ 1.34 BOX="<window" 1.35 [ -n "$backtitle" ] && BOX="$BOX title=\"$backtitle\"" 1.36 [ -n "$ICON" ] && BOX="$BOX icon-name=\"$ICON\"" 1.37 -BOX="$BOX> <vbox>" 1.38 -[ -n "$title" ] && BOX="$BOX <text use-markup=\"true\" width-chars=\"44\"> \ 1.39 -<label>\"<b>$title</b>\" </label> </text>" 1.40 -#[ -n "$msgbox" ] && BOX="$BOX <text wrap=\"true\" \ 1.41 -#width-chars=\"$cols\" use-markup=\"true\"><label> \"$msgbox\" </label></text>" 1.42 -[ -n "$msgbox" ] && BOX="$BOX <text wrap=\"true\" \ 1.43 -use-markup=\"true\"><label> \"$msgbox\" </label></text>" 1.44 -[ -n "$gauge" ] && BOX="$BOX <progressbar><input>while read data; do \ 1.45 -echo \$data; done</input><action type=\"exit\">0</action></progressbar>" 1.46 -[ -n "$default" ] && default="<default>$default</default>" 1.47 -[ -n "$inputbox" ] && BOX="$BOX <entry>$default<variable>OUTPUT</variable> \ 1.48 -</entry>" 1.49 +BOX="$BOX> 1.50 + <vbox> 1.51 +" 1.52 +[ -n "$title" ] && BOX="$BOX <text use-markup=\"true\" width-chars=\"44\"> 1.53 + <label>\"<b>$title</b>\" </label> 1.54 + </text> 1.55 +" 1.56 +[ -n "$msgbox" ] && BOX="$BOX <text wrap=\"true\" use-markup=\"true\"> 1.57 + <label> \"$msgbox\" </label> 1.58 + </text> 1.59 +" 1.60 +[ -n "$gauge" ] && BOX="$BOX <progressbar> 1.61 + <input>while read data; do echo \$data; done</input> 1.62 + <action type=\"exit\">0</action> 1.63 + </progressbar> 1.64 +" 1.65 +[ -n "$default" ] && default="<default>$default</default> 1.66 + " 1.67 +[ -n "$inputbox" ] && BOX="$BOX <entry> 1.68 + $default<variable>OUTPUT</variable> 1.69 + </entry> 1.70 +" 1.71 #[ -n "$textbox" ] && BOX="$BOX <text><input file width-chars=\"$cols\" \ 1.72 #height=\"$lines\" wrap=\"true\">$textbox</input></text>" 1.73 -[ -n "$textbox" ] && BOX="$BOX <text><input file \ 1.74 -wrap=\"true\">$textbox</input></text>" 1.75 -[ -n "$menu" ] && BOX="$BOX <list>$( 1.76 - set -- $args | while [ -n "$1" ]; do 1.77 - echo "<item>$1 $2</item>" 1.78 +[ -n "$textbox" ] && BOX="$BOX <text> 1.79 + <input file wrap=\"true\">$textbox</input> 1.80 + </text> 1.81 +" 1.82 +[ -n "$menu" ] && BOX="$BOX <list> 1.83 +$(while [ -n "$1" ]; do 1.84 + echo " <item>$1 $2</item> 1.85 +" 1.86 shift 2 1.87 - done) <variable>LIST</variable> </list>" 1.88 -[ -n "$checklist" ] && BOX="$BOX $( 1.89 - i=0; set -- $args | while [ -n "$1" ]; do 1.90 + done) <variable>LIST</variable> 1.91 + </list> 1.92 +" 1.93 +[ -n "$radiolist" ] && BOX="$BOX$( 1.94 + i=0; while [ -n "$1" ]; do 1.95 [ "$3" = "on" ] && c=" active=\"true\"" || c="" 1.96 - echo "<checkbox$c><label>$1 $2</label><variable>CHECK$i</variable></checkbox>" 1.97 + echo " <radiobutton$c> 1.98 + <label>$1 $2</label> 1.99 + <variable>CHECK$i</variable> 1.100 + </radiobutton> 1.101 +" 1.102 i=$(($i+1)) 1.103 shift 3 1.104 done)" 1.105 -[ "$yeslabel" = "ok" ] && yeslabel="" || yeslabel="<label>$yeslabel</label>" 1.106 -[ "$nolabel" = "cancel" ] && nolabel="" || nolabel="<label>$nolabel</label>" 1.107 +[ -n "$checklist" ] && BOX="$BOX $( 1.108 + i=0; while [ -n "$1" ]; do 1.109 + [ "$3" = "on" ] && c=" active=\"true\"" || c="" 1.110 + echo " <checkbox$c> 1.111 + <label>$1 $2</label> 1.112 + <variable>CHECK$i</variable> 1.113 + </checkbox> 1.114 +" 1.115 + i=$(($i+1)) 1.116 + shift 3 1.117 + done)" 1.118 +[ -n "$fselect" ] && BOX="$BOX <hbox> 1.119 + <entry> 1.120 + <variable>OUTPUT</variable> 1.121 + </entry> 1.122 + <button> 1.123 + <input file stock=\"gtk-open\"></input> 1.124 + <variable>FILE_BROWSE</variable> 1.125 + <action type=\"fileselect\">OUTPUT</action> 1.126 + </button> 1.127 + </hbox> 1.128 +" 1.129 +[ "$yeslabel" = "ok" ] && yeslabel="" || yeslabel=" 1.130 + <label>$yeslabel</label>" 1.131 +[ "$nolabel" = "cancel" ] && nolabel="" || nolabel=" 1.132 + <label>$nolabel</label>" 1.133 [ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX <hbox>" 1.134 -[ -n "$buttonok" ] && BOX="$BOX <button ok>$yeslabel \ 1.135 -<action type=\"exit\">0</action> </button>" 1.136 -[ -n "$buttonextra" ] && BOX="$BOX <button><label>$extralabel</label> \ 1.137 -<input file icon=\"forward\"> </input> <action type=\"exit\">3</action> \ 1.138 -</button>" 1.139 -[ -n "$buttoncancel" ] && BOX="$BOX <button cancel>$nolabel \ 1.140 -<action type=\"exit\">1</action> </button>" 1.141 -[ -n "$buttonhelp" ] && BOX="$BOX <button help> <action type=\"exit\">2\ 1.142 -</action> </button>" 1.143 -[ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX </hbox>" 1.144 -BOX="$BOX </vbox></window>" 1.145 +[ -n "$buttonok" ] && BOX="$BOX <button ok>$yeslabel 1.146 + <action type=\"exit\">0</action> 1.147 + </button> 1.148 +" 1.149 +[ -n "$buttonextra" ] && BOX="$BOX <button> 1.150 + <label>$extralabel</label> 1.151 + <input file icon=\"forward\"> </input> 1.152 + <action type=\"exit\">3</action> 1.153 + </button> 1.154 +" 1.155 +[ -n "$buttoncancel" ] && BOX="$BOX <button cancel>$nolabel 1.156 + <action type=\"exit\">1</action> 1.157 + </button> 1.158 +" 1.159 +[ -n "$buttonhelp" ] && BOX="$BOX <button help> 1.160 + <action type=\"exit\">2</action> 1.161 + </button> 1.162 +" 1.163 +[ -n "$buttonok$buttonextra$buttoncancel" ] && BOX="$BOX </hbox> 1.164 +" 1.165 +BOX="$BOX </vbox> 1.166 +</window> 1.167 +" 1.168 export BOX 1.169 status=$(if [ -n "$gauge" ]; then 1.170 ( while read line; do 1.171 @@ -131,9 +192,8 @@ 1.172 *OUTPUT*) eval $line 1.173 echo "$OUTPUT" 1>&2 ;; 1.174 *CHECK*true*) line=${line%=*}; line=${line#CHECK} 1.175 - set -- $args 1.176 - [ $line -eq 0 ] || shift $(($line * 3)) 1.177 - echo -n "\"$1\" " 1>&2 ;; 1.178 + [ $line -eq 0 ] || shift $((3 * $line)) 1.179 + echo -n "\"$1\" " 1>&2;; 1.180 *LIST=*) eval $line; set -- $LIST 1.181 echo "$1" 1>&2 ;; 1.182 *EXIT*abort*) echo 255;;