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
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

#701 Post by misko_2083 »

Have to add a newline character at the end because formfeed character has no effect if the file sent to text-info dialog doesn't end with the newline char.
echo -e '\n' >/tmp/TP
without it formfeed character is added at the end of the last string.

Code: Select all

function savedtranstexts (){
   rm -f /tmp/TP
   stxtp=/tmp/TP
   mkfifo -m 755 $stxtp
   exec 4<> $stxtp
yad --plug=$$ --tabnum=1 --list --item-separator=" " --column="Saved Trans" \
    $(for f in $HOME/Trans-Text*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
    --select-action="bash -c \"echo -e '\f' >/tmp/TP ; cd "$HOME" ; cat  "%s" >/tmp/TP ; echo -e '\n' >/tmp/TP \""  &
yad --plug=$$ --tabnum=2 --editable --text-info --listen <&4 &

WINDOWTITLE="Saved-Texts"
yad --window-icon=$pics/wireless.png --width=600 --height=440 --no-buttons --on-top --paned --splitter=160 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal

}; export -f savedtranstexts

stemsee

#702 Post by stemsee »

Thanks Misko!

I could not have got even close to that!

Thank you so much! If you have the inclination to explain in detail what's going on in there I would be very grateful.

stemsee

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

#703 Post by fredx181 »

Can anyone shine a light on this ? (and possibly knows a solution/workaround ?)
Using for both examples same --geometry, the first example has shorter text than the second, for me with the first, the width can be adjusted as it should be, but not with the second one. I'm using yad version 0.38.2

Code: Select all

GUI=$(yad --title=Test --button="gtk-quit:1" --button="gtk-ok:0" --text "This is a rather short text, width and height can be adjusted. " --geometry 700x400+70+120)

Code: Select all

GUI=$(yad --title=Test --button="gtk-quit:1" --button="gtk-ok:0" --text "This is a rather long text, why the width cannot be adjusted ? Only height. " --geometry 700x400+70+120)
EDIT:
Actually I mean that width cannot be made smaller with the second example
EDIT2: Tried now also with yad version 0.41, same problem.
EDIT3: Btw, same problem without --geometry, just using --width and --height :

Code: Select all

GUI=$(yad --title=Test --button="gtk-quit:1" --button="gtk-ok:0" --text "This is a rather long text, why the width cannot be adjusted ? Only height. " --center --width=700 --height=400)
Fred

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

#704 Post by misko_2083 »

stemsee wrote:Thanks Misko!

I could not have got even close to that!

Thank you so much! If you have the inclination to explain in detail what's going on in there I would be very grateful.

stemsee
Populate the list:
We skip ls, because ls is not meant for scripts.
It's designed to make a colorful, user friendly output.
We use built in

Code: Select all

for f in $HOME/bla-bla*
If it's a file (not dir) echo file name (removes the path)

Code: Select all

[[ -f "${f}" ]]  && echo "${f##*/}"
full

Code: Select all

$(for f in $HOME/Trans-Text*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)
Select action:
yad forks the process and can't use the variables (unless you export them)
Write to /tmp/TP directly
resets text info:

Code: Select all

echo -e '\f' >/tmp/TP
cd to the dir containing files,

gets the value of the selected row item %s and write to /tmp/TP

Code: Select all

 cat  "%s" >/tmp/TP
At the end we need new line

Code: Select all

 echo -e '\n' >/tmp/TP
to be able to reset text-info on next selected row when echo -e '\f' >/tmp/TP is executed.
full cmd

Code: Select all

--select-action="bash -c "echo -e '\f' >/tmp/TP ; cd "$HOME" ; cat  "%s" >/tmp/TP ; echo -e '\n' >/tmp/TP ""

stemsee

#705 Post by stemsee »

thanks misko


:)

Wognath
Posts: 423
Joined: Sun 19 Apr 2009, 17:23

timeout=zero

#706 Post by Wognath »

In a script, I call a function

Code: Select all

yad --timeout=$x --button=cancel && cancel action || timeout action
Usually, $x is 10 or 60, but in one case I want to go immediately to the timeout action. x=0 disables timeout, but any non-integer string results in yad error, exit code 255, and gives the desired result.
A trivial tip, but mine own :?

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#707 Post by MochiMoppel »

:lol:
I wouldn't count on it.
Exploiting an error is one thing and works here since you don't test for a real timeout (exit code 70), but relying on a possible bug is another thing. Other dialogs like Xdialog or gxmessage treat a timeout text string (or empty string) as "0", the same as bash. IMO this is the way yad should behave.

Instead of letting yad crash you could achieve what you want by testing $x. If it is empty or contains any non-numeric character then go straight to your timeout action:

Code: Select all

[[ $x =~ [0-9]+ ]] && yad --timeout=$x --button=cancel && echo cancel action || echo timeout action

Wognath
Posts: 423
Joined: Sun 19 Apr 2009, 17:23

#708 Post by Wognath »

MM, thanks for your insight, as always. If the author fixes this "possible bug", then I'll certainly have to change my script!

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

convert flexibly

#709 Post by achim »

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


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


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

Re: convert flexibly

#710 Post by misko_2083 »

achim wrote: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
You made one for each forum. (•‿•)
The answer is is in the other one. :lol:

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

Re: convert flexibly

#711 Post by achim »

You are the best - thank you :) :)

stemsee

#712 Post by stemsee »

i cant activate yad notification icon right-click on touchscreen. what would be a workaround?

stemsee

stemsee

#713 Post by stemsee »

To answer my own question! I added "bash -c 'xdotool click 3'" as yad notification --command.

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

#714 Post by achim »

I have a question for the experts,

is it possible to fix a YAD information window so that only the content is changed via a for loop running in the background?

Greetings achim

stemsee

#715 Post by stemsee »

achim

im not an expert but yes,

Code: Select all

mkfifo /tmp/testpipe
exec 8<> /tmp/testpipe

yad --text-info --listen --width=200 --height=200 <&8 &
while sleep 8
do
echo -e '\f' >/tmp/testpipe
yad --entry >/tmp/testpipe
done
comment out the echo line if you want accumulative updates.

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

#716 Post by achim »

Thank you stemseee, you helped me a lot!

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

#717 Post by achim »

After I have dealt a little closer with the answer of stemsee I have to say that it is for me at the moment a little more complicated than I thought. Especially since I have not used mkfifo and exec so often. But I want to learn to handle it.
Currently I have a snippet of code with which I want to reach, which can be seen in a YAD window, which image files are being copied. However, this code opens a new window for each file. I have not been able to apply the example of stemsee to my situation.

Code: Select all

....
z=0

for f in *.jpg; do name=`echo "${f%.*}"`; echo "Kopiervorgang des Bildes "$f" läuft...";
	rsync -t $CAMERA/"$f" $ZIEL/$DATE/;
	z=$[$z+1];
TEXT='<span color=\"blue\" font="Monospace italic 12">

Der Kopiervorgang des Bildes 

'$f'

wird als laufende Nr. '$z' durchgeführt...

</span>'
	yad --text="$TEXT" --width=600 --fixed --window-icon="$HOME/.icons/Movies-icon24.png" \
--title="Verlaufskontrolle" --text-align=center --no-buttons --timeout=1;	
done

echo $z Bilder kopiert.
....

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

#718 Post by fredx181 »

Hi achim, probably there are different ways, but what I would do is pipe to a yad --text-info dialog, like this:

Code: Select all

cd $CAMERA/
(
z=0
for f in *.jpg; do name=`echo "${f%.*}"`; echo "Kopiervorgang des Bildes "$f" läuft..."
   rsync -t $CAMERA/"$f" $ZIEL/$DATE/;
   z=$[$z+1];

echo "Der Kopiervorgang des Bildes"

echo "$f"

echo "wird als laufende Nr. $z durchgeführt..."
echo "$z Bilder kopiert"
done
) | yad --text="Kopiervorgang des Bildes" --width=600 --height 200 --fixed --window-icon="$HOME/.icons/Movies-icon24.png" --text-info --wrap --tail \
--title="Verlaufskontrolle" --text-align=center --no-buttons

stemsee

#719 Post by stemsee »

out of interest

non pipe version. type on commandline and hit enter to send.

How to make it send as it is being typed without newlines until return is hit??

Code: Select all

while true; do read ound; echo "$ound"; done | yad --text-info --listen --width=200 --height=200
Last edited by stemsee on Thu 19 Sep 2019, 11:52, edited 1 time in total.

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

#720 Post by achim »

Hello Fred,

this is a very good tip, which I also like to take over. However, after terminating the for loop, the variable "z" is no longer available. Do you know how to get around this problem?

PS. would like to give you some coffee for your good tips. Are you possibly in Germany? :)

Post Reply