Posted: Mon 09 Jan 2012, 14:27
There is a simple progress bar example in /usr/share/doc/gtkdialog3 (in the devx)
READ-ONLY Archive
https://oldforum.puppylinux.com/
SFR,SFR wrote:Hi
Is it possible to show variable or function's result as a button's label (<button></button>)?
I tried with <input>, <input file...>, <label> and nothing works...
Thanks in advance.
Greetings!
Code: Select all
#! /bin/bash
LABEL=`echo result of some program`
export MAIN_DIALOG='
<button>
<label>'"$LABEL"'</label>
<action>echo new label '"$LABEL"' created</action>
</button>
'
gtkdialog3 --program=MAIN_DIALOG
This is exactly it, thanks very much!seaside wrote:Perhaps this is what you want-
This would take the result of some program (in this case the phrase "result of some program") and assign it to the variable LABEL. Note that $LABEL is surrounded by double quotes followed by outer single quotes.Code: Select all
#! /bin/bash LABEL=`echo result of some program` export MAIN_DIALOG=' <button> <label>'"$LABEL"'</label> <action>echo new label '"$LABEL"' created</action> </button> ' gtkdialog3 --program=MAIN_DIALOG
Code: Select all
#!/bin/bash
# timertest
# Functions====================================================================
text2svg()
{
#generate an image
WIDTH=$(($(echo "$1"|wc -c)*19))
T=35
BG="$2"
echo '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect width="'$WIDTH'"
height="50"
x="0"
y="0"
style="font-size:'${T}';fill:'$BG';fill-opacity:0.75;fill-rule:evenodd;stroke-width:3pt;"
id="rect1" />
<text
x="0"
y="35"
style="font-size:'${T}';font-weight:normal;fill-opacity:0.75;stroke-width:3pt;font-family:helvetica;"
id="text1">
<tspan
id="tspan1">'"${1}"'</tspan>
</text>
</svg>' > /tmp/${3}.svg
}
export -f text2svg
randomfunc(){
echo "some random number $RANDOM"
}
export -f randomfunc
pixfunc(){
DATE=`date`
text2svg "${DATE}" "#ADD8E6" date
}
export -f pixfunc
btnfunc(){
TXT=`cat /tmp/timerfile`
case $TXT in
the)echo quick >/tmp/timerfile;text2svg quick "#0000FF" label ;;
quick)echo brown >/tmp/timerfile;text2svg brown "#00FFFF" label ;;
brown)echo fox >/tmp/timerfile;text2svg fox "#FF0000" label ;;
fox)echo jumped >/tmp/timerfile;text2svg jumped "#00FF00" label ;;
jumped)echo over >/tmp/timerfile;text2svg over "#FFFF00" label ;;
over)echo a >/tmp/timerfile;text2svg a "#FF00FF" label ;;
a)echo lazy >/tmp/timerfile;text2svg lazy "#FF9500" label ;;
lazy)echo dog >/tmp/timerfile;text2svg dog "#FF00AA" label ;;
dog)echo the >/tmp/timerfile;text2svg the "#FFFFFF" label ;;
esac
}
export -f btnfunc
#==============================================================================
echo dog >/tmp/timerfile
pixfunc
btnfunc
export gui='<window>
<vbox>
<text><label>timer test</label></text>
<pixmap>
<variable>PIX</variable>
<input file>/tmp/date.svg</input>
</pixmap>
<hbox homogeneous="true">
<button tooltip-text="exit">
<variable>BTX</variable>
<input file>/tmp/label.svg</input>
</button>
</hbox>
<text><variable>VAR</variable><input>date +%T</input></text>
<text><variable>RANDNUM</variable><input>randomfunc</input></text>
<entry><variable>ENTRY</variable><input>echo $RANDOM is random too</input></entry>
<timer interval="1" visible="false">
<action>pixfunc</action>
<action>btnfunc</action>
<action type="refresh">PIX</action>
<action type="refresh">BTX</action>
<action type="refresh">VAR</action>
<action type="refresh">RANDNUM</action>
<action type="refresh">ENTRY</action>
</timer>
<hbox>
<button ok></button>
</hbox>
</vbox>
</window>'
eval $(gtkdialog -p gui)
case $EXIT in
*)rm -f /tmp/*.svg ;;
esac
Code: Select all
download_progress(){
while ([ $# -gt 0 ]) do
wget -v $1 -o /dev/stdout | while read LINE; do
case $LINE in
*%*)LINE=${LINE##*..};echo ${LINE%%%*};;
esac
done |Xdialog --gauge "Download progress ($# files remaining.)
Current file is:
$1" 0 0
shift
done
}
Code: Select all
upload_progress(){
curl --progress-bar $CURL_PARAMETERS 2>&1 \
| tr "\r" "\n"|sed "s,# *,,gm" \
| Xdialog --title "Progress" --gauge "$1 \n transfering ..." 0 0
}
Gtkdialog enables you to run a shell inside the progressbar element, so you can just sort the wget output inside it... that's what I did with the dhcpcd progressbars (note that with gtkdialog, when you echo a number, it is used for the percentage, while echoing text changes what's displayed in the progressbar).technosaurus wrote:It often comes up how to get wget to give you the percent complete (for progress bars), so I grokked it out to work with Xdialog (I am working on some gtk1 stuff right now) - perhaps someone would like to tweak it for gtkdialog?
Code: Select all
#!/bin/sh
#Combo-Checklist example
export NUM="5"
function funcChkCreate() {
for ((i=1;i<"$NUM";i++)); do
echo '<checkbox>
<label>NAME '"$i"'</label>
<variable>STAT'"$i"'</variable>
</checkbox>'
done
}
ComboCheck() {
echo
for ((i=1;i<"$NUM";i++)); do
eval echo "NAME ${i}=""\$STAT${i}" >/tmp/out
var[$i]=`cat /tmp/out`
echo "${var[$i]}"
done
}
export -f ComboCheck
export MAIN_DIALOG='
<vbox height="150" scrollable="true">
'"$(funcChkCreate)"'
<hbox>
<button>
<label>ComboCheck</label>
<action>ComboCheck</action>
</button>
<button ok></button>
</hbox>
</vbox>
'
gtkdialog --program=MAIN_DIALOG
Hi.jpeps wrote:Here's one solution to a combo-checklist. I was looking for a simple way to create a useable array for the whole checklist.
Code: Select all
#!/bin/sh
#Combo-Checklist example
export NUM="15"
function funcChkCreate() {
for ((i=1;i<"$NUM";i++)); do
echo '<checkbox>
<label>NAME '"$i"'</label>
<variable>STAT'"$i"'</variable>
</checkbox>'
done
}
ComboCheck() {
echo
for ((i=1;i<"$NUM";i++)); do
eval echo "NAME ${i}=""\$STAT${i}" >/tmp/out
var[$i]=`cat /tmp/out`
echo "${var[$i]}"
done
}
export -f ComboCheck
export MAIN_DIALOG='
<vbox>
<vbox height="150" scrollable="true">
'"$(funcChkCreate)"'
</vbox>
<vbox>
<hbox>
<button>
<label>ComboCheck</label>
<action>ComboCheck</action>
</button>
<button ok></button>
</hbox>
</vbox>
</vbox>'
gtkdialog --program=MAIN_DIALOG
Code: Select all
for ((i=1;i<"$NUM";i++)); do
Typically, you start with i=0. This is just a template, so NUM is irrelevant. In practice, the labels would be names from a list with NUM being the number of lines.RSH wrote: By giving 5 as NUM i always get only 4 arguments back.
Code: Select all
#! /bin/sh
message="Something"
change () {
message="Completely different something"
echo $message # for debugging
}
export -f change
export MAIN='
<vbox>
<edit>
<variable>VAR</variable>
<default>'"$message"'</default>
</edit>
<button>
<action>change</action>
<action>refresh:VAR</action>
<label>Refresh</label>
</button>
</vbox>
'
gtkdialog -p MAIN
echo $message #for debugging also
Code: Select all
<hbox>
<text><label>"Save Folder (path)"</label></text>
<entry tooltip-text=" Folder destination for recording ">
<input>cat "$WORKDIR/SAVEFOLDER"</input>
<variable>SAVEFOLDER</variable>
</entry>
<button tooltip-text=" Folder selector ">
<input file>/usr/local/share/icons/folder-open.png</input>
<action>Xdialog --title "Choose Directory to save recording" --stdout --no-buttons --no-cancel --dselect /mnt 32 80 > $WORKDIR/SAVEFOLDER</action>
<action>refresh:SAVEFOLDER</action>
</button>
<button tooltip-text="Path Examples">
<input file stock="gtk-info"></input>
<action>info_dialog</action>
</button>
</hbox>
Code: Select all
#!/bin/sh
export MAIN='
<vbox>
<edit>
<variable>VAR</variable>
<default>'"`date`"'</default>
</edit>
<button>
<action>refresh:VAR</action>
<label>Refresh</label>
</button>
</vbox>
'
gtkdialog -p MAIN
Code: Select all
export MAIN='
<vbox>
<entry>
<variable>VAR</variable>
<input>date</input>
</entry>
<button>
<action>refresh:VAR</action>
<label>Refresh</label>
</button>
</vbox>
'
gtkdialog3 -p MAIN
Yes, this works, but after deeper reflection I think that GTKDialog simply doesn't provide this mechanism in <edit> widget.seaside wrote:This works -
Code: Select all
export MAIN=' <vbox> <entry> <variable>VAR</variable> <input>date</input> </entry> <button> <action>refresh:VAR</action> <label>Refresh</label> </button> </vbox> ' gtkdialog3 -p MAIN
There are <input file> AND <input> directives available. All right.Code: Select all
<entry tag_attr="value"...> <default>text</default> <variable>varname</variable> <height>value</height> <width>value</width> <input>command</input> <input file>filename</input> <sensitive>state</sensitive> <action>activity</action>... <action signal="type">activity</action>... <action type="function">parameter</action>... <output file>filename</output> </entry>
There's ONLY <input file> directive...Code: Select all
<edit tag_attr="value"...> <default>state</default> <variable>varname</variable> <height>value</height> <width>value</width> <input file>filename</input> <sensitive>state</sensitive> <action signal="type">activity</action>... <output file>filename</output> </edit>
Thanks for clarification, I suspected something like that, but wasn't sure how exactly it works.seaside wrote:Generally, only "<variable>VAR</variable>" variables get set on a "refresh:VAR" command. Variables like "$message" are set once and if a "child process" (such as a function) is begun in an attempt to reset a variable, it isn't visible to the parent (original gtkdialog program).
You'll notice that frequently /tmp files are used to hold variables so that they can be referenced in those cases.
Code: Select all
<checkbox visible="false">
<label>a</label>
<variable>UPDATE_GUI</variable>
<input>cat /path/UPDATE_GUI</input>
<action>if true refresh:PLAYLIST</action>
<action>if true refresh:ARTWORK</action>
<action>if true refresh:BUTTON_PLAY</action>
<action>if true echo false > /path/UPDATE_GUI</action>
<action>if true refresh:UPDATE_GUI</action>
</checkbox>
What will make the checkbox reread the inputfile?jpeps wrote:Wouldn't it be posible to eliminate the timer altogether? If something like a new track gets played, an input file gets flagged and the checkbox gets refreshed.