YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
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

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

#441 Post by misko_2083 »

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

Code: Select all

 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"
Attachments
yad-special-columns.png
(13.5 KiB) Downloaded 737 times

stemsee

#442 Post by stemsee »

That reminds me of my old msx computer's game graphics! :lol:

lika
Posts: 7
Joined: Tue 07 Aug 2018, 01:30

#443 Post by lika »

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. :(

It looks like this:
Image
(this is merging layers in the GIMP) in fact it turns out either checkboxes or progress

Code: Select all

#!/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.

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

#444 Post by misko_2083 »

stemsee wrote:That reminds me of my old msx computer's game graphics! :lol:
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. :)
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. :(
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.
Image

Code: Select all

#!/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>&-

lika
Posts: 7
Joined: Tue 07 Aug 2018, 01:30

#445 Post by lika »

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: Select all

tar: Error is not recoverable: exiting now
I add "$1" as a destination folder to the tar:

Code: Select all

tar xfv archive.tar.xz -C "$1" 2>&1 >> $percentage_pipe & echo $! > "$main_proc_id"
and now:

Code: Select all

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.

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

#446 Post by fredx181 »

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: Select all

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

lika
Posts: 7
Joined: Tue 07 Aug 2018, 01:30

#447 Post by lika »

fredx181 wrote: That works for me if I remove the slashes (and quotes after them) on line 3, so becomes this:

Code: Select all

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.

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

#448 Post by fredx181 »

lika wrote:
fredx181 wrote: That works for me if I remove the slashes (and quotes after them) on line 3, so becomes this:

Code: Select all

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: Select all

tar xfv app.tar.xz -C "$1" 2>&1 >> $percentage_pipe & echo $! > "$main_proc_id"
Fred

lika
Posts: 7
Joined: Tue 07 Aug 2018, 01:30

#449 Post by lika »

fredx181 wrote: Strange.. works for me to extract to folder of choice, with this tar extract line the way you changed:

Code: Select all

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.

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

#450 Post by fredx181 »

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: Select all

   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

lika
Posts: 7
Joined: Tue 07 Aug 2018, 01:30

#451 Post by lika »

fredx181 wrote: There is some output, but not all, I think commenting out some lines starting at line 41, change to:

Code: Select all

   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.
Fred
Thank you.
I'll see.

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

#452 Post by misko_2083 »

Thanks fredx181, don't know why I thought that DIR field in the form dialog doesn't quote the path. :roll:

lika Added pv command to display the progress. One more dependancy to install but I see no other way for now.

X window button is managed by the window manager so intercepting it is impossible. It's only possible to get the exit status 252 when the window is closed via X.That's why I added undecoratzed to pprevent the paned dialog from closing and --no-escape to prevent closing the same dialog if Escape was pressed. That is the simplest solution. Anything else would be too complex.

To use the checkboxes in the function install_app you would need to check if $2 and $3 are true or false.

The script now displays extra dialogs and prevents them from opening multiple times e.g.if the cancel and abort buttons are clicked several times. This is working for me:

Code: Select all

#!/bin/bash

if ! hash pv; then
   yad --text "install pv first"
   exit 1
fi

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

# We need this to store the main proces ID
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 -r line; do
     # If line is a integer number
     if [[ "$line" == +([0-9]) ]];then
        echo "$line" >> "$progress_pipe"
     else
        echo "#$line" >> "$progress_pipe"
     fi

   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"
    
    pv -n archive.tar.xz 2>$percentage_pipe | xzcat | tar xp -C "$1" -v 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"
         >$main_proc_id
         yad --text="Install successfull" --button="gtk-ok:0"  &
    elif [[ ! -s "$main_proc_id" ]]; then
         echo "#Install canceled." >> "$progress_pipe"
         kill "$LOOP_PID"
         >$main_proc_id
    else
         echo "#Install error." >> "$progress_pipe"
         kill "$LOOP_PID"
         >$main_proc_id
    fi

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

function get_pid_and_kill () {
Sure_Command='yad --text=Are you sure you want to cancel the installation? --button=gtk-yes:0 --button=gtk-no:1'
Sure_Command_PID="$(ps -eo pid,cmd | grep -F "$Sure_Command" | grep -v "grep" | awk '{ print $1 }')"

if [[ -s "$main_proc_id" ]] && [[ "$Sure_Command_PID" == "" ]] && yad --text="Are you sure you want to cancel the installation?" --button="gtk-yes:0" --button="gtk-no:1"; then
  if [[ -s "$main_proc_id" ]]; then
     BCKUPID="$(<$main_proc_id)"
     >"$main_proc_id"
     kill $BCKUPID 2>/dev/null
     sleep 1
  fi
   # The special yad variable $YAD_PID stores the main window PID
   # killing that PID closes the window
  [[ "$1" == "CLOSE" ]] && kill -s SIGUSR1 $YAD_PID
elif [[ ! -s "$main_proc_id" ]] ; then
  [[ "$1" == "CLOSE" ]] && kill -s SIGUSR1 $YAD_PID
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         # set default folder in this line
    echo "TRUE" > $form_pipe               # default first checkbox value
    echo "FALSE" > $form_pipe              # default second checkbox value
    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":'bash -c "get_pid_and_kill CLOSE" 2>/dev/null' \
    --button="Abort!gtk-stop":'bash -c "get_pid_and_kill" 2>/dev/null' \
    --text="" --title="TEST" --window-icon="$ICON" --center \
    --no-escape --undecorated & MAIN_PID=$!

# Redirecting kill output from get_pid_and_kill function to /dev/null
wait $MAIN_PID 2>/dev/null

exec 3>&-
exec 4>&-
exec 5>&-

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

#453 Post by misko_2083 »

by the way fred, discovered something by accident.

killing $YAD_PID in the beginning of funcion install_app, closes the first tab and the second tab goes to the top of the paned window. :shock:
The progress continues to run. :lol:

Code: Select all

.....

function install_app
{
# Check this out
kill $YAD_PID

# 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"

....

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

#454 Post by fredx181 »

Always your scripts are very educational misko, thanks !
I'm still struggling to understand these pipes and paned thing, but I'll get there probably... some day :wink:

Fred

stemsee

#455 Post by stemsee »

fredx181 wrote:Always your scripts are very educational misko, thanks !
I'm still struggling to understand these pipes and paned thing, but I'll get there probably... some day :wink:

Fred
Ditto (echo) that sentiment!

I have many questions :?
stemsee

Post Reply