YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
matchpoint
Posts: 168
Joined: Fri 26 Jan 2018, 20:54

#346 Post by matchpoint »

Ha! I forgot to save the paste before running.

That the console now complains with "--text-align=center" tells me we have a Zenity/YAD version difference, right?

I've come across these type messages before.

Ultimately though, I'd like the choice selection to be made like in the original, by keystroke, not mouse click.

Maybe one more example, Fred. Then I think I may be able to run with it.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#347 Post by fredx181 »

matchpoint wrote:Ha! I forgot to save the paste before running.

That the console now complains with "--text-align=center" tells me we have a Zenity/YAD version difference, right?

I've come across these type messages before.

Ultimately though, I'd like the choice selection to be made like in the original, by keystroke, not mouse click.

Maybe one more example, Fred. Then I think I may be able to run with it.
Probably Zenity doesn't have "--text-align=center" :?: , btw, I removed that from script above to be compatible with older yad versions. (see also edit in my previous post)

Let me understand, you want to run the script in terminal, type 1 or 2 and the rest by YAD gui, or do you want to type the temperature also in terminal and use YAD only for the final output ?

Fred
Last edited by fredx181 on Sat 10 Feb 2018, 17:31, edited 1 time in total.

matchpoint
Posts: 168
Joined: Fri 26 Jan 2018, 20:54

#348 Post by matchpoint »

Fred, thanks and relax. I'll get back to this little later.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#349 Post by fredx181 »

Hi matchpoint, I think I sort of get it now what you'd like, anyway here's another with 2 boxes where you can type in the choices, ok, I'll relax now :wink:

Code: Select all

#!/bin/bash

SETUP=`yad --title="Temperature scale conversion" --center --text="<b>*** Temperature scale conversion ***</b> \n Type 1 to convert Celsius to Fahrenheit \n Type 2 to convert Fahrenheit to Celsius" \
--width=400 \
--window-icon="preferences-system" --form  \
--field=" Type 1 or 2: : " "" \
--field=" Type temperature: : " "" \
--button="gtk-cancel:1" --button="gtk-ok:0"`
[[ $? -ne 0 ]] && exit 1

export CHOICE=$(echo $SETUP | cut -d "|" -f 1)
export TEMP_=$(echo $SETUP | cut -d "|" -f 2)

case $CHOICE in
1)
  tc=$TEMP_
  # formula Tf=(9/5)*Tc+32
  tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc)
  echo "$tc C = $tf F" | yad --title="Celsius to Fahrenheit" --center --text-info --width=300 --button="gtk-close:0"
;;
2)
  tf=$TEMP_
  # formula Tc=(5/9)*(Tf-32)
  tc=$(echo "scale=2;(5/9)*($tf-32)"|bc)
  echo "$tf F = $tc C" | yad --title="Fahrenheit to Celsius" --center --text-info --width=300 --button="gtk-close:0"
;;
esac
Fred

matchpoint
Posts: 168
Joined: Fri 26 Jan 2018, 20:54

#350 Post by matchpoint »

Fred, I'd like the dialog to run and read like my script, except with one line spacings between each entry and not yet requesting temperature input until a choice has been made. Once made however, the dialog should then switch to an "Enter temperature (C/F)" sequence, rest for 3 or so seconds after user input, then exit, effectively removing the need to "Press any key to exit."

:D Can do?

You know, even this script I have should sign off like how I've described.

And how do I get spacing between lines when dumping to stdout?

Like between these opening echos?

Code: Select all

#!/bin/bash

echo "*** Temperature scale conversion ***"
echo "Convert Celsius to Fahrenheit = 1"
echo "Convert Fahrenheit to Celsius = 2"
echo -n "Select 1 or 2, then Enter:"
read choice

if [ $choice -eq 1 ]
then
  echo -n "Enter temperature (C) : "
  read tc
  # formula Tf=(9/5)*Tc+32
  tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc)
  echo "$tc C = $tf F"
elif [ $choice -eq 2 ]
then
  echo -n "Enter temperature (F) : "
  read tf
  # formula Tc=(5/9)*(Tf-32)
  tc=$(echo "scale=2;(5/9)*($tf-32)"|bc)
  echo "$tf F = $tc C"
else
  echo "Please select 1 or 2 only"
  exit 1
fi

echo -n "
-->  Press any key to exit "
read echoice

exit 0

matchpoint
Posts: 168
Joined: Fri 26 Jan 2018, 20:54

#351 Post by matchpoint »

Check!

Code: Select all

echo -e ' \t '
Attachments
excellent.jpg
(29.6 KiB) Downloaded 698 times

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#352 Post by fredx181 »

matchpoint wrote: :D Can do?


Hi matchpoint, sorry, I keep misunderstanding what you'd like to accomplish, maybe someone else understands.
Perhaps best to try make script yourself with gui dialog commands included and show that (even if doesn't work as you like, anyway then it's clear where the gui dialog part should be)

Fred

matchpoint
Posts: 168
Joined: Fri 26 Jan 2018, 20:54

#353 Post by matchpoint »

No worries Fred. I appreciate your time and the examples you've provided.

Proost en een goede gezondheid!

User avatar
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

#354 Post by misko_2083 »

matchpoint, there is this script
https://www.gnome-look.org/content/show ... ent=174312
I've had a quick look and it does what you need. Plus, it checks if you enter the temerature bellow the absolute zero.

stemsee

#355 Post by stemsee »

I found the solution to my request, which was how to use yad --list --listen to receive data to replace existing data without closing and re-opening the yad gui.

I wonder how this will work in the tabbed version?

Code: Select all

echo -e '\f' > /tmp/pipe
clears all data. No the same as updating existing data. Empty and refill.[/code]

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#356 Post by step »

stemsee wrote: I wonder how this will work in the tabbed version?

Code: Select all

echo -e '\f' > /tmp/pipe
Yes, it works for a tabbed dialog, as long as you write to the pipe of the contained yad --list process. When the container dialog exits, it outputs the current contents of the list widget having erased everything before the \f. In some cases involving multiple columns I had to use \f\n instead of \f.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#357 Post by fredx181 »

stemsee wrote:I found the solution to my request, which was how to use yad --list --listen to receive data to replace existing data without closing and re-opening the yad gui. .
Could you provide a simple example of why/how this can be useful ? (also, with tabbed dialog I'd like to understand also)

Thanks,

Fred

stemsee

#358 Post by stemsee »

Thanks step! I haven't had a chance to try that out yet.

Here is yad 40.3 with html (webkit) 64bit compiled on fatdog 721
https://drive.google.com/open?id=11DrgG ... iJogqlHS8A

Hi Fred

A lot of your yad GUIs like the ones for gdrive need to refresh update the data in the list field, normally you close the dialog gui and open a new one ... now you don't have to, as the fields are emptied and then refilled by using --list --listen <pipe to receive new data. One advantage as in wifi-scanner is that the gui can be placed and resized only once without fear of it re-opening somewhere differen on your desktop (manageability).

Here is what I needed it for (demo). Victor Ananjetsky kindly posted an answer to me!

In this example if you select with checkboxes on 'OK' gui closes and all checked rows are printed to stdout. Note '--dclick-action' I set to output to /tmp/net only one row which is double clicked, meaning the gui stays open with fresh scan results updated every 8 seconds in my while true loop.

Hope it helps.

Code: Select all

#!/bin/bash
#Victor Ananjesky script adapted by stemsee for wifi scanning
#
test -e /tmp/yadpipe03 && rm -f /tmp/yadpipe03

# Named pipe initialization
export PIPE_03=/tmp/yadpipe03
mkfifo $PIPE_03
exec 3<> $PIPE_03

function clear_all
{
PATTERN='
s/^.*Address: ([0-9A-Z:]*)/\n\1/p 
s/^.*Quality=([^ ]*).*Signal level=(.*)/\1 \2/p 
s/^.*key:([onf]*)/~\1~/p 
s/^.*ESSID://p' 
while true
do
  iwlist wlan4 scan | sed -rn "$PATTERN" | tac > $PIPE_03
  sleep 8
  echo -e '\f'
done
}
export -f clear_all

# Main Dialog
Record=($(yad --list --separator="|" --grid-lines=hor \
    --width=300 --height=200 --center \
    --title="Wifi-Scanner" \
    --text="Example" \
    --dclick-action=echo -e $1 > /tmp/net \
    --column "AP ssid" --column "Encryption" --column "qualiy/strength" --column "bssid" --column "Check:CHK"\
    --button="Start Scannning!gtk-clear":'bash -c "clear_all > $PIPE_03"' \
    --button="OK!gtk-ok":0 \
    --listen --print-all < $PIPE_03))
Action=$?

echo ${Record[@]}

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#359 Post by fredx181 »

Thanks Stemsee !
Nice, refresh while window stays open.
What I actually would like is a button to process an item (instead double click action) while the window stays open.
Do you know if that's possible ? (tried some things, but couldn't manage).
EDIT: Found this, which works similar (window stays open), but it also has only option double-click action.
https://sourceforge.net/p/yad-dialog/wi ... /?limit=50

Fred

stemsee

#360 Post by stemsee »

Maybe you need to use --select-action

Code: Select all

#!/bin/bash -a

mkfifo ${fifo=$(mktemp -u)}
exec {fd}<>${fifo}

dbl () {
echo double event - $1
printf '\f\n' > $fifo
printf "1\n2\n3\n4\n5\n" > $fifo
}

sel () {
echo select event - $1
}

yad \
--list \
--listen \
--dclick-action 'bash -c "dbl %s"' \
--select-action 'bash -c "sel %s"' \
--column 'A' 1 2 3 4 5 < $fifo
fromhttps://groups.google.com/forum/#!topic ... FYTLhtccd4

stemsee

#361 Post by stemsee »

Maybe you need to use --select-action or add a button that fires the select event. What sort of process to due to the item?

sel () {
echo select event - $1
}

yad \
--list \
--listen \
--dclick-action 'bash -c "dbl %s"' \
--select-action 'bash -c "sel %s"' \
--column 'A' 1 2 3 4 5 < $fifo
fromhttps://groups.google.com/forum/#!topic ... FYTLhtccd4

stemsee

#362 Post by stemsee »

Maybe you need to use --select-action

Code: Select all

#!/bin/bash -a

mkfifo ${fifo=$(mktemp -u)}
exec {fd}<>${fifo}

sel () {
echo select event - $1
}

yad \
--list \
--listen \
--select-action 'bash -c "sel %s"' \
--column 'A' 1 2 3 4 5 < $fifo
fromhttps://groups.google.com/forum/#!topic ... FYTLhtccd4

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#363 Post by fredx181 »

Hi Stemsee, your empty posts may be caused by an url link containing a space (or other reason I don't know of)

stemsee

#364 Post by stemsee »

How annoying, to have lost such a good post!

short version is, will --select-action suit your purpose, 'bash -c 'some_function "%s"'
https://groups.google.com/forum/#!topic ... FYTLhtccd4

stemsee

#365 Post by stemsee »

short version is, will --select-action suit your purpose, 'bash -c "some_function %s"'
https://groups.google.com/forum/#!topic ... FYTLhtccd4

Post Reply