Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 26 Sep 2018, 04:49
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
YAD - Tips
Post new topic   Reply to topic View previous topic :: View next topic
Page 30 of 35 [512 Posts]   Goto page: Previous 1, 2, 3, ..., 28, 29, 30, 31, 32, 33, 34, 35 Next
Author Message
stemsee

Joined: 27 Jun 2013
Posts: 2264
Location: In The Way

PostPosted: Fri 06 Jul 2018, 10:02    Post subject:  

I have a list of network blocks, each assigned to variables in a text document, I can display the blocks with
Code:
. $HOME/.wifi-connect/netblocks
echo $A{a..z}
, and also display a selector with
Code:
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:
$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:
# 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:
echo "$Ag" >/tmp/PIPE

but not from the code which is
Code:
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?
2018-07-06-123128_1218x308_scrot.png
Description  ow it should look
png

 Download 
Filename  2018-07-06-123128_1218x308_scrot.png 
Filesize  85.11 KB 
Downloaded  94 Time(s) 
2018-07-06-122408_402x433_scrot.png
 Description   
 Filesize   24.29 KB
 Viewed   649 Time(s)

2018-07-06-122408_402x433_scrot.png

Back to top
View user's profile Send private message MSN Messenger 
misko_2083


Joined: 08 Nov 2016
Posts: 55

PostPosted: Sat 07 Jul 2018, 10:59    Post subject:  

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!

Laughing 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:
echo "$Ag" >/tmp/PIPE

but not from the code which is
Code:
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:
#!/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
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2264
Location: In The Way

PostPosted: Sun 08 Jul 2018, 12:39    Post subject:  

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
Back to top
View user's profile Send private message MSN Messenger 
misko_2083


Joined: 08 Nov 2016
Posts: 55

PostPosted: Sun 08 Jul 2018, 16:58    Post subject:  

stemsee wrote:
Thanks misko
It works perfectly.
thanks again
stemsee

Нема проблема.
ХаЈде, у здравље и весеље, Стемси. Very Happy
Живели.

stemsee wrote:
At first I copied from the webpage and pasted into geany etc it didn't work until I reformatted it.

Maybe it's web browser related. There are similar issues for me with code formating in google groups.

I always мanually enter the BBCode tags.
Code:
[code]

[/code]
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2264
Location: In The Way

PostPosted: Tue 17 Jul 2018, 06:39    Post subject:  

Yad colour columns
I think someone shared this before, but I just (re) discovered it!
Code:
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"
2018-07-17-113511_267x237_scrot.png
 Description   
 Filesize   16.05 KB
 Viewed   459 Time(s)

2018-07-17-113511_267x237_scrot.png

2018-07-17-113441_285x238_scrot.png
 Description   
 Filesize   13.69 KB
 Viewed   459 Time(s)

2018-07-17-113441_285x238_scrot.png

Back to top
View user's profile Send private message MSN Messenger 
misko_2083


Joined: 08 Nov 2016
Posts: 55

PostPosted: Tue 17 Jul 2018, 08:47    Post subject:  

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

With font:
Code:
 yad --list --column="Column Name" --column="@fore@" --column="@back@" --column="@font@" "red text" "#ff0000" "#ffff00" "Ubuntu 15" "black text" "#000000" "#90EE90" "Arial" "yellow text" "#ffff00" "#0000FF" "Droid bold italic 20" "green text" "#90EE90" "#ff0000" "Sans italic 20"
yad-special-columns.png
 Description   
 Filesize   13.5 KB
 Viewed   426 Time(s)

yad-special-columns.png

Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2264
Location: In The Way

PostPosted: Wed 18 Jul 2018, 04:39    Post subject:  

That reminds me of my old msx computer's game graphics! Laughing
Back to top
View user's profile Send private message MSN Messenger 
lika

Joined: 06 Aug 2018
Posts: 6

PostPosted: Mon 06 Aug 2018, 23:57    Post subject:  

Hello misko_2083.

Can you help me solve the problem with a script. I modified your youtube-dl script, but without success.
I wish to add the forms with checkboxes and progress (with --enable- log) to an window. It's like appinstaller, checkboxes call scripts and when the archive is unpacked, a final dialog pops up.
For a week now I can't solve the problem, it does not work. Sad

It looks like this:

(this is merging layers in the GIMP) in fact it turns out either checkboxes or progress

Code:
#!/bin/bash

export faextraxt='@bash -c "install_app %1"'

# We need this to store the youtube PID
export fapid=$(mktemp -u --tmpdir fpid.XXXXXXXX)

export fapipe=$(mktemp -u --tmpdir ftd.XXXXXXXX)
mkfifo "$fapipe"
export fapipetwo=$(mktemp -u --tmpdir ftd2.XXXXXXXX)
mkfifo "$fapipetwo"

trap "rm -f $fapipe $fapipetwo $fapid" EXIT

fakey=$(($RANDOM * $$))

function install_app
{
  echo "2:@disable@"

# Check if the URL is valid with the spider
if wget -q --spider "$1"; then
  echo "#Preparing to download" >> "$fapipe"

   >"$fapid"
   while read line; do
     if [[ "$(echo $line | grep '[0-9]*%')" ]];then
        percent=$(echo $line | awk '{print $2}')
        echo "${percent%.*}%" >> "$fapipe"
     fi

     if [[ "$(echo $line | grep '\[download\]')" ]];then
        progress=$(echo $line | awk '{$1=""; print $0}')
        echo "#$progress" >> "$fapipe"
     fi
   done < "$fapipetwo" &
   LOOP_PID="$!"

    tar xf archive.tar.xz 2>&1 >> $fapipetwo & \
    echo $! > "$fapid"
    wait $!

    if [[ "$?" = 0 ]]
      then
         echo "100%" >> "$fapipe"
         echo "#Download completed." >> "$fapipe"
         kill "$LOOP_PID"
    elif [[ ! -s "$fapid" ]]; then
         echo "#Download canceled" >> "$fapipe"
         kill "$LOOP_PID"
    else
         echo "#Download error" >> "$fapipe"
         kill "$LOOP_PID"
    fi
else
    echo "#Invalid URL" >> "$fapipe"
fi

    echo "2:$faextraxt"
}
export -f install_app

function get_pid_and_kill () {
if [[ -s "$fapid" ]]; then
  BCKUPID="$(<$fapid)"
  >"$fapid"
  kill $BCKUPID 2>/dev/null
fi
}
export -f get_pid_and_kill

exec 3<> $fapipe
exec 4<> $fapipetwo

yad --plug="$fakey" --tabnum=1 --form --field "Choose a folder:DIR" "$HOME" \
--field="Install!system-software-install:fbtn" "$faextraxt" &

#yad --plug="$fakey" --tabnum=2 --form --field="Add a shortcut in the applications menu:CHK" --field="Add a desktop shortcut:CHK" <&3 &

yad --plug="$fakey" --tabnum=2 --window-icon="$ICON" --progress \
--enable-log="Show log" --log-height=100 --tail --borders=5 <&3 &


yad --paned --key="$fakey" --buttons-layout=edge --button="gtk-close:0" \
--button="Abort":'bash -c "get_pid_and_kill" 2>/dev/null' --text="" \--title="TEST" --window-icon="$ICON" --center

exec 3>&-
exec 4>&-


Thank you in advance.
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 55

PostPosted: Tue 07 Aug 2018, 07:28    Post subject:  

stemsee wrote:
That reminds me of my old msx computer's game graphics! Laughing

You must have had a lot of 8-bit fun.
The first one I had had a pentium 1 MMX on 233MHz and 32 MB of RAM. Smile

lika wrote:
Hello misko_2083.

Can you help me solve the problem with a script. I modified your youtube-dl script, but without success.
I wish to add the forms with checkboxes and progress (with --enable- log) to an window. It's like appinstaller, checkboxes call scripts and when the archive is unpacked, a final dialog pops up.
For a week now I can't solve the problem, it does not work. Sad

I made an example with for one loop as the main process so you can see how the data is flowing to the progress bar.
The form fields are now restored.
Also you may want to disable the form fields while installing. Added that too.


Code:
#!/bin/bash

export faextraxt='bash -c "install_app \"%1\" %2 %3 %4"'

# We need this to store the youtube PID
export main_proc_id=$(mktemp -u --tmpdir fpid.XXXXXXXX)

export progress_pipe=$(mktemp -u --tmpdir ftd.XXXXXXXX)
mkfifo "$progress_pipe"

export percentage_pipe=$(mktemp -u --tmpdir ftd2.XXXXXXXX)
mkfifo "$percentage_pipe"

export form_pipe=$(mktemp -u --tmpdir ftd3.XXXXXXXX)
mkfifo "$form_pipe"

trap "rm -f $progress_pipe $percentage_pipe $form_pipe $main_proc_id" EXIT

fakey=$(($RANDOM * $$))

function install_app
{

# Form fields are read in a cycle 1-4, each cycle sets new values

# Disables all the form fields when the install starts
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"

echo "#Selected extraction path: $1" >> "$progress_pipe"
echo "#" >> "$progress_pipe"
echo "#Add a shortcut in the applications menu : $2" >> "$progress_pipe"
echo "#Add a desktop shortcut : $3" >> "$progress_pipe"
echo "#" >> "$progress_pipe"

  echo "#Preparing to extract..." >> "$progress_pipe"

   >"$main_proc_id"
   while read line; do
     if [[ "$(echo $line | grep '[0-9]*%')" ]];then
        percent=$(echo $line | awk '{print $2}')
        echo "${percent%.*}%" >> "$progress_pipe"
        echo "$line" >> "$progress_pipe"
     fi

     echo "#$line" >> "$progress_pipe"

   done < "$percentage_pipe" &
   LOOP_PID="$!"

    # main process example for a demonstration purpose
    for i in {1..100}; do echo "$i %" 2>&1 >> $percentage_pipe; sleep .1; done & echo $! > "$main_proc_id"
   
    # You would probably do something like this
    # tar xf archive.tar.xz 2>&1 >> $percentage_pipe & echo $! > "$main_proc_id"

    # Wait here
    # Wait returns exit status ${?}
    # It's stderr is redirected to /dev/null to prevent kill command to print messages
    wait $(<$main_proc_id) 2>/dev/null

    if [[ "$?" = 0 ]]
      then
         echo "100%" >> "$progress_pipe"
         echo "#Install completed." >> "$progress_pipe"
         kill "$LOOP_PID"
    elif [[ ! -s "$main_proc_id" ]]; then
         echo "#Install canceled." >> "$progress_pipe"
         kill "$LOOP_PID"
    else
         echo "#Install error." >> "$progress_pipe"
         kill "$LOOP_PID"
    fi


    # Strips quotes from stored path
    install_dir="${1#\'}"
    install_dir="${install_dir%\'}"

    # Resets the field values when the install ends
    echo "${install_dir}" > $form_pipe
    echo "$2" > $form_pipe
    echo "$3" > $form_pipe
    echo "$faextraxt &" > $form_pipe
}
export -f install_app


function get_pid_and_kill () {
if [[ -s "$main_proc_id" ]]; then
  BCKUPID="$(<$main_proc_id)"
  >"$main_proc_id"
  kill $BCKUPID 2>/dev/null
fi
}
export -f get_pid_and_kill

exec 3<> $progress_pipe
exec 4<> $percentage_pipe
exec 5<> $form_pipe

yad --plug="$fakey" --tabnum=1 --form \
    --field="Choose a folder:DIR" \
    --field="Add a shortcut in the applications menu:CHK" \
    --field="Add a desktop shortcut:CHK" \
    --field="Install!system-software-install:fbtn" --cycle-read <&5 &

    # This is the initial cycle that sets the form field values
    echo "${HOME}" > $form_pipe
    echo "TRUE" > $form_pipe
    echo "FALSE" > $form_pipe
    echo "$faextraxt &" > $form_pipe

yad --plug="$fakey" --tabnum=2 --window-icon="$ICON" --progress \
--enable-log="Show log" --log-height=100 --tail --borders=5 <&3 &


yad --paned --key="$fakey" --buttons-layout=edge --button="gtk-close:0" \
--button="Abort":'bash -c "get_pid_and_kill" 2>/dev/null' --text="" --title="TEST" --window-icon="$ICON" --center

exec 3>&-
exec 4>&-
exec 5>&-
Back to top
View user's profile Send private message 
lika

Joined: 06 Aug 2018
Posts: 6

PostPosted: Tue 07 Aug 2018, 19:13    Post subject:  

misko_2083 wrote:

I made an example with for one loop as the main process so you can see how the data is flowing to the progress bar.
The form fields are now restored.
Also you may want to disable the form fields while installing. Added that too.

Oh, it's great. Thank you very much!

How to print a realtime unpacking log from xz (gz, 7z whatever) to YAD log spoiler instead process simulation? And call a popup dialog if the "Abort" or "Close" or window close button pressed during installation?

I chose the path to extract, but:
Code:
tar: Error is not recoverable: exiting now


I add "$1" as a destination folder to the tar:
Code:
tar xfv archive.tar.xz -C "$1" 2>&1 >> $percentage_pipe & echo $! > "$main_proc_id"

and now:
Code:
tar: '/home/lika/local apps': Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

It looks like the script doesn't find the specified folder because that folder is not in the current folder where the script is located.
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3394
Location: holland

PostPosted: Wed 08 Aug 2018, 03:06    Post subject:  

lika wrote:
I add "$1" as a destination folder to the tar:
Code:
tar xfv archive.tar.xz -C "$1" 2>&1 >> $percentage_pipe & echo $! > "$main_proc_id"


That works for me if I remove the slashes (and quotes after them) on line 3, so becomes this:
Code:
export faextraxt='bash -c "install_app %1 %2 %3 %4"'


Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
lika

Joined: 06 Aug 2018
Posts: 6

PostPosted: Wed 08 Aug 2018, 03:49    Post subject:  

fredx181 wrote:

That works for me if I remove the slashes (and quotes after them) on line 3, so becomes this:
Code:
export faextraxt='bash -c "install_app %1 %2 %3 %4"'


Fred

In this case the archive.tar.zx is unpacked in the same folder where is it located.
Regardless of the specified path.
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3394
Location: holland

PostPosted: Wed 08 Aug 2018, 04:41    Post subject:  

lika wrote:
fredx181 wrote:

That works for me if I remove the slashes (and quotes after them) on line 3, so becomes this:
Code:
export faextraxt='bash -c "install_app %1 %2 %3 %4"'


Fred

In this case the archive.tar.zx is unpacked in the same folder where is it located.
Regardless of the specified path.


Strange.. works for me to extract to folder of choice, with this tar extract line the way you changed:
Code:
tar xfv app.tar.xz -C "$1" 2>&1 >> $percentage_pipe & echo $! > "$main_proc_id"


Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
lika

Joined: 06 Aug 2018
Posts: 6

PostPosted: Wed 08 Aug 2018, 04:48    Post subject:  

fredx181 wrote:

Strange.. works for me to extract to folder of choice, with this tar extract line the way you changed:
Code:
tar xfv app.tar.xz -C "$1" 2>&1 >> $percentage_pipe & echo $! > "$main_proc_id"

Yes, pathing works. My previous post was wrong.

And how to print a original realtime unpacking log (which can be seen in the terminal) from xz, gz etc to YAD log spoiler instead percentages simulation + call a popup dialog ("Are you sure you want to cancel the installation?) while "Abort" or "Close" or window close button pressed.

I tried to apply the "--wrap" option for the log spoiler, but seems it not affected for progress form or I'm doing something wrong.
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3394
Location: holland

PostPosted: Wed 08 Aug 2018, 07:32    Post subject:  

lika wrote:
And how to print a original realtime unpacking log (which can be seen in the terminal) from xz, gz etc to YAD log spoiler instead percentages simulation


There is some output, but not all, I think commenting out some lines starting at line 41, change to:
Code:
   while read line; do
#     if [[ "$(echo $line | grep '[0-9]*%')" ]];then
#       percent=$(echo $line | awk '{print $2}')
#        echo "${percent%.*}%" >> "$progress_pipe"
        echo "$line" >> "$progress_pipe"
#     fi

Then I see all output from tar.

Your other question can be answered better by misko, I guess.

Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 30 of 35 [512 Posts]   Goto page: Previous 1, 2, 3, ..., 28, 29, 30, 31, 32, 33, 34, 35 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2247s ][ Queries: 12 (0.0459s) ][ GZIP on ]