YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#601 Post by fredx181 »

achim wrote:Hi Fred,

if you're interested, I changed the parameter order for the FFMPEG command as follows:

Code: Select all

ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" -acodec copy -vcodec copy "$OUTPUT"
So everything works to my satisfaction.

Best regards

achim
Thanks achim, apparently the order of parameters makes a difference.
From what I understand reading about it on the web, the spitting isn't always exact , that will be only when the split point is a "keyframe" .
When re-encoding (instead using copy), maybe it can be exact, but I don't know much about ffmpeg, so not sure.

Fred

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

#602 Post by achim »

Hello Fred,

Thank you for this information. If you know a more precise way to split videos, please let me know.

Up soon,

Achim

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

#603 Post by fredx181 »

achim wrote:Hello Fred,

Thank you for this information. If you know a more precise way to split videos, please let me know.

Up soon,

Achim
Hi achim, here's good info, I think, it mentions what difference the order of parameters makes and in the end that re-encoding is the best for splitting, but can have quality loss.
http://www.markbuckler.com/post/cutting-ffmpeg/
I found that for re-encoding (to mp4) this has nice quality (but takes a lot longer than copying):

Code: Select all

ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" -vcodec libx264  -preset medium -crf 24 -acodec libmp3lame -ab 128k "$OUTPUT"
You may want to replace "libmp3lame" by "libfaac" if your ffmpeg supports it (and maybe change the bitrate for audio).

Fred

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

#604 Post by achim »

Hello Fred,

nice that you help me with the topic "cut videos with FFmpeg" so well. The link is very interesting and the command line

Code: Select all

ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" -vcodec libx264  -preset veryfast -crf 16 -acodec libmp3lame -ab 196k "$OUTPUT"
I tested. As you can see, I have changed it a bit by experimenting. I think I get good results with this parameter setting now. Maybe I would like to create a YAD script later, with which I can query the parameters after the YT download. Let's see how much time I have for it. But one more thing: YAD is a great tool, it's fun.
I wish you all the best

achim

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

#605 Post by achim »

Hello Fred,

I have spent too many hours solving a problem. Look at this code:

Code: Select all

if [[ $INPUT = *.mp4 ]]; then
ffmpeg -i "${INPUT}" -vn -ar 44100 -ac 2 -ab 320k "${INPUT%.mp4}.mp3";
fi
FFmpeg will not stop automatically after that. I have to help with Ctrl + C. Do you have any idea why that is?

achim

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

#606 Post by fredx181 »

Hi achim, strange.... tried your code and works fine for me.
Don't know. Maybe the encoding takes much longer than you expected ?

Let's not continue here if the subject isn't about YAD, better go on about ffmpeg in your thread (or other thread you create maybe):
http://murga-linux.com/puppy/viewtopic.php?t=115844

Fred

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

#607 Post by achim »

OK, thanks Fred

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

#608 Post by achim »

Hi fred,

here is the complete code, which you can extend as you like (works very well!)

Code: Select all

#!/bin/bash
# mp3 aus Video extrahieren (Einzeln)
cd
cd /home/achim/Youtube-Videos

TITLE="MP3 aus Video extrahieren"
TEXT="Bitte die Endung wählen und anschließend eine Datei selektieren: "

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

basePath=${filename%.*} 
baseName=${basePath##*/}
newPath=${basePath%/*}
TEXT1="<span color='blue'>Die Datei "$baseName".mp3 

wurde im Verzeichnis "$newPath" gespeichert!</span>"

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

case $filename in
        *.mp4)
ffmpeg -i "$filename" -vn -ar 44100 -ac 2 -ab 320k "$basePath".mp3
sleep 2
xdotool key "Return"
yad --center height=200 --width=550 --window-icon="/home/achim/.icons/Movies-icon24.png" --title="Ex­trak­ti­on aus Video erfolgreich" \
--text="$TEXT1" --image-on-top --image="/home/achim/.icons/Hand-thumbs-up-like-2-icon72.png" \
--no-buttons --close-on-unfocus ;;
        *.m4a)
ffmpeg -i "$filename" -vn -ar 44100 -ac 2 -ab 320k "$basePath".mp3
sleep 2
xdotool key "Return"
yad --center height=200 --width=550 --window-icon="/home/achim/.icons/Movies-icon24.png" --title="Ex­trak­ti­on aus Video erfolgreich" \
--text="$TEXT1" --image-on-top --image="/home/achim/.icons/Hand-thumbs-up-like-2-icon72.png" \
--no-buttons --close-on-unfocus ;;
        *.avi)
ffmpeg -i "$filename" -vn -ar 44100 -ac 2 -ab 320k "$basePath".mp3
sleep 2
xdotool key "Return"
yad --center height=200 --width=550 --window-icon="/home/achim/.icons/Movies-icon24.png" --title="Ex­trak­ti­on aus Video erfolgreich" \
--text="$TEXT1" --image-on-top --image="/home/achim/.icons/Hand-thumbs-up-like-2-icon72.png" \
--no-buttons --close-on-unfocus ;;
esac
exit 0

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

#609 Post by fredx181 »

Hi achim,
Nice !
About the issue you had , it makes no difference for me if I comment out the xdotool line or not. Both ways will go to the terminal prompt only after the last yad dialog is closed (by unfocus)

Fred

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

#610 Post by fredx181 »

Hi, I'd like to have a 'Preview' button for a form dialog
This simple example to demonstrate works OK with the button (fbtn) as a field inside the form (with choice opening leafpad or geany what's inside the text-box):

Code: Select all

#!/bin/bash

export load_cmd='@bash -c "editor %1 %2"'

editor () {
echo $1 > /tmp/file
[ $2 = Leafpad ] && leafpad /tmp/file || geany /tmp/file
rm -f /tmp/file
}
export -f editor

yad --form --field "code :TXT" 'Hello World' --item-separator="|" --field "Choose editor:CB" "Leafpad|Geany" --field "Preview:fbtn" "$load_cmd" --button="gtk-cancel:1"  --button="gtk-ok:0"
But.. Don't know if possible, I'd like to have the 'Preview' button next to the cancel button (see second pic) and achieve the same (opening leafpad or geany with what's in the text-box) when clicking on it, maybe need to use a pipe, can't figure out how.

Fred
Attachments
2019-04-29-175347_207x260_scrot.png
Using code above, this works as it should when clicking 'Preview'
(18.48 KiB) Downloaded 517 times
2019-04-29-173118_284x217_scrot.png
(18.21 KiB) Downloaded 526 times

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#611 Post by Geoffrey »

Not yad, but will this do

Code: Select all

#!/bin/sh
#
THIS_APP="$(readlink -e "$0")"
sleep 0.3
[ `pidof "$(basename "$THIS_APP")" -o %PPID | wc -w` -gt 1 ] && exit 1

export DIALOG='
<window title="" icon-name="edit">
   <vbox>
      <edit wrap-mode="3">
         <variable>EDIT</variable>
         <height>150</height>
         <width>500</width>
      </edit>
      <hbox homogeneous="true">
      <hbox>
       <comboboxtext>
	<variable>EDITOR</variable>
	<item>Leafpad</item>
	<item>Geany</item>
	</comboboxtext>
          <button>
            <label>Preview</label>
            <input file stock="gtk-ok"></input>
            <action>`echo "$EDIT" > /tmp/file ; "${EDITOR,}" /tmp/file` &</action>
          </button>
          <button cancel></button>  
        </hbox>
      </hbox>
   </vbox>
</window>'

gtkdialog --program=DIALOG
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

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

#612 Post by misko_2083 »



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

#613 Post by fredx181 »

Thanks Geoffrey and misko_2083 anyway, but I decided to stay with the preview button inside the form, it's for my "Markdown to HTML" experiments, and I don't like very much that the button has the full width of the GUI (800) (that's why I asked about possible different way) but I guess I'll have to accept it.
http://murga-linux.com/puppy/viewtopic. ... 41#1026741

EDIT:
@Geoffrey, thanks again, your gtkdialog code was a good start for my new md2html app:
http://murga-linux.com/puppy/viewtopic. ... 36#1026936

Fred

User avatar
lamplinux
Posts: 31
Joined: Mon 21 Jan 2019, 06:05
Contact:

Yad Twiisted Coding - Checkit out.

#614 Post by lamplinux »

I've been busy hacking Yad & a little bash scripting.

I'm swapping out icons in this example. Using --tails to feed to --text-info a Single Paned Window.

I am using Tilda Terminal that positions exactly over --text-info window so user can be guided when running terminal commands.

Still a work in progress but, I have learned so much. Thank you Misko & others for helping me.

Video of Latest Work: https://www.youtube.com/watch?v=j8DsrCBo4rQ

Image

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

#615 Post by misko_2083 »

Fredx181, if you want to make one, even simpler version of yradio,
you can use the list for navigation between the radio categories and stations.

Here's an example with the notification icon.
Left click on the icon opens a list dialog with categories.
If you select the first category, the list will cycle read "back and "item-1".
Back returns to the categories, item-1 launches the window.

xdotool is here to close the list if the notification dialog is clicked (preferable behavior),
Right click opens the menu just so that the notification can be closed.

Code: Select all

#!/bin/bash

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

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

[ $DEPCOUNT -eq 0 ] || exit 1

VERSION=`yad --version | awk '{ print $1 }'`
verlte() {
    [  "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}

verlt() {
    [ "$1" = "$2" ] && return 1 || verlte $1 $2
}

if verlt $VERSION 0.38.2; then
   yad --text=" The version of yad installed is too old for to run this program, \n Please upgrade yad to a version higher than 0.38.2   " \
       --button="gtk-close"
   exit
fi


# window class for the list dialog
export CLASS="left_click_001"

# fifo
export YAD_NOTIF=$(mktemp -u --tmpdir YAD_NOTIF.XXXXXX)
mkfifo "$YAD_NOTIF"

export listpipe="/tmp/ylist.$RANDOM"
mkfifo "$listpipe"


# trap that removes fifo
trap "rm -f $YAD_NOTIF $listpipe" EXIT

# function to return to the root category
yikes_back(){
   exec 3<> $listpipe
   echo -e '\f' >&3
   printf "%s\n" "gtk-ok" "yikes_one" "category 1" "gtk-no" "yikes_launch Cat-2" "Category-2" >&3
}
export -f yikes_back


# function to open first category
yikes_one(){
   exec 3<> $listpipe
   echo -e '\f' >&3
   printf "%s\n" "gtk-refresh" "yikes_back" "Back" >&3
   printf "%s\n" "gtk-ok" "yikes_launch item-1" "Item 1" >&3
}
export -f yikes_one

# function to launch
yikes_launch(){
   txt="$1"
   yad --text "Item launched $txt" 
}
export -f yikes_launch

# function to launch the list dialog
list_dialog() {
# Ensures only one instance of this window
# if there is another yad window close any dialog with the mathing class
if [[ $(pgrep -c $(basename $0)) -ne 1 ]]; then
   pids="$(xdotool search --class "$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
           exit 1
        fi
   done
fi

exec 3<> $listpipe

yad --list \
    --class="$CLASS" \
    --column="":IMG \
    --column="" \
    --column="" \
    --no-headers --no-buttons \
    --undecorated \
    --close-on-unfocus \
    --on-top \
    --skip-taskbar \
    --mouse \
    --width=200 --height=300 \
    --hide-column="2" \
    --sticky --cycle-read \
    --select-action="sh -c \"echo %s | sed 's/[^ ]* //' 2>&1 | xargs -I {} bash -c {} \"" <&3 &

printf "%s\n" "gtk-ok" "yikes_one" "One" "gtk-no" "yikes_launch Category-2" "two" >&3
}
export -f list_dialog

# fuction to set the notification icon
function set_notification_icon() {
  echo "icon:firefox" 
  echo "tooltip:Come on"
  echo "menu:About!bash -c 'yad --about'!gtk-about||Quit!quit!gtk-quit"
}

exec 3<> $YAD_NOTIF

yad --notification --command="bash -c 'list_dialog'" --listen <&3 & notifpid=$!

# waits until the notification icon is ready
until xdotool getwindowname $(xdotool search --pid "$notifpid" | tail -1) &>/dev/null; do
        # sleep until the window opens
        sleep 0.5       
done

set_notification_icon >&3

# Waits for notification to exit
wait $notifpid

exec 3>&-

exit 0

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

Keyboard instead of Mouse

#616 Post by achim »

Hello everybody,

How can I move with the keyboard instead of the mouse in a selection dialog created with "--file-selection"?

Best regards, Achim

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

Re: Keyboard instead of Mouse

#617 Post by misko_2083 »

achim wrote:Hello everybody,

How can I move with the keyboard instead of the mouse in a selection dialog created with "--file-selection"?

Best regards, Achim
Tab to change the focus to another widget, then arrow keys up and down.
To get to the right pane when you open a yad file selection press shift+tab.

achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

Re: Keyboard instead of Mouse

#618 Post by achim »

misko_2083 wrote:
achim wrote:Hello everybody,

How can I move with the keyboard instead of the mouse in a selection dialog created with "--file-selection"?

Best regards, Achim
Tab to change the focus to another widget, then arrow keys up and down.
To get to the right pane when you open a yad file selection press shift+tab.
Thanks misko_2083!

artsown
Posts: 403
Joined: Wed 12 Sep 2012, 18:35

cpu temperature monitor

#619 Post by artsown »

Say I have a folder holding icons showing temperatures from 10C to
105C. My bash script finds the temp and selects the appropriate icon.
How using yad can I place the icon in the tray? I would arrange to do
this "find temp and display icon" loop every few seconds.

Edit: The icons are from an old tempicon app having .svg extensions,
if that's a concern or consideration. Maybe they can be converted if
necessary.

Art

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

#620 Post by fredx181 »

misko_2083 wrote:Fredx181, if you want to make one, even simpler version of yradio,
you can use the list for navigation between the radio categories and stations.

Here's an example with the notification icon.
....
....
Hey Misko, thanks anyway, but I have no idea how to implement your code in yradio, if you feel like it sometime, maybe you want to do it ?
(also I'm not sure if I understand what the improvement exactly can be :roll: , but it sounds promising what you're suggesting )

Fred

Post Reply