You are not logged in.

#101 2019-01-09 12:33:11

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

^ yes thats it, thanks damo.

--button=gtk-cancel:1 \
--button="Killall Conky":kill-conky \

Offline

#102 2019-01-09 13:54:07

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

Yad conky chooser v0.2. Bit better looking than the list option. Bunsenlabs conky manager is a work of art, much better control. I wonder is there ability for yad to do what bl conky manager can do?

2019-01-09--1547041697_467x305_scrot.th.png

#!/bin/bash

yad --title="Conky Chooser" --form --center --on-top --width=300 --height=200 --window-icon=utilities-system-monitor --width=250 \
--field="NL-Conky":fbtn 'conky -c "/home/s7/.config/conky/nl.conky.conf"' \
--field="BL-Top Conky":fbtn 'conky -c"/home/s7/.config/conky/BL conkys/BL-Top.conkyrc"' \
--field="Bar-Conky":fbtn 'conky -c "/home/s7/.config/conky/bar.conky.conf"' \
--button="Killall Conky":kill-conky \
--button="Restart Conky":conkyrestart \
--button=gtk-cancel:1

Offline

#103 2019-01-09 19:48:02

damo
....moderator....
Registered: 2015-08-20
Posts: 4,966

Re: The great yad hacking thread

S7.L wrote:

... I wonder is there ability for yad to do what bl conky manager can do?

Well, the BL conky manager uses yad as the graphical interface for the script. Yad needs something behind the scenes to operate anything constructively!


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#104 2019-01-12 15:22:32

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: The great yad hacking thread

Too bad there is no a way to detect anything within html dialog.

I haven't used that dialog much just played with some photo loading/preview.

https://i.imgur.com/Pugp1CRm.png
yad --width=800 --height=600 --html --uri=/home/misko/Desktop/test.html

test.html

 <!DOCTYPE html>
<html>
<body>



 <script src="https://code.jquery.com/jquery-2.2.4.min.js" async="async"></script>
    <link rel="stylesheet" media="all" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />

<style>
  .thumb {
    height: 300px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;
  }
</style>

example 1

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form1" runat="server">
  <input type='file' id="imgInp" />
  <img id="blah" class="thumb" src="#" alt="your image" />
</form>
<script>
function readURL(input) {

  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('#blah').attr('src', e.target.result);
    }

    reader.readAsDataURL(input.files[0]);
  }
}

$("#imgInp").change(function() {
  readURL(this);
});

</script>

<p>example 2</p>



<input type="file" id="files" style="display:none" accept="image/x-png,image/gif,image/jpeg" name="files[]" multiple />
<a href="javascript:;" onclick="getImage()"/>
    <img src="/usr/share/icons/Faenza/actions/32/gtk-open.png"/>
</a>
<output id="list"></output>

<script>
     function getImage(){
       $('#files').click();
     }
</script>

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {

      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }

      var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          var span = document.createElement('span');
          span.innerHTML = ['<img class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, null);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);

</script>
</body>
</html> 

Last edited by misko_2083 (2019-01-12 15:24:36)

Offline

#105 2019-01-13 15:22:08

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

Using a bit different config...

yad --width 200 --height 400 --title "CONKY" --form --center --on-top --width=300 --height=200 --window-icon=utilities-system-monitor --width=250 \
    --form \
    --field="Conky Bar:BTN" 'conky -c  "/home/s7/.config/conky/bar.conky.conf"' \
    --field="Conky NL:BTN" 'conky -c  "/home/s7/.config/conky/nl.conky.conf"' \
    --field="Conky BL-Top:BTN" 'conky -c  "/home/s7/.config/conky/BL-Top.conf"' \
    --field="Restart Conky":fbtn "conkyrestart" \
    --field="Kill Conky":fbtn "kill-conky" \

2019-01-14-011841_1366x768_scrot.th.png

I would like to space those cancel and ok buttons better.

^just use this...

--button=gtk-close:1

Last edited by S7.L (2019-01-13 15:33:48)

Offline

#106 2019-01-14 00:02:09

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: The great yad hacking thread

^ I gave it a shot with --html and yad v.40

#!/bin/bash

stdbuf -oL -eL yad --title="Conky Chooser" \
                    --width=400 --height=250 \
                    --html --uri="/home/misko/Desktop/test2.html" \
                    --button=gtk-cancel:1 \
                    --print-uri 2>&1 \
| while read -r line; do
     case ${line##*/} in
      gg)
        conky -c  "/home/s7/.config/conky/bar.conky.conf" ;;
      bb)
        conky -c  "/home/s7/.config/conky/nl.conky.conf" ;;
      ee)
        conky -c  "/home/s7/.config/conky/BL-Top.conf" ;;
      restart)
        conkyrestart ;;
      kill)
        kill-conky ;;
      *) echo "unknown command" ;;
     esac
done

And here's "frontend" smile in test2.html
-javascript prevents context menu popup-

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.body {
  background-color: #CECECE;
}

.btn {
  border: 2px solid black;
  background-color: white;
  color: black;
  padding: 14px 28px;
  font-size: 16px;
  cursor: pointer;
}

/* Green */
.bar {
  border-color: #4CAF50;
  color: green;
  text-decoration: none;
}

.bar:hover {
  background-color: #4CAF50;
  color: white;
}

/* Blue */
.bl {
  border-color: #2196F3;
  color: dodgerblue;
  text-decoration: none;
}

.bl:hover {
  background: #2196F3;
  color: white;
  text-decoration: none;
}

/* Orange */
.bltop {
  border-color: #ff9800;
  color: orange;
  text-decoration: none;
}

.bltop:hover {
  background: #ff9800;
  color: white;
  text-decoration: none;
}

/* Red */
.restart{
  border-color: #f44336;
  color: red;
  text-decoration: none;
}

.restart:hover {
  background: #f44336;
  color: white;
}

/* Gray */
.default {
  border-color: #000000;
  color: black;
  text-decoration: none;
}

.default:hover {
  background: #000000;
  color: white;
  text-decoration: none;
}
</style>

<script type="text/javascript">
    if (document.addEventListener) { // IE >= 9; other browsers
        document.addEventListener('contextmenu', function(e) {
            //here you do nothing on right-click
            e.preventDefault();
        }, false);
    } else { // IE < 9
        document.attachEvent('oncontextmenu', function() {
            alert("You've tried to open context menu");
            window.event.returnValue = false;
        });
    }
</script>

</head>
<body class="body">

<div 
 style="-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;-o-user-select:none;" 
 unselectable="on"
 onselectstart="return false;" 
 onmousedown="return false;">
<h1>S7.Conky</h1>

<a href="gg" class="btn bar">Bar</a>
<a href="bb" class="btn bl">BL</a>
<a href="ee" class="btn bltop">BL-Top</a>
<br></br>
<br></br>
<a href="restart" class="btn restart">Restart Conky</a>
<a href="kill" class="btn default">Stop Conky</a>

</div>

</body>
</html>

Scrrenshot
4Uup5ez.gif
Sorry about bad looking buttons, I'm not a web developer. smile

Offline

#107 2019-01-15 11:16:54

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

^ Thats very cool misko thankyou, is that something like electron? I wouldnt have a clue how to do that sort of thing, ive dabbled a bit in html and css but not ever puting it together with say a bash script.

Offline

#108 2019-01-16 14:06:20

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: The great yad hacking thread

S7.L this is something like Ubuntu Mate Welcome screen. Except with UMW it's used python webkit for front end and in back end it's python. Like having two layers that communicate.
One that is used to interact with user and the other one to do everything else.

With python much more can be done with ease, like creating and modifying the front end.
With Yad's webkit that would probably be hard to do. Though as a simple launcher like "launch and forget" it can be useful.

Offline

#109 2019-02-04 11:52:05

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

Im trying to create my own cancel button instead of using the gtk cancel button shipped with yad, i think i have it figured but i dont like the fact this command kills all instances of yad, i just want it to cancel the exit dialog only, so basically kill itself lol. Is that possible? Im using the --no-buttons flag so it doesn't show the cancel or ok buttons.

yad --no-buttons --form --width=250 --center --on-top --undecorated --text-align="center" --text="Exit Artix" \
--field="logout":fbtn "openbox --exit" \
--field="reboot":fbtn "sudo reboot" \
--field="poweroff":fbtn "sudo poweroff" \
--field="lock":fbtn "slock" \
--field="cancel":fbtn "yad-cancel" \

Edit:

Probably not the best solution but it works, find and kill a process in regex.

Found here: https://stackoverflow.com/questions/351 … -and-regex

script is called "yad-cancel" and gets called by last field fbtn in the yad script.

#!/bin/bash

kill $(ps aux | awk '/Exit Artix/ {print $2}')

Edit 2. No need for grep.

Last edited by S7.L (2019-02-04 14:35:15)

Offline

#110 2019-02-04 15:21:59

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

Ok so i figured it out in the one script instead of calling another with the use of a function. Very cool smile

#!/bin/bash

yad-cancel() {
	kill $(ps aux | awk '/Exit Artix/ {print $2}')
}

yad --no-buttons --form --width=250 --center --on-top --undecorated --text-align="center" --text="Exit Artix" \
--field="logout":fbtn "openbox --exit" \
--field="reboot":fbtn "sudo reboot" \
--field="poweroff":fbtn "sudo poweroff" \
--field="lock":fbtn "slock" \
yad-cancel --field="cancel":fbtn ""\

Offline

#111 2019-02-04 17:46:27

damo
....moderator....
Registered: 2015-08-20
Posts: 4,966

Re: The great yad hacking thread

Or get the process id when you first start yad, then use that to kill it

yad
yadPID=$!

...

kill $yadPID

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#112 2019-02-05 00:14:49

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: The great yad hacking thread

You can use the variable YAD_PID
but first export the function.

#!/usr/bin/env bash

yad-cancel() {
	kill -USR1 $YAD_PID
}
export -f yad-cancel

yad --no-buttons --form --width=250 \
--center --on-top --undecorated --text-align="center" \
--text="Exit Artix" \
--field="logout":fbtn "openbox --exit" \
--field="reboot":fbtn "sudo reboot" \
--field="poweroff":fbtn "sudo poweroff" \
--field="lock":fbtn "slock" \
--field="cancel":fbtn "bash -c yad-cancel"

If you use SIGUSR1 exit is 0
with SIGUSR2 exit is 1.

Offline

#113 2019-02-05 08:16:31

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

^^ thanks for that damo and misko, seems my script was way off and stopped working which is weird because it was working yesterday.

I actually tried " Kill -USR1 $YAD_PID" in the functionbut was unsure how to call in the field button, so that helped me understand a bit better misko, thanks.

so export -f

Options
      -f   The names refer to shell functions; 
           otherwise the names refer to shell variables.

and bash -c

      -c        If the -c option is present, then commands are read from the
                 first non-option argument command_string.  If there are
                 arguments after the command_string, the first argument is
                 assigned to $0 and any remaining arguments are assigned to
                 the positional parameters.  The assignment to $0 sets the
                 name of the shell, which is used in warning and error
                 messages.

Offline

#114 2019-02-05 13:25:45

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

Back again, i love yad.

I cant take full credit for this as i found it here http://smokey01.com/yad/.

But i modified it to suit, so this is a feh wallpaper picker, unfortunatly it just shows you a list of where you keep your wallpapers and when you double click a directory item in the list it sets the background wallpaper in scale mode eg; --bg-scale.
This could be hacked so much more to be similar to nitrogen i think.

So once you set an image to background feh in its awesomeness created ~/.fehbg script you can autostart from .xinitrc or openbox autostart or where programs you autostart are.

#!/usr/bin/env bash

yad --title="--dclick-action=CMD" --width=700 --height=400 --separator=" " --list --dclick-action="feh --bg-scale" --column=Fehpicker $HOME/Pictures/Walls/*

scrot..

2019-02-05-232531_1366x768_scrot.th.png

Offline

#115 2019-02-05 16:20:15

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: The great yad hacking thread

^ very handy

just one thing yad list complains about file names with some special characters.

(yad:8206): Gtk-WARNING **: Failed to set text from markup due to error parsing markup: Error on line 1: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp;

It's best to use --no-markup for that reason

yad --title="Feh picker" --width=700 --height=400 --separator=" " --list  --no-markup --dclick-action="feh --bg-scale" --column=Fehpicker $HOME/Pictures/*

Offline

#116 2019-02-06 10:54:57

S7.L
Member
Registered: 2018-09-16
Posts: 338

Re: The great yad hacking thread

^ I didn't get that gtk warning when i run it from the terminal but i will definitely take your word for it and add it in.

Offline

#117 2019-02-06 19:12:11

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: The great yad hacking thread

S7.L wrote:

^ I didn't get that gtk warning when i run it from the terminal but i will definitely take your word for it and add it in.

It happens when you have an ampersand '&' in the filename.
You can try:

yad --list --column="1" "&"

Offline

#118 2019-03-31 12:37:13

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: The great yad hacking thread

The little installer/unpacker I'm making.
It will use tar to unpack the archive and pv to display the progress bar.

This is only a simulation, no unpacking is done.

#!/bin/bash

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

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

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

export APP_TITLE="=TEST="

export faextraxt='bash -c "install_app %1 %2 %3 %4"'
export faeclose='bash -c "get_pid_and_kill $1" 2>/dev/null'

# 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 () {

   # Sets form fields in a cycle 1-8

   # Disables all the form fields except abort when the install starts
   echo "@disabled@" > "$form_pipe"
   echo "@disabled@" > "$form_pipe"
   echo "@disabled@" > "$form_pipe"
   echo "@disabled@" > "$form_pipe"
   echo "@disabled@" > "$form_pipe"
   echo "$faeclose &" > "$form_pipe" # 6: Abort button
   echo "@disabled@" > "$form_pipe"
   echo "@disabled@" > "$form_pipe"

   echo "#Selected extraction path: $1" >> "$progress_pipe"
   echo "#" >> "$progress_pipe"

   if [[ "$2" == TRUE ]]
   then
       # Handle shortcut in the applications menu
       echo "#Add a shortcut in the applications menu : $2" >> "$progress_pipe"
   fi

   if [[ "$3" == TRUE ]]
   then
       # Handle desktop shortcut
       echo "#Add a desktop shortcut : $3" >> "$progress_pipe"
   fi

   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
         [ $(( $i % 10 )) -eq 0 ] && echo "#$i %" >> "$progress_pipe"
         sleep .1
     done & echo $! > "$main_proc_id"
    # ------------------------------------------------

    # main process
    #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
    echo "@disabled@" > "$form_pipe"
    echo "@disabled@" > $form_pipe
    echo "$faeclose  CLOSE &" > $form_pipe
    echo "" > "$form_pipe"
}
export -f install_app

function get_pid_and_kill () {
   XWININFO=$(xwininfo -name "$APP_TITLE")
   ARRAY=(${XWININFO#* id: })
   YY_PID=$(xprop -id ${ARRAY[0]} _NET_WM_PID | awk '{print $3}')

   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" == "" ]]; then
  if yad --text="Are you sure you want to cancel the installation?" --button="gtk-yes:0" --button="gtk-no:1" --close-on-unfocus; then
     if [[ -s "$main_proc_id" ]]; then
        BCKUPID="$(<$main_proc_id)"
        >"$main_proc_id"
        kill $BCKUPID 2>/dev/null
        sleep 1
     fi
  fi

  [[ "$1" == "CLOSE" ]] && kill -s SIGUSR1 $YY_PID
elif [[ ! -s "$main_proc_id" ]] ; then
  [[ "$1" == "CLOSE" ]] && kill -s SIGUSR1 $YY_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" \
    --field=":LBL" \
    --field="Abort!gtk-cancel:BTN" \
    --field="Close!gtk-close:BTN" \
    --field=":LBL" --cycle-read <&5 >/dev/null &

# 1: folder selection
# 2: checkbox
# 3: checkbox
# 4: install button
# 5: horizontal line
# 6: abort button
# 7: close Button
# 8: horizontal line

    # This is the initial cycle that sets the form field values on start
    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
    echo "" > "$form_pipe"
    echo "@disabled@" > $form_pipe
    echo "$faeclose CLOSE &" > $form_pipe
    echo "" > "$form_pipe"                 # empty label is a horizontal line

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


yad --paned --key="$fakey" --buttons-layout=edge \
    --text="" --title="$APP_TITLE" --window-icon="$ICON" --center \
    --no-escape --undecorated  --no-buttons & export 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>&-

https://i.imgur.com/YA8EmTy.gif

Offline

#119 2019-04-11 12:14:16

Anton
New Member
Registered: 2019-04-11
Posts: 4

Re: The great yad hacking thread

misko_2083 wrote:

The little installer/unpacker I'm making.

This script doesn't work with GTK3 YAD.
Displayed some bar only.

//upd
Adding "--fixed" to "yad --paned..." makes GTK3 version work.

//upd2
This is your GTK3 YAD modified script by me, but Cancel-quit button (fbtn) only abort unpacking sad :

#!/bin/bash

export main_proc_id="$(mktemp -u --tmpdir fpid.XXXXXXXX)"
export progress_pipe="$(mktemp -u --tmpdir ftd.XXXXXXXX)"
mkfifo "$progress_pipe"
export form_pipe="$(mktemp -u --tmpdir ftd2.XXXXXXXX)"
mkfifo "$form_pipe"
trap 'rm -f "$main_proc_id" "$progress_pipe" "$form_pipe"' "EXIT"
export key="$(($RANDOM * $$))"
export unpack='bash -c "install_app %1 %2 %3 %4"'
export cancel_quit='bash -c "get_pid_and_kill $1" 2>/dev/null'
function install_app
{
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "$cancel_quit &" > "$form_pipe"

# Unpacking package
#COMMAND HERE DEPENDS ON ARCHIVER

wait "$(<$main_proc_id)" 2>/dev/null

if [ "$?" = "0" ]; then
	echo "#Installation completed" >> "$progress_pipe"
	kill "$main_pid" 2>/dev/null
	>"$main_proc_id"
else
	echo "#Installation canceled" >> "$progress_pipe"
	kill "$main_pid" 2>/dev/null
	>"$main_proc_id"
fi
}

export -f install_app

function get_pid_and_kill
{
sure_command='"yad --title=" " --width=1 \
	--text="Are you sure you want to cancel?" \
	--text-align=center	--on-top --center \
	--window-icon="system-software-install" \
	--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" == "" ]]; then
	if yad --title=" " --width=1 \
	--text="Are you sure you want to cancel?" \
	--text-align=center	--on-top --center \
	--window-icon="system-software-install" \
	--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
		fi
	fi
	[[ "$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<> "$form_pipe"

yad --paned --key="$key" --no-buttons \
--window-icon="system-software-install" --fixed \
--center --no-escape --splash & main_pid="$!"

yad --plug="$key" --tabnum=1 --form \
--field=" Select the destination path::DIR" \
--field=" Create a launcher in the applications menu:CHK" \
--field=" Create a launcher on the desktop:CHK" \
--field=" Begin Installation!system-software-install:fbtn" \
--field=" Cancel Installation and quit!gtk-quit:fbtn" \
--cycle-read <&4 &

echo "$HOME" > "$form_pipe"		# default directory
echo "TRUE" > "$form_pipe"		# default first checkbox value
echo "FALSE" > "$form_pipe"		# default second checkbox value
echo "$unpack &" > "$form_pipe"	# progress bar value

yad --plug="$key" --tabnum=2 --progress <&3 &

wait "$main_pid" 2>/dev/null

exec 3>&-
exec 4>&-

How to make the button immediately cancel all processes and close the window after confirm dialog?

ec0d08f889bc6b1b577b14a3f61e448a.jpeg 03ac36a831d3e9cf6a84a393f0049abb.jpeg 3d5bc36d358584ef82d2e4435e106879.jpeg

I made another working installer (similar on the screenshots above) with GTK2/3 YAD and percentage progress (without log expander), without pv etc, only YAD and archiver. But here is no way to give you a cloud link to its for testing.

I've a couple of questions for you about window manager. There is a script with pop-up dialog while close the window (after count actions):

#!/bin/bash

while true; do

Record=(`yad --text "Click Action button or close this window" \
        --width=400 --height=300 --center --button="Action":1`)
Action=$?

if [[ $Action == 1 ]]; then
    yad --width=300 --height=100 --title="Do you want to Action?" \
    --text "Click OK to confirm Action" --center
    ret=$?

    # Cancel = 252, OK = 0
    if [[ $ret == 0 ]]; then
    ((TransCount++))
        let i=1
    while [ $i -lt $ListArrCnt ]; do
        if [ ${ListArr[$i]} -eq ${RecArr[1]} ]; then
        # Matching record number
        j=$(($i - 1))
        k=$(($j + $RecArrCnt))
        while [ $j -lt $k ] ; do
            unset 'ListArr[$j]'
            j=$(($j + 1))
        done
        for i in "${!ListArr[@]}"; do
                NewArr+=( "${ListArr[$i]}" )
        done
        ListArr=("${NewArr[@]}")
        unset NewArr
        let i=$(($ListArrCnt + 1)) # force exit from while loop
        else
        let i=$(($i + $RecArrCnt)) # Check next entry
        fi
    done
    fi

elif [[ $Action == CLOSE ]] || [[ $Action == 252 ]]; then
    # Cancel-quit or X close the window or Escape
    if [[ $TransCount -gt 0 ]]; then
    yad --question --center --on-top --text "You have made $TransCount action(s). Do you really want to quit?"
    rc=$?
    if [[ $rc -eq 0 ]]; then
        exit
    fi
    else
    exit
    fi
fi

done

But I don't figure out how to do this in installer script, i.e. WM close button action the same as Cancel-quit.

Last edited by Anton (2019-04-12 13:58:45)

Offline

#120 2019-04-12 13:33:45

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: The great yad hacking thread

About the first issue:
  You have three dialogs
   1. paned
   2. form
   3. progress
And each of them sets YAD_PID variable.

Since you use SIGUSR1 signal in the form dialog it will not close the paned dialog.
You have to export the PID of the paned dialog and kill it when you want to quit.

#!/bin/bash

export main_proc_id="$(mktemp -u --tmpdir fpid.XXXXXXXX)"
export progress_pipe="$(mktemp -u --tmpdir ftd.XXXXXXXX)"
mkfifo "$progress_pipe"
export form_pipe="$(mktemp -u --tmpdir ftd2.XXXXXXXX)"
mkfifo "$form_pipe"
trap 'rm -f "$main_proc_id" "$progress_pipe" "$form_pipe"' "EXIT"
export key="$(($RANDOM * $$))"
export unpack='bash -c "install_app %1 %2 %3 %4"'
export cancel_quit='bash -c "get_pid_and_kill" 2>/dev/null'

function install_app
{
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "$cancel_quit &" > "$form_pipe"

# Unpacking package
#COMMAND HERE DEPENDS ON ARCHIVER
    
    # ------------------------------------------------
    # main process example for a demonstration purpose
     for i in {1..100}; do
         [ $(( $i % 10 )) -eq 0 ] && echo "#$i %" >> "$progress_pipe"
         sleep .1
     done & echo $! > "$main_proc_id"
    # ------------------------------------------------


wait "$(<$main_proc_id)" 2>/dev/null

if [ "$?" = "0" ]; then
	echo "#Installation completed" >> "$progress_pipe"
	kill "$main_pid" 2>/dev/null
	>"$main_proc_id"
else
	echo "#Installation canceled" >> "$progress_pipe"
	kill "$main_pid" 2>/dev/null
	>"$main_proc_id"
fi
}

export -f install_app

function get_pid_and_kill
{
sure_command='"yad --title=" " --width=1 \
	--text="Are you sure you want to cancel?" \
	--text-align=center	--on-top --center \
	--window-icon="system-software-install" \
	--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" == "" ]]; then
	if yad --title=" " --width=1 \
	--text="Are you sure you want to cancel?" \
	--text-align=center	--on-top --center \
	--window-icon="system-software-install" \
	--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
		fi
	fi

	kill -s SIGUSR1 $main_pid
fi
}

export -f get_pid_and_kill
exec 3<> "$progress_pipe"
exec 4<> "$form_pipe"

yad --paned --key="$key" --no-buttons \
--window-icon="system-software-install" --fixed \
--center --no-escape & export main_pid="$!"

yad --plug="$key" --tabnum=1 --form \
--field=" Select the destination path::DIR" \
--field=" Create a launcher in the applications menu:CHK" \
--field=" Create a launcher on the desktop:CHK" \
--field=" Begin Installation!system-software-install:fbtn" \
--field=" Cancel Installation and quit!gtk-quit:fbtn" \
--cycle-read <&4 &

echo "$HOME" > "$form_pipe"		# default directory
echo "TRUE" > "$form_pipe"		# default first checkbox value
echo "FALSE" > "$form_pipe"		# default second checkbox value
echo "$unpack &" > "$form_pipe"	# progress bar value
echo "@disabled@" > "$form_pipe"        # Disable cancel button

yad --plug="$key" --tabnum=2 --progress <&3 &

wait "$main_pid" 2>/dev/null
echo "Exit status of the main dialog: $?"

if [[ -s "$main_proc_id" ]]; then
    bckupid="$(<$main_proc_id)"
    >"$main_proc_id"
    kill "$bckupid" 2>/dev/null
    echo "killed the main process"
fi

exec 3>&-
exec 4>&-

-------------
Second issue is more complex, because you want to display "Are you sure you want to quit" dialog when the main window is closed.
So you wan to continue the installation if "No" is selected and kill the archiver and exit if "Yes" is selected...

I'll get back to you when I see how that works.

----------------
Here it is. I hope it work with Gtk3.
It should reopen the paned dialog and continue running the progress after you click "Cancel" on "Are you sure you want to quit".

#!/bin/bash

export main_proc_id="$(mktemp -u --tmpdir fpid.XXXXXXXX)"
export progress_pipe="$(mktemp -u --tmpdir ftd.XXXXXXXX)"
mkfifo "$progress_pipe"
export form_pipe="$(mktemp -u --tmpdir ftd2.XXXXXXXX)"
mkfifo "$form_pipe"
trap 'rm -f "$main_proc_id" "$progress_pipe" "$form_pipe"' "EXIT"
export key="$(($RANDOM * $$))"
export unpack='bash -c "install_app %1 %2 %3 %4"'
export cancel_quit='bash -c "get_pid_and_kill" 2>/dev/null'

function install_app
{
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "@disabled@" > "$form_pipe"
echo "$cancel_quit &" > "$form_pipe"

# Unpacking package
#COMMAND HERE DEPENDS ON ARCHIVER
    
    # ------------------------------------------------
    # main process example for a demonstration purpose
     for i in {1..100}; do
         [ $(( $i % 10 )) -eq 0 ] && echo "#$i %" >> "$progress_pipe"
         sleep .1
     done & echo $! > "$main_proc_id"
    # ------------------------------------------------


wait "$(<$main_proc_id)" 2>/dev/null

if [ "$?" = "0" ]; then
	echo "#Installation completed" >> "$progress_pipe"
	#kill "$main_pid" 2>/dev/null
	>"$main_proc_id"
else
	echo "#Installation canceled" >> "$progress_pipe"
	kill "$main_pid" 2>/dev/null
	>"$main_proc_id"
fi
    echo "$HOME" > "$form_pipe"		# default directory
    echo "TRUE" > "$form_pipe"		# default first checkbox value
    echo "FALSE" > "$form_pipe"		# default second checkbox value
    echo "$unpack &" > "$form_pipe"	# progress bar value
    echo "@disabled@" > "$form_pipe"        # Disable cancel button
}

export -f install_app

function get_pid_and_kill
{
sure_command='"yad --title=" " --width=1 \
	--text="Are you sure you want to cancel?" \
	--text-align=center	--on-top --center \
	--window-icon="system-software-install" \
	--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" == "" ]]; then
	if yad --title=" " --width=1 \
	--text="Are you sure you want to cancel?" \
	--text-align=center	--on-top --center \
	--window-icon="system-software-install" \
	--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
		fi

           kill -s SIGUSR1 $main_pid
	fi

fi
}

export -f get_pid_and_kill
exec 3<> "$progress_pipe"
exec 4<> "$form_pipe"

while true; do

yad --paned --key="$key" --no-buttons \
--window-icon="system-software-install" --fixed \
--center --no-escape & export main_pid="$!"

yad --plug="$key" --tabnum=1 --form \
--field=" Select the destination path::DIR" \
--field=" Create a launcher in the applications menu:CHK" \
--field=" Create a launcher on the desktop:CHK" \
--field=" Begin Installation!system-software-install:fbtn" \
--field=" Cancel Installation and quit!gtk-quit:fbtn" \
--cycle-read <&4 &

if [[ -s "$main_proc_id" ]]; then
    # If the installation is running
    echo "@disabled@" > "$form_pipe"
    echo "@disabled@" > "$form_pipe"
    echo "@disabled@" > "$form_pipe"
    echo "@disabled@" > "$form_pipe"
    echo "$cancel_quit &" > "$form_pipe"
else
    # If the installation is not running
    echo "$HOME" > "$form_pipe"		# default directory
    echo "TRUE" > "$form_pipe"		# default first checkbox value
    echo "FALSE" > "$form_pipe"		# default second checkbox value
    echo "$unpack &" > "$form_pipe"	# progress bar value
    echo "@disabled@" > "$form_pipe"        # Disable cancel button
fi

yad --plug="$key" --tabnum=2 --progress <&3 &

wait "$main_pid" 2>/dev/null
Action=$?

if [[ -s "$main_proc_id" ]]; then

    if [[ $Action == 143 ]] || [[ $Action == 252 ]]; then
        # Cancel-quit or X close the window or Escape
        yad --question --center --on-top --text "Do you really want to quit?"
        rc=$?
        if [[ $rc -eq 0 ]]; then
            bckupid="$(<$main_proc_id)"
            >"$main_proc_id"
            kill "$bckupid" 2>/dev/null
            break
        fi
    fi
else
   break
fi

done

exec 3>&-
exec 4>&-

*There could be some issues here and there.

Last edited by misko_2083 (2019-04-12 14:00:27)

Offline

#121 2019-04-12 14:05:58

Anton
New Member
Registered: 2019-04-11
Posts: 4

Re: The great yad hacking thread

misko_2083 wrote:

Second issue

I add "--splash" instead "--undecorated" and now Alt+F4 don't close the window.
Good bye Alt+Tab/Taskbar smile But it'better than nothing. The window can now be closed only with Quit button.

Offline

#122 2019-04-12 14:08:43

Anton
New Member
Registered: 2019-04-11
Posts: 4

Re: The great yad hacking thread

misko_2083 wrote:

Here it is. I hope it work with Gtk3.

Thank so much. I'll see it later.

//upd
The closing action window is working, but there is no filling of the progress bar, although the percentages are working.
f762b6a095ed4caf90d377e5d774441b.jpeg

//upd2
Hmm, it works completely (the progress bar is being filled) with the real unpacking, but if the window closes, the request dialog doesn't appear.
Here is an example: yadi.sk/d/07nC3KGxevzcYA

Last edited by Anton (2019-04-13 16:05:17)

Offline

#123 2019-04-24 18:44:55

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: The great yad hacking thread

Да си жив и здрав.
You'll figure it out eventually.

I like to help but realy don't want to run those BLOBs in the archive.
It's more than enough having all those proprietary BLOBs in the linux kernel. smile

Offline

#124 2019-04-24 19:27:40

Anton
New Member
Registered: 2019-04-11
Posts: 4

Re: The great yad hacking thread

misko_2083 wrote:

Да си жив и здрав.
You'll figure it out eventually.

I like to help but realy don't want to run those BLOBs in the archive.
It's more than enough having all those proprietary BLOBs in the linux kernel. smile

There is no proprietary BLOBs in the tar.
Except the game itself in the pak.arc (archive) file that I packed with the FreeArc archiver. See github links in readme.txt, encode.ru and others sites.

Of course, running the game is not necessary.
If you want, I can pack something else.

Last edited by Anton (2019-04-24 19:47:13)

Offline

#125 2019-07-11 18:20:24

misko_2083
Member
Registered: 2016-05-24
Posts: 205

Re: The great yad hacking thread

This is an experiment with the relative screen positioning and tint2 variable

This script opens alsa volume control.
If tint2 button runs this script, yad window will position next to the button in all the panel orientations.
Requires xdotool and yad.
The screen position can be read the from tin2rc, however I wanted to explore this option of calculating screen position.

#!/bin/bash

# alsa volume notification icon misko_2083

ERR(){ echo "ERROR: $1" 1>&2; }

declare -i DEPCOUNT=0
for DEP in /usr/bin/{xdotool,yad}; {
	[ -x "$DEP" ] || {
		ERR "$LINENO Dependency '$DEP' not met."
		DEPCOUNT+=1
	}
}
[ $DEPCOUNT -eq 0 ] || exit 1


# export tint2 variables
export TINT2_BUTTON_ALIGNED_X1=$TINT2_BUTTON_ALIGNED_X1
export INT2_BUTTON_ALIGNED_X2=$TINT2_BUTTON_ALIGNED_X1
export TINT2_BUTTON_ALIGNED_Y1=$TINT2_BUTTON_ALIGNED_Y1
export TINT2_BUTTON_ALIGNED_Y2=$TINT2_BUTTON_ALIGNED_Y2


function get_volume(){
vol=$(amixer get Master | grep "\[on\]\|\[off\]")
vol=( $vol )
# Fredx181 check for pulseaudio
 [ $(pidof pulseaudio) ] && CURVOL=$(echo ${vol[4]} | sed 's/[][%]//g') || CURVOL=$(echo ${vol[3]} | sed 's/[][%]//g')
}
export -f get_volume

main(){

 # set window class
 YAD_CLASS="YAD_AUDIO"

 # Unmap the window if the script is relaunched
 # This closes the window if notification icon is clicked while the popup window is in focus
   pids="$(xdotool search --class "$YAD_CLASS")"
   wpid="$(xdotool getwindowfocus)"

   for pid in $pids; do
        # Compares window class pid with the pid of a window in focus
        if [[ "$pid" == "$wpid" ]]; then
           xdotool windowunmap $pid &>/dev/null
           exit 1
        fi
   done

get_volume

# Format xrandr output
xrandr="$(xrandr | grep -w "connected" | grep -o "[0-9]\+x[0-9]\++[0-9]\++[0-9]\+" | tr "x+" " " | sort -nk 4)"
# Get num of monitors
num_screens=$(echo "$xrandr" |  wc -l)
[ "$num_screens" -gt 2 ] && echo "Script cannot deal with more than 2 monitors" >&2 && exit 1
# Get screen resolution
screen_left=($(echo "$xrandr" | head -1))
[ "$num_screens" -gt 1 ] && screen_right=($(echo "$xrandr" | tail -1))

# Get current mouse position
out="$(xdotool getmouselocation)"
out=(${out//[^0-9 ]/})
current_x="${out[0]}"
current_y="${out[1]}"

# Calculate current monitor and relative position to this monitor
if [ "$num_screens" -gt 1 ] && [ "$current_x" -gt "${screen_right[2]}" ]; then
	current_screen=(${screen_right[*]})
	current_x=$(($current_x-${screen_right[2]}))
else 
	current_screen=(${screen_left[*]})
fi

# Check relative position
if [ "$current_y" -lt "$((${current_screen[1]}*1/4))" ]; then # IN-TOP
	var_key="top"
elif [ "$current_y" -gt "$((${current_screen[1]}*3/4))" ]; then # IN-BOTTOM
	var_key="bottom"
fi
if [ "$current_x" -lt "$((${current_screen[0]}*1/4))" ]; then # IN-LEFT
	var_key="${var_key}left"
elif [ "$current_x" -gt "$((${current_screen[0]}*3/4))" ]; then # IN-RIGHT
	var_key="${var_key}right"
fi
[ ! "$var_key" ] && var_key="center"

case ${var_key} in
top)         current_x=${TINT2_BUTTON_ALIGNED_X1}
             current_y=${TINT2_BUTTON_ALIGNED_Y1}
             ;;
topleft)     current_x=${TINT2_BUTTON_ALIGNED_X1}
             current_y=${TINT2_BUTTON_ALIGNED_Y1}
             ;;
topright)    current_y=${TINT2_BUTTON_ALIGNED_Y1}
             current_x=$(($TINT2_BUTTON_ALIGNED_X2-300))
             ;;
bottom)      current_x=${TINT2_BUTTON_ALIGNED_X1}
             current_y=$(($TINT2_BUTTON_ALIGNED_Y1-200))
             ;;
bottomleft)  current_x=${TINT2_BUTTON_ALIGNED_X1}
             current_y=$(($TINT2_BUTTON_ALIGNED_Y2-200))
             ;;
bottomright) current_x=$(($TINT2_BUTTON_ALIGNED_X2-300))
             current_y=$(($TINT2_BUTTON_ALIGNED_Y2-200))
             ;;
left)        current_x=${TINT2_BUTTON_ALIGNED_X1}
             current_y=$(($TINT2_BUTTON_ALIGNED_Y2-200))
             ;;
right)       current_y=${TINT2_BUTTON_ALIGNED_Y1}
             current_x=$(($TINT2_BUTTON_ALIGNED_X2-300))
             ;;
center)      current_x=${TINT2_BUTTON_ALIGNED_X1}
             current_y=${TINT2_BUTTON_ALIGNED_Y1}
             ;;
esac

if [ "$current_x" == "" ]
then
     current_x="${out[0]}"
     current_y="${out[1]}"
fi

PLUG=$(($RANDOM * $$))
yad --plug=$PLUG --tabnum=1 --scale \
    --print-partial \
    --text="  Volume Control                   " \
    --min-value=0 --max-value=100 \
    --image="preferences-desktop-sound" \
    --borders="12" \
    --value="$CURVOL" 2> /dev/null | \
while read VOL; do
    amixer sset 'Master' "$VOL%" 2>&1 >/dev/null
done &

yad --plug=$PLUG --tabnum=2 --text="" --form --field="Mute/Unmute":fbtn "bash -c 'alsa_toggle'" &

yad --paned --key=$PLUG --tab="Tab 1" --tab="Tab 2" --width=300 --height=200 \
    --posy=$current_y --posx=$current_x \
    --no-buttons  \
    --undecorated \
    --close-on-unfocus \
    --on-top \
    --skip-taskbar \
    --sticky \
    --class="$YAD_CLASS"
}
export -f  main


function alsa_toggle(){
  if amixer | grep -E -A 6 -B 0 'Master|Headphone|Speaker' | grep '\[off\]'; then
    amixer  set Master unmute
    amixer  set Speaker unmute
    amixer  set Headphone unmute
    get_volume
  else
    amixer set Master mute
  fi
}
export -f alsa_toggle

main

Offline

Board footer

Powered by FluxBB