YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
stemsee

#421 Post by stemsee »

Howabout using yad --file-selector (or MMview) as a wifi network connection display manager? Perform a scan and use data for each ssid to generate a .jpg (using 01mickos wallpaper generator) or .svg (maybe easier) to populate a directory in /tmp or on disk. This should be so easy to code and unique in the world of wifi connection tools! Are you up for this Fred? Misky? Mochi?
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#422 Post by MochiMoppel »

stemsee wrote:Are you up for this Fred? Misky? Mochi?
Not me. I know nothing about wifi.
stemsee

#423 Post by stemsee »

Fair enough ... The main thing is the algorithm to convert/imbed selected scan data into the image, and have that algorithm function in reverse to extract scan data from the image back into usable text strings.

Any file selector/browser then becomes a Wifi/network connection app.

EDIT: completed ... a basic function
Attachments
2018-06-10-170413_729x405_scrot.png
(89.51 KiB) Downloaded 637 times
stemsee

#424 Post by stemsee »

With rox and yad --file-selection --add-preview
Attachments
xscreenshot-20180611T113639.png
(79.1 KiB) Downloaded 163 times
stemsee

#425 Post by stemsee »

does anyone know why I am not getting any exit codes from this

Code: Select all

	yad --image=$track/images/$line.svg --window-icon="$pics/wifi24.png" --geometry="$(cat $camino/geometry/$WINDOWTITLE)" --title="$WINDOWTITLE" --text "Yes to keep this connection\nNo try next open AP/nCancel to stop and exit!" --button=gtk-yes:0 --button=gtk-no:2 --button=gtk-cancel:1 --timeout-indicator=top --timeout=8
It looks like this
Attachments
2018-06-30-110313_577x309_scrot.png
(45.9 KiB) Downloaded 530 times
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#426 Post by MochiMoppel »

stemsee wrote:does anyone know why I am not getting any exit codes from this
Don't know why it wouldn't work. How do you read the exit codes?
Works here as expected for this stripped down code:

Code: Select all

yad --button=gtk-yes:0 --button=gtk-no:2 --button=gtk-cancel:1 --timeout-indicator=top --timeout=8
echo $?
Returns exit codes 0,2,1,70 (timeout) or 252 (Alt+F4)
stemsee

#427 Post by stemsee »

Thanks MochiMoppel

Firstly I associated the yad statemnet with a variable goOn=`yad ...`
and then ret=$?, followed by a case statement. When I first implemented these they seemed to work, but now not. i wonder if the extra variables confuse yad (ie yad has a bug).

Is there a constraint on how many functions bash can address? Or how many functions and variables a script may produce?
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#428 Post by MochiMoppel »

stemsee wrote:Firstly I associated the yad statemnet with a variable goOn=`yad ...`
and then ret=$?, followed by a case statement.
When exactly is "then"? If you add ret=$? after your yad statement, still within the command substitution (= the expression delimited by backtics), the value of ret will be lost as soon as you finish your assignment to variable goOn.
If you add ret=$? after the goOn assignment, the value will always be 0.

You need to print the value of $ret to stdout within the command substitution:.

Code: Select all

goOn=$(yad --button=gtk-yes:0 --button=gtk-no:2 --button=gtk-cancel:1 --timeout-indicator=top --timeout=8; ret=$? ;echo $ret)
case $goOn in
0) echo you pressed yes ;;
1) echo you pressed cancel ;;
2) echo you pressed no ;;
*) echo you did not press a button;;
esac
Assigning $? to ret makes little sense here. You could echo $? directly.
stemsee

#429 Post by stemsee »

That explains the results I was seeing perfectly!

Ervyreihtng is wronikg fnie aiagn! I can see taht I was mnixig dnefifret mhoteds!

Tnahks McohiMpoepl

semsete
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#430 Post by MochiMoppel »

Yu'reo womelec!
stemsee

#431 Post by stemsee »

MochiMoppel wrote:Yu'reo womelec!
Ha ha! The linguistic code is that the first and last letter of each word must be as the usual spelling but internal letters can be in any order! Native like level English reader's brains will get the correct reading!

smeetse
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#432 Post by MochiMoppel »

I figured that a clever English brain would get the meaning with only the first letters in its usual place.
Of course the brain of a genius would need no specific order at all.
Covfefe!
stemsee

#433 Post by stemsee »

Since when does coffee have a 'v' in it? 'v' must be a sugar free sweetener!
User avatar
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

#434 Post by misko_2083 »

stemsee wrote:Since when does coffee have a 'v' in it? 'v' must be a sugar free sweetener!
It's one of those internet memes. That is how Trump spells "coverage" on twitter. :D

In English or other languages, the brain can see the whole word at once as long as the first and the last letters are in the right possition. Although it takes more time to read such text.

As you can see, by the Mochi's word play, the brain can easily be tricked.
Image

-----------------------------------------------------------------------

By the way, how does timeout indicator works?
If the timeout is set to 8 seconds, the progress bar can reach 9 or even 10 occasionally. :roll:

Code: Select all

#!/bin/bash
i=1
while true
 do
   echo "1:#$(date '+%T')"
   echo "2:#$(date '+%D %a')"
   echo "3:#${i}"
   echo "3:$(( ${i}*100 /8 ))"
   i=$(($i+1))
   sleep 1
 done | yad --multi-progress \
             --bar="Time":NORM \
             --bar="Date":NORM \
             --bar="Countdown":NORM \
             --window-icon="clock" \
             --image="clock" \
             --borders="20" \
             --no-buttons \
             --timeout-indicator=top \
             --timeout=8 
------------------------------------------

With both --watch-bar=3 and --auto-close included, the dialog will close before the timeout is reached.

Perhaps, yad applies a custom version of the the general theory of relativity. Time is relative to the length of the Gtk+ bar? :lol:
stemsee

#435 Post by stemsee »

misko_2083 wrote: It's one of those internet memes. That is how Trump spells "coverage" on twitter. :D
Something I would never have known!
Perhaps, yad applies a custom version of the the general theory of relativity. Time is relative to the length of the Gtk+ bar? :lol:
So, that is why I look so young!
stemsee

#436 Post by stemsee »

I have a list of network blocks, each assigned to variables in a text document, I can display the blocks with

Code: Select all

. $HOME/.wifi-connect/netblocks
echo $A{a..z}
, and also display a selector with

Code: Select all

yad --plug=$$ --form --field="Selector:CBE" "`echo A{a..z}`"
However I cannot get the selected eg, 'Ag', even when written to a file as

Code: Select all

$Ag
to expand as a variable, it remains treated as an object.

when I import the netblocks file with 26 blocks as variables as follows

Code: Select all

# Only WPA-PSK is used. Any valid cipher combination is accepted.

Ac='$sect
	proto=WPA
	key_mgmt=WPA-PSK
	pairwise=CCMP TKIP
	group=CCMP TKIP WEP104 WEP40'

# WPA-Personal(PSK) with TKIP and enforcement for frequent PTK rekeying

Ad='$sect
	proto=WPA
	key_mgmt=WPA-PSK
	pairwise=TKIP
	group=TKIP
	wpa_ptk_rekey=600'

# Only WPA-EAP is used. Both CCMP and TKIP is accepted. An AP that used WEP104
# or WEP40 as the group cipher will not be accepted.

Ae='ssid=$ssid
	proto=RSN
	key_mgmt=WPA-EAP
	pairwise=CCMP TKIP
	group=CCMP TKIP
	eap=TLS
	identity="$id"
	ca_cert="/etc/cert/ca.pem"
	client_cert="/etc/cert/user.pem"
	private_key="/etc/cert/user.prv"
	private_key_passwd="$password"'
They can be piped from a terminal which has imported the variables from the file, with

Code: Select all

echo "$Ag" >/tmp/PIPE
but not from the code which is

Code: Select all

rm -f /tmp/PIPE
mkfifo -m 755 /tmp/PIPE
exec 4<> /tmp/PIPE
touch /tmp/net
. $HOME/.wifi-connect/netblocks
while read line
do
. $HOME/.wifi-connect/netblocks
echo "`cat /tmp/net`" >/tmp/PIPE
done &
yad --plug=$$ --tabnum=1 --list --columns=1 --item-separator=" " --column="NetBLocks:CBE" `echo A{a..z}` --select-action='bash -c "printf %s $1 | sed 's/^/\$/g' >/tmp/net"' &
yad --plug=$$ --tabnum=2 --text-info <&4 &
yad --window-icon=/usr/share/pixmaps/refdnd.png --width=400 --height=400 \
--no-buttons --on-top --paned --splitter=100 --key=$$ --title="NetBlocks" --tab="Preview" --tab="Selector" --orient=hori  &
So what am I doing wrong?
Attachments
2018-07-06-123128_1218x308_scrot.png
ow it should look
(85.11 KiB) Downloaded 168 times
2018-07-06-122408_402x433_scrot.png
(24.29 KiB) Downloaded 963 times
User avatar
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

#437 Post by misko_2083 »

stemsee wrote:Perhaps, yad applies a custom version of the the general theory of relativity. Time is relative to the length of the Gtk+ bar?
So, that is why I look so young!
:lol: You learned the secret from Doctor Who.
stemsee wrote:I have a list of network blocks, each assigned to variables in a text document, I can display the blocks with

.... Long text.....

They can be piped from a terminal which has imported the variables from the file, with

Code: Select all

echo "$Ag" >/tmp/PIPE
but not from the code which is

Code: Select all

rm -f /tmp/PIPE
mkfifo -m 755 /tmp/PIPE
exec 4<> /tmp/PIPE
touch /tmp/net
. $HOME/.wifi-connect/netblocks
while read line
do
. $HOME/.wifi-connect/netblocks
echo "`cat /tmp/net`" >/tmp/PIPE
done &
yad --plug=$$ --tabnum=1 --list --columns=1 --item-separator=" " --column="NetBLocks:CBE" `echo A{a..z}` --select-action='bash -c "printf %s $1 | sed 's/^/\$/g' >/tmp/net"' &
yad --plug=$$ --tabnum=2 --text-info <&4 &
yad --window-icon=/usr/share/pixmaps/refdnd.png --width=400 --height=400 \
--no-buttons --on-top --paned --splitter=100 --key=$$ --title="NetBlocks" --tab="Preview" --tab="Selector" --orient=hori  &
So what am I doing wrong?
This is for bash 4.1 and above;

Code: Select all

#!/bin/bash

rm -f /tmp/PIPE /tmp/net
mkfifo -m 755 /tmp/PIPE
exec 4<> /tmp/PIPE

mkfifo -m 755 /tmp/net
exec 5<> /tmp/net

. $HOME/.wifi-connect/netblocks

while read line || [ -n "$line" ]
do
  # clear text-info
  echo -e "\f" >/tmp/PIPE

  echo "${!line}" >/tmp/PIPE
  # For bash lower than 4.1 you can use case
  # case $line in ...
done <&5 & MON_PID=$!


yad --plug=$$ --tabnum=1 --list --columns=1 --item-separator=" " --column="NetBLocks:CBE" `echo A{a..z}` \
    --select-action='bash -c "foo=$(printf %s $1); echo  "$foo" >/tmp/net"' &

yad --plug=$$ --tabnum=2 --text-info <&4 &

yad --window-icon=/usr/share/pixmaps/refdnd.png --width=400 --height=400 \
--no-buttons --on-top --paned --splitter=100 --key=$$ --title="NetBlocks" --tab="Preview" --tab="Selector" --orient=hori

# close file descriptoprs
4<&-
5<&-

kill -9 $MON_PID
stemsee

#438 Post by stemsee »

Thanks misko

It works perfectly. At first I copied from the webpage and pasted into geany etc it didn't work until I reformatted it.

I see that using a pipe not a file is essential. I thought I was quite close!

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

#439 Post by misko_2083 »


stemsee

#440 Post by stemsee »

Yad colour columns
I think someone shared this before, but I just (re) discovered it!

Code: Select all

yad --list --column="Column Name" --column="@fore@" "red text" "#ff0000" "black text" "#000000"  "yellow text" "#ffff00" "green text" "#90EE90"
yad  --list --column="Column Name" --column="@back@" "red" "#ff0000" "yell" "#ffff00" "green" "#90EE90"
Attachments
2018-07-17-113511_267x237_scrot.png
(16.05 KiB) Downloaded 776 times
2018-07-17-113441_285x238_scrot.png
(13.69 KiB) Downloaded 776 times
Post Reply