YAD - tips'n'tricks

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

step
Posts: 546
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 57 times
Been thanked: 198 times
Contact:

Re: YAD - tips'n'tricks

Post by step »

Hopefully I understood your question correctly. The scale widgets output as numbers as I slide the slider then press OK. Does it not behave that way for you?

man yad wrote:

SCL - scale field. Value of this field in a range 0..100.

The initial value of a scale widget is NOT a shell command, and the widget will NOT execute a shell command.
To run commands in a form you could use a :BTN or :FBTN.
Caveat: if the button command is meant to set a form value - e.g. "@echo 3:new_value" to assign "new_value" to the third field - the assignment will happen only after the command exits. Therefore, don't use infinite loops expecting to see fields changing their value.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

So Im trying to make a multi volume panel, or graphic equaliser. The thing is if you move a scale or scales in one yad form it outputs its value numerically next to the slider/s .... so if it can do that why doesn't it output to stdout or pipe ?

step
Posts: 546
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 57 times
Been thanked: 198 times
Contact:

Re: YAD - tips'n'tricks

Post by step »

Without seeing your code I can only suggest some guidelines. I apologize for using ALL CAPS below, I'm being lazy to avoid having to tediously enter bbcodes. I'm not shouting.

1) Yad outputs to stdout - not stderr, unless you redirect it to do so.

2) Yad's MAIN widget outputs when the dialog EXITS - no way around this. By MAIN widget I mean one of --form, --list, --text-info (when it does), --color, --file, etc., that is, the main purpose of the dialog.

3) Yad will NOT output if the dialog exits with NON-ZERO status.

4) There is a method for some MAIN widgets (FORM and LIST, YYRC) to output also before yad exits. The method consists in setting the value of a FORM button or LIST ACTION to a (shell) command that STARTS WITH @. Then when the button or list item is actioned, command's stdout is CAPTURED and any lines that START WITH N: are subtracted from stdout and redirected back to the MAIN widget, precisely to the Nth item thereof. Note: the current design has some issues that are being looked at on GitHub, where the development of yad takes place (#214, #219).

5) There is another method for the SCALE main widget to output to stdout as it's being affected: combine options --scale --print-partial.

Worth mentioning that aside from the points above, REGULAR yad buttons can output to stdout at any time. By REGULAR I mean buttons that don't belong to the MAIN widget, in other words, --button buttons.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

Code: Select all

yad --title="Headphone Volume" --mouse --geometry="400x50" \
 --button="Mute":"bash -c 'amixer set Headphone toggle'" --on-top --window-icon="$camino/icons/speaker.png" --scale --print-partial \
--value="$Vol" | while read line; do amixer set 'Headphone' ${line}% ; sleep 0.01; echo "$line" > /root/.config/snapp/settings/headvolume; done ) & 

outputs on the fly without closing

so I want to use --form widget with several fields of type :SCL, and each output to a volume or equalizer setting in realtime. It should work if the widget --scale is anything to go by, and as i pointed out, moving the slider prints the value in the gui in real time, I could use xdotool to read that value, but seeing is that value is already there why can't it be sent to stdout as well? I suspect that the 'limitation' is the output format is hardcoded to be '%1|%2|%3|%4'

step
Posts: 546
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 57 times
Been thanked: 198 times
Contact:

Re: YAD - tips'n'tricks

Post by step »

stemsee wrote: Thu Jan 26, 2023 1:37 pm

Code: Select all

yad --title="Headphone Volume" --mouse --geometry="400x50" \
 --button="Mute":"bash -c 'amixer set Headphone toggle'" --on-top --window-icon="$camino/icons/speaker.png" --scale --print-partial \
--value="$Vol" | while read line; do amixer set 'Headphone' ${line}% ; sleep 0.01; echo "$line" > /root/.config/snapp/settings/headvolume; done ) & 

outputs on the fly without closing

I had forgotten about --scale --print-partial. Thank you very much for mentioning it. I have added to my previous post
as point #5.

so I want to use --form widget with several fields of type :SCL, and each output to a volume or equalizer setting in realtime. It should work if the widget --scale is anything to go by, and as i pointed out, moving the slider prints the value in the gui in real time, I could use xdotool to read that value, but seeing is that value is already there why can't it be sent to stdout as well? I suspect that the 'limitation' is the output format is hardcoded to be '%1|%2|%3|%4'

I see. Well, --print-partial is an option for --scale, not for --form. Form doesn't support --print-partial; you can confirm this in the manual page.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

Yes, I know it's not 'supposed' to be an option, but sometimes bugs lets things work and other times undocumented features work like

Code: Select all

printf "%s\n%s\n%s\n"  "" '\' ""

clears contents of field 2 only leaving other fields and contents intact. And yad ignores unknown options.

User avatar
MochiMoppel
Posts: 1239
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 440 times

Re: YAD - tips'n'tricks

Post by MochiMoppel »

stemsee wrote: Thu Jan 26, 2023 3:34 pm

other times undocumented features work like

Code: Select all

printf "%s\n%s\n%s\n"  "" '\' ""

clears contents of field 2 only leaving other fields and contents intact.

?

step
Posts: 546
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 57 times
Been thanked: 198 times
Contact:

Re: YAD - tips'n'tricks

Post by step »

stemsee wrote: Thu Jan 26, 2023 3:34 pm

And yad ignores unknown options.

As a general statement it is incorrect. Yad doesn't ignore unknown options. It does by default but it can be configured not to ignore unknown options. Edit $HOME/.config/yad.conf (yad 0.42.x).

Code: Select all

# default true
ignore_unknown_options=false

As a specific statement for the case at hand --form --print-partial yad does ignore --print-partial vs. the main --form widget simply because --print-partial is not and unknown option, it is just out of context, and does nothing to the form.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

duple

Last edited by stemsee on Fri Jan 27, 2023 5:54 pm, edited 1 time in total.
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

MochiMoppel wrote: Fri Jan 27, 2023 1:57 am
stemsee wrote: Thu Jan 26, 2023 3:34 pm

other times undocumented features work like

Code: Select all

printf "%s\n%s\n%s\n"  "" '\' ""

clears contents of field 2 only leaving other fields and contents intact.

?

Yes try snapp (network) > transdialoguefn
yad --form with 5 fields.

Code: Select all

function clearfn { # clears respective fields of text contents
	case "$1" in
A1) printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '' '' '' >> "$fpipe";; 
A2) printf "%s\n%s\n%s\n%s\n%s\n" '' '' '' '\' '' >> "$fpipe";;
B1) printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '' '' '' >> "$dpipe";;
B2) printf "%s\n%s\n%s\n%s\n%s\n" '' '' '' '\' '' >> "$dpipe";;
ALL) printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '' '\' '' > "$fpipe"
printf "%s\n%s\n%s\n%s\n%s\n" '' '\' '' '\' '' > "$dpipe";; 
	  esac
}; export -f clearfn
Screenshot.gif
Screenshot.gif (472.3 KiB) Viewed 3068 times
don570
Posts: 688
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 117 times

Re: YAD - tips'n'tricks

Post by don570 »

refer to stemsee code

Code: Select all

yad --title="Headphone Volume" --mouse --geometry="400x50" \
 --button="Mute":"bash -c 'amixer set Headphone toggle'" --on-top --window-icon="$camino/icons/speaker.png" --scale --print-partial \
--value="$Vol" | while read line; do amixer set 'Headphone' ${line}% ; sleep 0.01; echo "$line" > /root/.config/snapp/settings/headvolume; done ) &

Is the round bracket ')" supposed to be there near end??

I tried following script without round bracket ... just to see what would happen

Code: Select all

#! /bin/bash
Vol=.8
line=uuuuu

yad --title="Headphone Volume" --mouse --geometry="400x50" \
 --button="Mute":"bash -c 'amixer set Headphone toggle'" --on-top --window-icon="/root/baconrecorder.svg" --scale --print-partial \
--value="$Vol" | while read line; do amixer set 'Headphone' ${line}% ; sleep 0.01; echo "$line" > /root/headvolume; done  &

and it seemed to work???
By the way I know nothing about yad.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

Oh yeah! There was another rounded bracket at the front end which was part of a test, but wasn't necessary!

yad is supposed to be a quick way of using prepared gtk-widgets....but sometimes I wonder :lol:

User avatar
fredx181
Posts: 3085
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1315 times
Contact:

Re: YAD - tips'n'tricks

Post by fredx181 »

About the option "@disabled@", e.g. "echo 6:@disabled@" started here with comment by @step :
https://forum.puppylinux.com/viewtopic. ... 452#p79452

The wiki example script here: https://github.com/v1cont/yad/wiki/Fron ... ind%281%29 has it (on top of function 'run_find") and I would have thought that it prevents running again while 'busy' if you click more than once on the 'yad-search' button.
But it doesn't work, clicking again while busy, it runs the search again. (EDIT: And if I remove the first and last line of that run_find function, it works exactly the same, from what I tested)
(some may say, "ok then don't click twice", that's right, in reality I don't do that, but just like to know the mechanism to prevent running more than once)

So, been looking for a way to prevent that behaviour and with success (clicking the yad-search button twice, will only search once), added another pipe and --cycle-read to the --form in the top pane.

OK, it works and just sharing, perhaps useful for someone, but perhaps it's overdone, I'd like to know how (if ?) it can be done more simple / compact (and frankly I don't really understand all I did, mostly experimented).

Modified "Frontend-for-find" :

Code: Select all

#! /bin/bash

export find_cmd='@bash -c "run_find %1 %2 %3 %4 %5"'

export fts=$(mktemp -u --tmpdir find-ts.XXXXXXXX)
export fpipe=$(mktemp -u --tmpdir find.XXXXXXXX)
export npipe=$(mktemp -u --tmpdir fnd.XXXXXXXX)
mkfifo "$fpipe"
mkfifo "$npipe"

trap "rm -f $fpipe $npipe $fts" EXIT

fkey=$(($RANDOM * $$))

function run_find
{
  echo "6:"
    if [[ $2 != TRUE ]]; then
        ARGS="-name '$1'"
    else
        ARGS="-regex '$1'"
    fi
    if [[ -n "$4" ]]; then
        touch -d "$4" $fts
        ARGS+=" -newer $fts"
    fi
    if [[ -n "$5" ]]; then
        ARGS+=" -exec grep -q -E '$5' {} \;"
    fi
    ARGS+=" -printf '%p\n%s\n%M\n%TD %TH:%TM\n%u/%g\n'"
    echo -e '\f' >> "$fpipe"
    eval find "$3" $ARGS >> "$fpipe"

echo -e "\n\n\n\n\n$find_cmd" > $npipe
}
export -f run_find

exec 3<> $fpipe
exec 4<> $npipe

# set default values
echo -e "*\nno\n$HOME\n\n\n$find_cmd" >&4

yad --plug="$fkey" --tabnum=1 --date-format="%Y-%m-%d" \
    --form --columns=2 --cycle-read --field="Name" --field="Use regex:chk" \
    --field="Directory:dir" --field="Newer than:dt" \
    --field="Content" --field="yad-search:fbtn" <&4 &

yad --plug="$fkey" --tabnum=2 --list --no-markup --dclick-action="xdg-open '%s'" \
    --text "Search results:" --column="Name" --column="Size:sz" --column="Perms" \
    --column="Date" --column="Owner" --search-column=1 --expand-column=1 <&3 &

yad --paned --key="$fkey" --button="yad-close:1" --width=700 --height=500 \
    --title="Find files" --window-icon="system-search"

exec 3>&-

To make the search duration long enough to click more than once (before finished), I searched for .png images in /usr

2023-01-28_17-53-23.png
2023-01-28_17-53-23.png (211 KiB) Viewed 3240 times
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

@fredx181 don't use echo ... try just ... 6:@disabled@

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

don570 wrote: Fri Jan 27, 2023 10:03 pm

refer to stemsee code

Code: Select all

yad --title="Headphone Volume" --mouse --geometry="400x50" \
 --button="Mute":"bash -c 'amixer set Headphone toggle'" --on-top --window-icon="$camino/icons/speaker.png" --scale --print-partial \
--value="$Vol" | while read line; do amixer set 'Headphone' ${line}% ; sleep 0.01; echo "$line" > /root/.config/snapp/settings/headvolume; done ) &

Is the round bracket ')" supposed to be there near end??

I tried following script without round bracket ... just to see what would happen

Code: Select all

#! /bin/bash
Vol=.8
line=uuuuu

yad --title="Headphone Volume" --mouse --geometry="400x50" \
 --button="Mute":"bash -c 'amixer set Headphone toggle'" --on-top --window-icon="/root/baconrecorder.svg" --scale --print-partial \
--value="$Vol" | while read line; do amixer set 'Headphone' ${line}% ; sleep 0.01; echo "$line" > /root/headvolume; done  &

and it seemed to work???
By the way I know nothing about yad.

try this ... shows mute/unmute

Code: Select all

IT="$(echo $RANDOM)"
yad --plug=$IT --tabnum=1 --scale --orient=vert --print-partial --value="70" | while read line; do amixer set 'Headphone' ${line}%; done &
TEST=$(amixer get Headphone | grep off)
[ -z "$TEST" ] && export STATE="Unmuted" || export STATE="Muted"
yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in Unmuted|on]) echo 2:Muted;amixer set Headphone toggle;; Muted|off]) echo 2:Unmuted;amixer set Headphone toggle;; esac"' --field=':RO' "$STATE" &
yad --title="Headphones" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab=Vol --tab=mute --splitter=50 --orient=vert --no-buttons &
User avatar
fredx181
Posts: 3085
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1315 times
Contact:

Re: YAD - tips'n'tricks

Post by fredx181 »

stemsee wrote: Sat Jan 28, 2023 11:50 pm

@fredx181 don't use echo ... try just ... 6:@disabled@

That gives "command not found: 6:@disabled@" ... of course.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

if you do 'echo 6:disabled' because the command will be replaced with 'disabled' I think, so to re-enable you would need to echo 6:some_function, it wont be greyed out but it will be disabled! In my function 3:@disabled@ seems to work, that is from a function in which the gui is not.

User avatar
fredx181
Posts: 3085
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1315 times
Contact:

Re: YAD - tips'n'tricks

Post by fredx181 »

stemsee wrote: Sun Jan 29, 2023 5:48 pm

if you do 'echo 6:disabled', it wont be greyed out but it will be disabled! In my function 3:@disabled@ seems to work, that is from a function in which the gui is not.

Sorry, I don't understand what you mean by:

In my function 3:@disabled@ seems to work, that is from a function in which the gui is not

can you perhaps stick to the example from the yad wiki ? https://github.com/v1cont/yad/wiki/Fron ... ind%281%29
And my "issue" is not about "greyed out" specifically, just about: not running again (and again) when clicking more than once on the button (while busy).
EDIT: As I said, I've solved it, but was just thinking that there could be a easier way perhaps.

So, been looking for a way to prevent that behaviour and with success (clicking the yad-search button twice, will only search once), added another pipe and --cycle-read to the --form in the top pane.

step
Posts: 546
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 57 times
Been thanked: 198 times
Contact:

Re: YAD - tips'n'tricks

Post by step »

@fredx181, In [1] I tried to explain why the value "@disabled@" that is used in Frontend-for-find script can't work. It's a design limitation in yad's source code that prevents the logic in Frontend-for-find from working. Quoting [1]:

disabling and then enabling the same button with a SINGLE command doesn't work because, in this case, yad does not process command output as it's being produced, but only after it was produced. Therefore the field receives @disabled@ and then IMMEDIATELY after (microseconds apart) "some other value" that re-enables the field. To sum up, to disable/enable a form button you need to keep the command that sends @disabled@ and the command that sends "some other value" as separate processes.

There is an unofficial patch [2] on GitHub that automatically disables a button while its command is running. If the author of yad will accept the patch, we won't have to worry about this problem anymore in the future. Until then any working solution will need to run a process to disable the button (set the value "@disabled@"), and another process to re-enable the button (set some value other than "@disabled@").

[1] https://forum.puppylinux.com/viewtopic. ... 614#p79614
[2] https://github.com/v1cont/yad/pull/221

disclosure: I authored [2].

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

Thanks @step

I know it must be frustrating for you, repeating yourself .... maybe my observations don't contradict what you highlight, but this example seems to show what i observe.

This function has a similar layout, but no @disabled@ command, yet the button is disabled for the duration of the sleep command, probably the sleep command could be replaced with the wait command.

Code: Select all


TEST=$(amixer get Headphone | grep off)
[ -z "$TEST" ] && export STATE="Unmuted" || export STATE="Muted"
function empty {
yad --text "busy...please wait" --timeout=3
}; export -f empty
function buttonfn {
CMND='@sh -c "case %2 in Unmuted|on]) echo 1:empty;echo 2:Muted;amixer set Headphone toggle;sleep 3; buttonfn;; Muted|off]) echo 1:empty;echo 2:Unmuted;amixer set Headphone toggle;sleep 8;buttonfn;; esac"'
echo "1:$CMND"
}; export -f buttonfn

yad  --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in Unmuted|on]) echo 1:empty;echo 2:Muted;amixer set Headphone toggle;sleep 2; buttonfn;; Muted|off]) echo 1:empty;echo 2:Unmuted;amixer set Headphone toggle; sleep 4;buttonfn;; esac"' --field=':RO' "$STATE" --no-buttons &

EDIT: It's greyed out but not disabled!!!! And the button does not accept a new command definition while in the state of having been pressed! I surrender!

User avatar
fredx181
Posts: 3085
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1315 times
Contact:

Re: YAD - tips'n'tricks

Post by fredx181 »

Thanks @stemsee I thought a better test is to make all sleep values the same,modified from your code, below it's all 4 .

Code: Select all

TEST=$(amixer get Headphone | grep off)
[ -z "$TEST" ] && export STATE="Unmuted" || export STATE="Muted"
function empty {
yad --text "busy...please wait" --timeout=3
}; export -f empty
function buttonfn {
CMND='@sh -c "case %2 in Unmuted|on]) echo 1:empty;echo 2:Muted;amixer set Headphone toggle;sleep 4; buttonfn;; Muted|off]) echo 1:empty;echo 2:Unmuted;amixer set Headphone toggle;sleep 4;buttonfn;; esac"'
echo "1:$CMND"
}; export -f buttonfn

yad  --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in Unmuted|on]) echo 1:empty;echo 2:Muted;amixer set Headphone toggle;sleep 4; buttonfn;; Muted|off]) echo 1:empty;echo 2:Unmuted;amixer set Headphone toggle; sleep 4;buttonfn;; esac"' --field=':RO' "$STATE" --no-buttons &

But when I click twice on the top button it's taking 8 seconds (clicking once only 4), so IMO not disabling the button (while "busy").

EDIT:

EDIT: It's greyed out but not disabled!!!!

I don't see "greyed out", only "darker" view of the top button while busy.

step
Posts: 546
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 57 times
Been thanked: 198 times
Contact:

Re: YAD - tips'n'tricks

Post by step »

stemsee wrote: Tue Jan 31, 2023 4:55 pm

EDIT: It's greyed out but not disabled!!!! And the button does not accept a new command definition while in the state of having been pressed! I surrender!

Peace :thumbup:

User avatar
fredx181
Posts: 3085
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 376 times
Been thanked: 1315 times
Contact:

Re: YAD - tips'n'tricks

Post by fredx181 »

step wrote: Tue Jan 31, 2023 7:10 pm
stemsee wrote: Tue Jan 31, 2023 4:55 pm

EDIT: It's greyed out but not disabled!!!! And the button does not accept a new command definition while in the state of having been pressed! I surrender!

Peace :thumbup:

So is what you're saying something like 'believe in what you want to believe, I won't stop you from that" ? :shock:

step
Posts: 546
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 57 times
Been thanked: 198 times
Contact:

Re: YAD - tips'n'tricks

Post by step »

Sorry Fred, I hadn't seen your reply to stemsee. I can confirm the behavior you described in your reply; the button isn't disabled, of course, it only looks different, for a short but noticeable time. The actual color the button takes depends on your GTK theme. In my case it looks blue for about 1 second then it turns gray again. Blue is the color my GTK theme uses for a button in the pressed state. Perhaps, stemsee's GTK theme uses the same color for both a "pressed" and a "disabled" button, which could justify why he said that "it looks disabled". I don't want to think that "it" referred to the read-only field. I am joking, of course.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

fredx181 wrote: Tue Jan 31, 2023 6:56 pm

Thanks @stemsee I thought a better test is to make all sleep values the same,modified from your code, below it's all 4 .

Code: Select all

TEST=$(amixer get Headphone | grep off)
[ -z "$TEST" ] && export STATE="Unmuted" || export STATE="Muted"
function empty {
yad --text "busy...please wait" --timeout=3
}; export -f empty
function buttonfn {
CMND='@sh -c "case %2 in Unmuted|on]) echo 1:empty;echo 2:Muted;amixer set Headphone toggle;sleep 4; buttonfn;; Muted|off]) echo 1:empty;echo 2:Unmuted;amixer set Headphone toggle;sleep 4;buttonfn;; esac"'
echo "1:$CMND"
}; export -f buttonfn

yad  --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in Unmuted|on]) echo 1:empty;echo 2:Muted;amixer set Headphone toggle;sleep 4; buttonfn;; Muted|off]) echo 1:empty;echo 2:Unmuted;amixer set Headphone toggle; sleep 4;buttonfn;; esac"' --field=':RO' "$STATE" --no-buttons &

But when I click twice on the top button it's taking 8 seconds (clicking once only 4), so IMO not disabling the button (while "busy").

EDIT:

EDIT: It's greyed out but not disabled!!!!

I don't see "greyed out", only "darker" view of the top button while busy.

having the different sleep durations provided additional contrast between the two commands.

Yes, my theme givesdark grey for a busy button and almost white (or same as background) for a disabled button.

"greyed out" or "grayed out" is terminology commonly used to describe the change in status through appearance of a clicked button, it is not meant to be taken literally, that's a 'red herring', or a logical fallacy! Sorry to have taken up everyone's time, needlessly!

User avatar
wiak
Posts: 4082
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1208 times
Contact:

Re: YAD - tips'n'tricks

Post by wiak »

I wrote the briefest and least sophisticated of small yad scripts as quick frontend to simple commands a week or so ago, but really don't know yad at all (and totally forgot what I once knew), so could do with improving them eventually.

Having faced a lot of pain trying to develop gtkdialog code a few years ago, I gave up using gtkdialog for anything new altogether (and also since was dropped Arch/Void repos aside from old version via AUR) - just kept gtkdialog around for supporting a couple of my own legacy X-based applications/GUI-front-ends until Wayland kills them off too...

Could someone therefore recommend a thorough, but precise/brief-to-the-point and up to date yad tutorial that could get me up to speed quickly? I don't program utility apps much nowadays anyway, but I find I still need to write the occasional simple GUI frontend to ease configuring some distros I'm building.

I have looked at smokey01's tutorial, but it is pretty old despite probably still being a good general resource.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

Hi @wiak

I learnt yad by learning to use it to achieve particular objectives. My objectives tend to be an intuitive and versatile interface which provides information and choice and additional functionality. Yad tutorials tend to be in the manner of working examples, with some explanation. But for general front end needs I tend to use yad --form widget. The form widget lets you have a variety of fields, and field types. It also allows backend operations on field contents without needing to close the gui. Fields can be updated by means of input from pipes, direct editing, or using --cycle-read, or special commands such as 'echo 1:@new text' etc
go through the manpage.
https://www.mankier.com/1/yad
Then when you need to work on a project advice will be forthcoming right here if you need it.

User avatar
wiak
Posts: 4082
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1208 times
Contact:

Re: YAD - tips'n'tricks

Post by wiak »

stemsee wrote: Wed Feb 15, 2023 5:14 pm

Hi @wiak

I learnt yad by learning to use it to achieve particular objectives. My objectives tend to be an intuitive and versatile interface which provides information and choice and additional functionality. Yad tutorials tend to be in the manner of working examples, with some explanation. But for general front end needs I tend to use yad --form widget. The form widget lets you have a variety of fields, and field types. It also allows backend operations on field contents without needing to close the gui. Fields can be updated by means of input from pipes, direct editing, or using --cycle-read, or special commands such as 'echo 1:@new text' etc
go through the manpage.
https://www.mankier.com/1/yad
Then when you need to work on a project advice will be forthcoming right here if you need it.

Thanks stemsee, I've also noted the versatility of the --form widget in the past - was used by fredx181 in his gifenc-sel I was trying some years ago to re-program simply to provide an exemplar for iup-lua programming. But I never used yad after that and so my mind fades and my knowledge of generally using yad pretty much non-existent until quick re-exploration recently.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

wiak wrote: Wed Feb 15, 2023 9:48 pm

... But I never used yad after that and so my mind fades and my knowledge of generally using yad pretty much non-existent until quick re-exploration recently.

Maybe it's a good thing, as there has been a lot of development and improvements recently. As you may know Victor (yad developer) lives in Kiev, and rotors as a soldier, and continues development when not soldiering. He works on gtk3 development, and this branch has a lot of new features. In the mean time our own @step maintains the gtk2 branch, and submits a lot of fixes and improvements to both branches. In the ppm there are a number of downloads for yad, at least I saw several, gtk2, gtk3, and some mixtures?! Probably the man page i linked is not up to date!

For quick reference for a fairly comprehensive yad --form example I would point you to my mounter-rotator script. For building a tray based menu app, checkout examples in Trans-Tray, in fact Trans-Tray has examples of building the tray menu with icons, and yad --notebook, with yad --list and yad --form and the yad main gui which swallows those two. I don't think it's too complex or complicated. But as I said I think it's better you do a project from the get go and get step by step help here depending on the features you wish to employ.

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: YAD - tips'n'tricks

Post by stemsee »

base64 text conversion for use in yad --text-info, --form --field:txt etc. in hope of easily preserving formatting, replacing the need for text with escaped characters, which are, for me, unsuccessfully transported to a file and from a file to the text field.

what i found so far
encode text (from file)

Code: Select all

asc=$(gzip < "$1" | base64)
echo "base64 -d <<<'$asc'| gzip -d"

print to ...

Code: Select all

base64 -d <<<'H4sIAASwqFEAA0vLL1LIVMjMU6g21NMzNKjlSsnn4kxJLEkFMvJSuQBZFmY0HwAAAA=='| gzip -d
Post Reply

Return to “Programming”