Very simplified concept script below to be test example of enable/disable button "Upload", but cannot make it work.
What I would like is that when changing the default server address, then clicking the "Scan" button, that the "Upload" button gets enabled (or disabled again) (if .... enable it, else ... disable it).
The real script I'm working on does a lot of things when clicking "Scan" , I just like to know how this if .. else condition in "re_scan" function can be made to work by enabling/disabling the "Upload" button.
(edit: the goal is to check if uploading is possible to a specific server address, if not, the Upload button must be disabled)
Tried a few things like refresh:UPLOAD, <visible> <sensitive> and more but have to admit that I don't really know what I'm doing (and if even possible )
The Upload button is disabled by default (as it should be).
Code: Select all
#!/bin/bash
export MAINHOSTDIR="http://192.168.1.2:8000"
echo false > /tmp/uload # Upload button disabled by default
re_scan () {
if [ "$(cat /tmp/nplay-main_dir)" != "http://192.168.1.2:8000" ]; then
echo "address changed (to $(cat /tmp/nplay-main_dir) ) OK, enable the upload button"
echo true > /tmp/uload
else
echo "disable the upload button"
echo false > /tmp/uload
fi
#rm /tmp/nplay-main_dir
}; export -f re_scan
up_load () {
echo "command to do the uploading"
}; export -f up_load
export testdialog='
<window title="button disable/enable other button test" icon-name="gtk-network">
<vbox>
<hbox width-request="620">
<text>
<label>Server address:</label>
</text>
<comboboxentry width-request="270" space-expand="true" space-fill="true">
<variable>MAINHOSTDIR</variable>
<default>'$MAINHOSTDIR'</default>
<item>'$MAINHOSTDIR'</item>
</comboboxentry>
<button>
<input file stock="gtk-refresh"></input>
<label>"Scan"</label>
<action>echo "$MAINHOSTDIR" | sed -e "s|//|/|2" > /tmp/nplay-main_dir</action>
<action>re_scan</action>
<action>refresh:UPLOAD</action>
</button>
<button>
<input file stock="gtk-go-up"></input>
<label>"Upload"</label>
<variable>UPLOAD</variable>
<sensitive>'$(cat /tmp/uload)'</sensitive>
<action>refresh:UPLOAD</action>
<action>up_load</action>
</button>
<button>
<label>'Exit'</label>
<input file stock="gtk-quit"></input>
<action type="exit">exit</action>
</button>
</hbox>
</vbox>
</window>'
gtkdialog --program=testdialog --center