gtkdialog question, enable/disable button

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
fredx181
Posts: 2610
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 284 times
Been thanked: 1015 times
Contact:

gtkdialog question, enable/disable button

Post 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 405 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
User avatar
Sofiya
Posts: 1824
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1210 times
Been thanked: 1090 times

Re: gtkdialog question, enable/disable button

Post 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
Attachments
Screenshot.png
Screenshot.png (5.84 KiB) Viewed 395 times

Vanilla Dpup 9.2.X - KLV-Airedale - KLA-OT2
PUPPY LINUX Simple fast free

User avatar
fredx181
Posts: 2610
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 284 times
Been thanked: 1015 times
Contact:

Re: gtkdialog question, enable/disable button

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

User avatar
Sofiya
Posts: 1824
Joined: Tue Dec 07, 2021 9:49 pm
Has thanked: 1210 times
Been thanked: 1090 times

Re: gtkdialog question, enable/disable button

Post 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

Vanilla Dpup 9.2.X - KLV-Airedale - KLA-OT2
PUPPY LINUX Simple fast free

Burunduk
Posts: 244
Joined: Thu Jun 16, 2022 6:16 pm
Has thanked: 6 times
Been thanked: 122 times

Re: gtkdialog question, enable/disable button

Post 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

User avatar
fredx181
Posts: 2610
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 284 times
Been thanked: 1015 times
Contact:

Re: gtkdialog question, enable/disable button

Post by fredx181 »

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

Post Reply

Return to “Programming”