Page 1 of 1

gtkdialog question, enable/disable button

Posted: Tue Mar 07, 2023 6:02 pm
by fredx181

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).

2023-03-07_18-50-33.png
2023-03-07_18-50-33.png (22.57 KiB) Viewed 419 times

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

Re: gtkdialog question, enable/disable button

Posted: Tue Mar 07, 2023 6:34 pm
by Sofiya

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

Re: gtkdialog question, enable/disable button

Posted: Tue Mar 07, 2023 6:57 pm
by fredx181

@Sofiya Sorry if I possibly wasn't clear, I see you put double quotes around $(cat /tmp/uload) but that doesn't help.
What I would like is that the Upload button gets enabled (not greyed out) (default it should be disabled, greyed out) after changing server address and clicking "Scan" (and again disabled if again changed to default server address). (edit: but I wouldn't be surprised if such a thing is not possible, btw)


Re: gtkdialog question, enable/disable button

Posted: Tue Mar 07, 2023 7:02 pm
by Sofiya
fredx181 wrote: Tue Mar 07, 2023 6:57 pm

@Sofiya Sorry if I possibly wasn't clear, I see you put double quotes around $(cat /tmp/uload) but that doesn't help.
What I would like is that the Upload button gets enabled (not greyed out) (default it should be disabled, greyed out) after changing server address and clicking "Scan" (and again disabled if again changed to default server address).

mmm understandable


Re: gtkdialog question, enable/disable button

Posted: Tue Mar 07, 2023 10:30 pm
by Burunduk

@MochiMoppel is an expert and will know how to do it right. We need to wait. Meanwhile test this:

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 condition="file_is_true(/tmp/uload)">enable:UPLOAD</action>
    <action condition="file_is_false(/tmp/uload)">disable:UPLOAD</action>
</button>

<button>
    <input file stock="gtk-go-up"></input>
    <label>"Upload"</label>
    <variable>UPLOAD</variable>
    <sensitive>false</sensitive>
    <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

It seems to work somehow. The info used is from here: /root/puppy-reference/doc/gtkdialog/reference/eventbox.html


Re: gtkdialog question, enable/disable button

Posted: Tue Mar 07, 2023 10:47 pm
by fredx181

@Burunduk Many thanks!!! Exactly what I want!