corresponds to different data ---> a list widget is filled with data
One button is used and the label text changes.
The two svg images are renamed to make programming the togglebutton
easier
Code: Select all
cp /tmp/SVG_Description.svg /tmp/true.svg
cp /tmp/SVG_Cities.svg /tmp/false.svg
There is a third svg image created in /tmp/ ---> SVG_Function.svg
This is for a simple button that is hidden when the script is first launched,
then it becomes the 'Function' button.
Note that
Code: Select all
<action>clear:LIST</action>
growing.
Code: Select all
#!/bin/bash
# make two svg images - labeled Cities and Description
for LABEL in 1 2 3 ;do
[ $LABEL -eq 1 ] && TEXT="Cities List"
[ $LABEL -eq 2 ] && TEXT="Description"
[ $LABEL -eq 3 ] && TEXT="Function"
X1=$(echo "$TEXT"|wc -c) # number of letters
W=$((${X1}*6*95/31))
DISPLACE=$(($W/7))
echo '<svg version="1.1">
<rect
style="fill:white;fill-opacity:.7;stroke-width:2;stroke:black;stroke-opacity:1;"
width='\"$W\"' height="36" rx="10" ry="10" x="1" y="1"/>
<text style="font-family:DejaVu;font-size:24;fill-opacity:1"
x='\"$DISPLACE\"' y="26" >
'$TEXT'
</text>
</svg>
'>/tmp/SVG_$TEXT.svg
done
cp /tmp/SVG_Description.svg /tmp/true.svg
cp /tmp/"SVG_Cities List.svg" /tmp/false.svg
#ln -sf /tmp/SVG_Description.svg /tmp/togglebutton.svg
mkdir -p /tmp/cities
echo 'High crime rate
Dirty
Skyscrappers' > /tmp/cities/"New York"
cp -f /tmp/cities/"New York" /tmp/cities/default
echo 'Windy
Cold
Sausage factories' > /tmp/cities/Chicago
echo 'Sunny
Dry
Hollywood' > /tmp/cities/"Los Angeles"
echo 'New York
Chicago
Los Angeles' > /tmp/cities/CITY_LIST
echo CITY_LIST > /tmp/cities/city
function function_switch {
if [ "$(cat /tmp/cities/city)" = CITY_LIST ];then
echo "New York" > /tmp/cities/city
else
echo CITY_LIST > /tmp/cities/city
fi
}
export -f function_switch
function function_switch2 {
if [ "$LIST" = "NEW York" ];then
echo "New York" > /tmp/cities/city
cp -f /tmp/cities/"$(cat /tmp/cities/city)" /tmp/cities/default
fi
if [ "$LIST" = "Chicago" ];then
echo "Chicago" > /tmp/cities/city
cp -f /tmp/cities/"$(cat /tmp/cities/city)" /tmp/cities/default
fi
if [ "$LIST" = "Los Angeles" ];then
echo "Los Angeles" > /tmp/cities/city
cp -f /tmp/cities/"$(cat /tmp/cities/city)" /tmp/cities/default
fi
}
export -f function_switch2
export MAIN_DIALOG='
<window title="Toggle text" border-width="20">
<vbox>
<list selected-row="0">
<variable>LIST</variable>
<height>200</height>
<width>250</width>
<input file>/tmp/cities/default</input>
</list>
<hbox>
<button>
<variable>BUTTON</variable>
<input file>/tmp/SVG_Function.svg</input>
<action>xmessage "You clicked a button - $LIST" &</action>
</button>
<togglebutton active="true">
<variable>togglebutton</variable>
<action>ln -sf /tmp/"$togglebutton".svg /tmp/togglebutton.svg</action>
<action>function_switch2</action>
<action>cp -f /tmp/cities/"$(cat /tmp/cities/city)" /tmp/cities/default</action>
<action>function_switch</action>
<action>if true hide:BUTTON</action>
<action>if false show:BUTTON</action>
<action>clear:LIST</action>
<action>refresh:LIST</action>
<action>refresh:togglebutton</action>
<input file>/tmp/togglebutton.svg</input>
</togglebutton>
</hbox>
</vbox>
<variable>MAIN_DIALOG</variable>
</window>'
gtkdialog --program=MAIN_DIALOG