You are not logged in.

#126 2019-07-11 20:02:32

malm
jgmenu developer
Registered: 2016-10-13
Posts: 480
Website

Re: The great yad hacking thread

tint2 and yad are ace. Not sure you could easily do that with another panel!

Offline

#127 2019-07-12 12:13:42

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

Re: The great yad hacking thread

^Yes, it's not so easy with the other panels.
A panel plugin is necessary in those cases.

Offline

#128 2019-08-23 00:34:07

achim
Member
Registered: 2019-08-23
Posts: 8

Re: The great yad hacking thread

Hello misko_2083,
in another forum you have ever helped very well. Now I find you here again by chance and have a question: I have created a YAD code under Linux Mint 18.3 and would like to build a progress bar for the FFMPEG command. But I need help. Here is my code:

#!/bin/bash

# videoformat auf 16:9 einstellen

cd /
cd /home/achim/Videos/

TITLE="Videoformat auf 16:9 einstellen"
TEXT="<span foreground='red'><b><big><big>
      Bitte eine beliebige Datei selektieren und mit 'OK' fortfahren!
</big></big></b></span>"

filename=$(yad --width=1500 --height=600 --window-icon="/home/achim/.icons/Movies-icon24.png" --title="$TITLE" --text="$TEXT" --file-selection \
            --button=" Abbrechen!/home/achim/.icons/Button-stop-icon24.png":1 --button=" OK!/home/achim/.icons/Accept-icon24.png":0 \
            --file-filter='*.mp4')

pfadname=${filename}
verz=${filename%/*}
datm=${pfadname##*/}
dato=${datm%.*}

[[ -z "$filename" ]] && exit 0

cd /
cd "$verz"

mediainfo --Output=file:///home/achim/.config/achim/medinfo.txt "$datm" > /home/achim/.config/achim/medlog.odt

va="$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$datm")" # = 334.089000
va1=${vb%.*} # = 334
secs=va1 # 334
va2=$(printf '%H:%M:%S' $(($secs/3600)) $(($secs%3600/60)) $(($secs%60)))
#va3=`date +%00:%M:%S`
va3="$(date +%T)"

ffmpeg -hide_banner -i "$datm" -vf scale="1920:1080" -aspect 16:9 -b:a 320000 "${datm%.*}-169.mp4" | yad --progress \
--progress-text="DerVorgang startete um $va3 und dauert etwa $va2" --width=1200 --height=300 --center --window-icon="gtk-execute" \
--title="Die Konvertierung des Videos  '$datm'  läuft..." --timeout=$va1 --timeout-indicator=Bottom --no-button --auto-kill --auto-close

exit 0

# va1 (334 Sekunden) = Laufzeit der Fortschrittanzeige für dieses Beispiel

Do you have a tip for me? (Sorry for my bad English)

achim

Last edited by achim (2019-08-23 22:14:46)

Offline

#129 2019-08-23 16:46:07

ohnonot
...again
Registered: 2015-09-29
Posts: 3,906
Website

Re: The great yad hacking thread

^ all I can see is that ffmpeg itself does not know when it will be finished; where do you plan to get the percentages for the progress bar?
- Ok, answering my own question:

man ffmpeg
...
       -stats (global)
           Print encoding progress/statistics. It is on by default, to explicitly disable it you need to specify "-nostats".

       -progress url (global)
           Send program-friendly progress information to url.

           Progress information is written approximately every second and at the end of the encoding process. It is made of "key=value" lines. key consists of only alphanumeric characters. The last key
           of a sequence of progress information is always "progress".

Offline

#130 2019-08-23 22:20:19

achim
Member
Registered: 2019-08-23
Posts: 8

Re: The great yad hacking thread

In between I helped myself a little and changed the code accordingly. But the progress bar is still a bit inaccurate. I keep working on it.

achim

Offline

#131 2019-08-24 05:42:36

ohnonot
...again
Registered: 2015-09-29
Posts: 3,906
Website

Re: The great yad hacking thread

please use "$HOME" instead of /home/achim.
Makes it easier for others to test or use your script.

Offline

#132 2019-08-24 13:11:33

clusterF
Member
Registered: 2019-05-07
Posts: 141

Re: The great yad hacking thread

@ achim, Might be a few hints in this script from here http://smokey01.com/help/yad-tips-0.0.2.html

#!/bin/sh

eval exec yad --title="xdf" \
	--image=drive-harddisk \
	--text="Disk\ usage:" \
	--buttons-layout=end \
	--width=650 \
	--multi-progress \
$(df -hT $1 | tail -n +2 | awk '{printf "--bar=\"<b>%s</b> (%s - %s) [%s/%s]\" %s ", $7, $1, $2, $4, $3, $6}')

Last edited by clusterF (2019-08-24 13:16:41)


Everything not saved will be lost.

--Nintendo "Quit Screen" message

Offline

#133 2019-08-24 18:12:57

achim
Member
Registered: 2019-08-23
Posts: 8

Re: The great yad hacking thread

Hello everybody,

I have the code ready now and it works quite well. With the variables vb, vc and vd I have adjusted the speed of the progress bar, since ffmpeg runs faster with me than the tool ffprobe has determined. With the variable the speed of the progress bar can be changed according to the speed of the system.

If you can still make suggestions for improvement, I am always grateful for it.

I thank the users @ohnonot and @clusterF for their help.

Here is the script:

#!/bin/bash

# videoformat auf 16:9 einstellen

cd /
cd $HOME/Videos/

TITLE="Videoformat auf 16:9 einstellen"
TEXT="<span foreground='red'><b><big><big>
      Bitte eine beliebige Datei selektieren und mit 'OK' fortfahren!
</big></big></b></span>"

filename=$(yad --width=1500 --height=600 --window-icon="$HOME/.icons/Movies-icon24.png" --title="$TITLE" --text="$TEXT" --file-selection \
            --button=" Abbrechen!$HOME/.icons/Button-stop-icon24.png":1 --button=" OK!$HOME/.icons/Accept-icon24.png":0 \
            --file-filter='*.mp4')

pfadname=${filename}
verz=${filename%/*}
datm=${pfadname##*/}
dato=${datm%.*}

[[ -z "$filename" ]] && exit 0

cd /
cd "$verz"

mediainfo --Output=file:///$HOME/.config/achim/medinfo.txt "$datm" > $HOME/.config/achim/medlog.odt

va="$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$datm")" # = 334.089000
vb=${va%.*} # = 334
vc=10
vd=6
((va1=$vb/$vc*$vd))
secs=vb # 334
va2=$(printf '%d Stunden, %d Minuten, %d Sekunden ' $(($secs/3600)) $(($secs%3600/60)) $(($secs%60)))
#va3=`date +%00:%M:%S`
va3="$(date +%T)"

ffmpeg -hide_banner -i "$datm" -vf scale="1920:1080" -aspect 16:9 -b:a 320000 "${datm%.*}-169.mp4" | yad --progress \
--progress-text="Der Vorgang startete um $va3 und dauert etwa $va2" --width=1200 --height=150 --center --window-icon="gtk-execute" \
--title="Die Konvertierung des Videos  '$datm'  läuft..." --timeout=$va1 --timeout-indicator=top --no-buttons --auto-kill --auto-close

yad --text-info --title="Die Mediainfos zu dem Video '$datm'  "   --width=1000 --height=800 --center --window-icon="gtk-execute" --wrap --back=gainsboro \
--fore=blue < $HOME//.config/achim/medlog.odt --fontname=" Monospace italic 12"

exit 0

# va1 (334 Sekunden) = Laufzeit der Fortschrittanzeige für dieses Beispiel

achim

Offline

#134 2019-08-25 05:56:56

ohnonot
...again
Registered: 2015-09-29
Posts: 3,906
Website

Re: The great yad hacking thread

^ Great!
A few things:

  • "cd /" is pointless. Remove it.

  • mediainfo files: are they temprary? are you planning on keeping them? If not, it might be a good idea to clean up after the script has finished. And use a folder that is present on all systems, not only yours.

  • Why is the input limited to .mp4 files?

  • I tested, the progress bar ran out before conversion was finished. Just a minute or so, but that's bad.

Offline

#135 2019-08-25 10:43:01

achim
Member
Registered: 2019-08-23
Posts: 8

Re: The great yad hacking thread

Thank you @ sononot

Top 1: done

Top 2: I will reconsider this point

Top 3: The selection can be extended (for example by changing the line 15 in --file-filter='*.mp4' --file-filter='*.m4a' --file-filter='*.avi')"

Top 4: Extend the runtime of the progress bar by increasing the variable vd (line 32) to 7, 8 or 9

Best regards

achim

Last edited by achim (2019-08-25 11:05:55)

Offline

#136 2019-09-11 23:46:27

achim
Member
Registered: 2019-08-23
Posts: 8

Re: The great yad hacking thread

Hello everybody,

I have created a YAD code to convert images. Now I want to make the fixed 50% but flexible. For this I need one, however, an additional input field. Can someone tell me if another query is needed or can I do everything with the following code?

#!/bin/bash

# Bilder konvertieren (Einzeln)

cd $HOME/Bilder/

TITLE="Bild konvertieren"
TEXT="<span foreground='red'><b><big><big>
		Bitte das gewünschte Bildformat wählen, eine beliebige Datei selektieren und mit 'OK' fortfahren!
</big></big></b></span>"

filename=$(yad --width=1600 --height=600 --window-icon="$HOME/.icons/Movies-icon24.png" --title="$TITLE" --file-selection \
            --text="$TEXT" --button=" Abbrechen!$HOME/.icons/Button-stop-icon24.png":1 --button=" OK!$HOME/.icons/Accept-icon24.png":0 \
            --file-filter='*.png' --file-filter='*.jpg' --file-filter='*.tif')

pfadname=${filename}
verz=${filename%/*}
datm=${pfadname##*/}
dato=${datm%.*}
	
cd  "$verz"

[[ -z "$filename" ]] && exit 0

case $filename in
     *.png)

echo "Konvertierung des Bildes "$datm" läuft...";
    convert "$datm" -resize 50% "$datm"-neu.png
yad --text="<span color='red'>Die Konvertierung des Bildes 

$datm

wird erzeugt...</span>" --width=550 --window-icon="$HOME/.icons/Movies-icon24.png" \
--title="Verlaufskontrolle" --text-align=center --no-buttons --timeout=3;   
    ;;

     *.jpg)

echo "Konvertierung des Bildes "$datm" läuft...";
    convert "$datm" -resize 50% "$datm"-neu.jpg
yad --text="<span color='red'>Die Konvertierung des Bildes 

$datm

wird erzeugt...</span>" --width=550 --window-icon="$HOME/.icons/Movies-icon24.png" \
--title="Verlaufskontrolle" --text-align=center --no-buttons --timeout=3;   
    ;;

     *.tif)

echo "Konvertierung des Bildes "$datm" läuft...";
    convert "$datm" -resize 50% "$datm"-neu.tif
yad --text="<span color='red'>Die Konvertierung des Bildes 

$datm

wird erzeugt...</span>" --width=550 --window-icon="$HOME/.icons/Movies-icon24.png" \
--title="Verlaufskontrolle" --text-align=center --no-buttons --timeout=3;   
    ;;

esac
exit 0

Offline

#137 2019-09-12 10:52:30

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

Re: The great yad hacking thread

^ For the progress bar "pv" app is a good option.

For the image conversion form dialog gives you more options.
And the dialog can stay open.

#!/bin/bash

convert_cmd="@bash -c 'run_convert "%1" "%2" "%3" "%4"'"
export convert_cmd

function run_convert
{
    # Disable convert button
    echo "4:@disable@"

    verz="${1%/*}"
    f_name="${1##*/}"
    dato="${f_name%.*}"

    cd  "$verz"

    if [[ ! -f "${f_name}" ]]; then
        yad --text "${1} is not a file"
    else

       exten="${1##*'.'}"

       convert "$f_name" -resize "$3"% -quality "$2"% "${dato}-new.${exten}" 
       [[ ${?} -ne 0 ]] && yad --text "Conversion failed: ${1}"
    fi

    # Enable convert button
    echo "4:$convert_cmd"
}
export -f run_convert

yad --form --width=500 --height=200 --window-icon="$HOME/.icons/Movies-icon24.png" \
    --title="$TITLE" \
    --field="Select an image":FL  --field="Quality":SCL  --field="Size in %":NuM --field="convert:fbtn" \
    "" "95" "50!5..99!1!0" "$convert_cmd" \
    --text="$TEXT" --button="gtk-cancel!Cancel":1 --button="gtk-ok!OK":0 \
    --file-filter='Image Files (*.jpg *.jpeg *.png *.tif)| *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG *.tif *.TIF' --no-buttons

exit

Offline

#138 2019-09-12 16:36:34

achim
Member
Registered: 2019-08-23
Posts: 8

Re: The great yad hacking thread

^ Thank you for the support. Where can I find out about Progress Bar PV?

Offline

#139 2019-09-12 18:13:32

ohnonot
...again
Registered: 2015-09-29
Posts: 3,906
Website

Re: The great yad hacking thread

^ It's a little command line app.
On my system it's a standalone package; try

apt install pv
man pv

It can do things like this:

echo -e "$(date)\b\b\b\b1984, $(uptime -p)"|pv -L 14 -q

Offline

#140 2019-09-14 10:41:36

clusterF
Member
Registered: 2019-05-07
Posts: 141

Re: The great yad hacking thread

Is there a way to create a yad dialog of web links, maybe buttons or just a list of clickable addresses? I wanting to create a menu of sorts that has all my favorite websites in a yad menu. Ive looked at the html options in yad but have no idea how to proceed.

Example;

button = bunsenlabs.org and xdg-opens inside x-www-browser ?

I have read you need yad built with the ./configure --html

and if you use yad --browser mode you need libwebkit2gtk.


Everything not saved will be lost.

--Nintendo "Quit Screen" message

Offline

#141 2019-09-14 13:25:55

damo
....moderator....
Registered: 2015-08-20
Posts: 5,057

Re: The great yad hacking thread

Another, simpler approach, is to create an OB menu item containing your links. This could be a submenu in your main menu; or a standalone menu run from a keybind, or a tint2 button/exec.


Be Excellent to Each Other...

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

Offline

#142 2019-09-14 14:56:31

clusterF
Member
Registered: 2019-05-07
Posts: 141

Re: The great yad hacking thread

^ that is an approach i had thought of. Seems yad doesnt really have good local web browser integration. I havent been able to figure out how to create a button that will open a link in my web browser. It would seem like a simple enough operation but i have googled and come up nil.


Everything not saved will be lost.

--Nintendo "Quit Screen" message

Offline

#143 2019-09-14 15:41:35

clusterF
Member
Registered: 2019-05-07
Posts: 141

Re: The great yad hacking thread

Figured something out. Having a separate txt file with html links helps.
links.txt needs full web address too like https://bunsenlabs.org

#!/bin/bash

yad --height=200 --width=150 --text-info --width=250 < $HOME/Documents/links.txt --show-uri \
--button=gtk-cancel:1

Last edited by clusterF (2019-09-14 15:44:03)


Everything not saved will be lost.

--Nintendo "Quit Screen" message

Offline

#144 2019-09-14 17:46:30

achim
Member
Registered: 2019-08-23
Posts: 8

Re: The great yad hacking thread

^ I would like to answer the question of the user cluserF and insert a picture. However, the png file does not work. How does that work?

Offline

#145 2019-09-14 18:28:00

damo
....moderator....
Registered: 2015-08-20
Posts: 5,057

Re: The great yad hacking thread

achim wrote:

^ I would like to answer the question of the user cluserF and insert a picture. However, the png file does not work. How does that work?

Use an [ img ] tag in your post edit window.

bunsenlabs wrote:

Please use thumbnails. Do not embed images larger than approx 250x250px (62,500px) into posts, use thumbnails linking to a hosted image instead. Thanks!

We recommend https://scrot.moe (free registration required) for image uploads. After uploading your image, click "Embed codes" and copy/paste the "Thumbnail image (linked) BBCode" at the bottom of the page, done.

Your post will have something like

[url=https://url-of-full-image][img]url-of-thumbnail.png[/img][/url] 

Be Excellent to Each Other...

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

Offline

#146 2019-09-15 09:36:13

achim
Member
Registered: 2019-08-23
Posts: 8

Re: The great yad hacking thread

Thanks to the moderator. I try it differently.

@ clusterF
I've built myself a very flexible htm file. This does not have anything to do with YAD, but if you're interested, please let me know by PM.

achim

Offline

#147 2019-09-15 10:46:55

clusterF
Member
Registered: 2019-05-07
Posts: 141

Re: The great yad hacking thread

@achim

Its ok, im just experimenting with yad. I wanted to see if i can create a button that links to a website and some other fields mixed together in the one yad window.


Everything not saved will be lost.

--Nintendo "Quit Screen" message

Offline

#148 Yesterday 06:51:16

ohnonot
...again
Registered: 2015-09-29
Posts: 3,906
Website

Re: The great yad hacking thread

clusterF wrote:

Figured something out. Having a separate txt file with html links helps.

--show-uri

That's a nice option.
And they just open in your chosen default browser?

Offline

#149 Yesterday 12:31:03

clusterF
Member
Registered: 2019-05-07
Posts: 141

Re: The great yad hacking thread

ohnonot wrote:
clusterF wrote:

Figured something out. Having a separate txt file with html links helps.

--show-uri

That's a nice option.
And they just open in your chosen default browser?

Yes apparently that will use xdg-open into your default browser.

From man yad in "Text Info Operations"

--show-uri
              Make links in text clickable. Links opens with xdg-open command.


Everything not saved will be lost.

--Nintendo "Quit Screen" message

Offline

Board footer

Powered by FluxBB