Page 18 of 42

Posted: Sat 10 Feb 2018, 06:44
by april
What command would you like to see . Same result yad first or last

Posted: Sat 10 Feb 2018, 14:57
by matchpoint
Hi April, and thanks. What I'm asking for is an example for having YAD handle the exchange. Then, maybe it's not YAD I'm after but GtkDialog. There's a nice example here, several here, and an intro by zigbert here. As not to spend much time trying to reinvent the wheel, and considering the amount of user input remains the same, I assigned an icon to my script and placed it on the launch bar for easy-peasy access.

Posted: Sat 10 Feb 2018, 15:07
by fredx181
Hi matchpoint, something like this maybe ?

Code: Select all

#!/bin/bash

SETUP=`yad --title="Temperature scale conversion" --center --text="   <b>*** Temperature scale conversion ***</b>" \
--width=400 \
--window-icon="preferences-system" --form  \
--field=" Select: :CB" "Convert Celsius to Fahrenheit!Convert Fahrenheit to Celsius" \
--field=" Set temperature: :NUM" "1!1..500!1" \
--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 | cut -f1 -d".")

case $CHOICE in
"Convert Celsius to Fahrenheit")
  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"
;;
"Convert Fahrenheit to Celsius")
  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
EDIT: Removed "--text-align=center" from above script for compatibility with older yad version

Fred

Posted: Sat 10 Feb 2018, 16:08
by matchpoint
Maybe Fred, it didn't open anything though.

It looks like your intention was for me to save it as a script and have it open a kind of message box, correct?

What's the "esac" on the end? YAD lingo?

Posted: Sat 10 Feb 2018, 16:16
by fredx181
matchpoint wrote:It looks like your intention was for me to save it as a script and have it open a kind of message box, correct?

What's the "esac" on the end? YAD lingo?
Yes, save it for example as "tempconv" and make excutable:

Code: Select all

chmod +x tempconv
And run it.

The esac in not yad code, it's builtin bash code, "case ... in", should be finished with esac, just like if ....; fi
Only where it shows "yad ......." is yad code.

edit: hopefully you have higher yad version than 0.12 (which is included in some Puppies), probably works only with version higher than 0.12 (or maybe needs some adjustments to make it work with 0.12)
edit2: edited the script above slightly so there's better chance it works with older yad.

Fred

Posted: Sat 10 Feb 2018, 16:34
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.

Posted: Sat 10 Feb 2018, 16:50
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

Posted: Sat 10 Feb 2018, 17:05
by matchpoint
Fred, thanks and relax. I'll get back to this little later.

Posted: Sat 10 Feb 2018, 17:13
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

Posted: Sat 10 Feb 2018, 20:27
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

Posted: Sat 10 Feb 2018, 20:49
by matchpoint
Check!

Code: Select all

echo -e ' \t '

Posted: Sun 11 Feb 2018, 13:18
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

Posted: Sun 11 Feb 2018, 15:55
by matchpoint
No worries Fred. I appreciate your time and the examples you've provided.

Proost en een goede gezondheid!

Posted: Mon 12 Feb 2018, 06:18
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.

Posted: Sun 18 Feb 2018, 17:26
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]

Posted: Mon 19 Feb 2018, 12:47
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.

Posted: Mon 19 Feb 2018, 19:09
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

Posted: Mon 19 Feb 2018, 20:04
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[@]}

Posted: Tue 20 Feb 2018, 11:31
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

Posted: Tue 20 Feb 2018, 15:28
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