YAD - Tips

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

stemsee

#721 Post by stemsee »

Code: Select all

export z

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

#722 Post by achim »

@ Stemsee,

where exactly should I enter the code?

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

#723 Post by achim »

with "export z" I already tested yesterday, unfortunately did not work, strange

stemsee

#724 Post by stemsee »

fredx181 wrote: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)); export z;

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
because you want the last value assigned to z, not the first. So z gets updated on each iteration of the loop. You could write it to a file in /tmp ((NOTE BENE not '[' but '(( ))'

Code: Select all

z=$((z + 1)); echo "z=$z" >/tmp/z

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

#725 Post by achim »

... You could write it to a file in /tmp ...
I would like to choose this option. Just how do I call the variable later - z=$(/tmp/z) ?

Post Reply