YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
stemsee

#691 Post by stemsee »

8)

in the trans script find google and change http: to https: problem solved.

Code: Select all

function googleInit() {
HttpProtocol = "https://"
HttpHost = "translate.googleapis.com"
HttpPort = 80
}
function googleRequestUrl(text, sl, tl, hl,    qc) {
qc = Option["no-autocorrect"] ? "qc" : "qca";
return HttpPathPrefix "/translate_a/single?client=gtx"\
"&ie=UTF-8&oe=UTF-8"\
"&dt=bd&dt=ex&dt=ld&dt=md&dt=rw&dt=rm&dt=ss&dt=t&dt=at&dt=gt"\
"&dt=" qc "&sl=" sl "&tl=" tl "&hl=" hl\
"&q=" preprocessByDump(text)
}
function googleTTSUrl(text, tl) {
return HttpProtocol HttpHost "/translate_tts?ie=UTF-8&client=gtx"\
"&tl=" tl "&q=" preprocessByDump(text)
}
function googleWebTranslateUrl(uri, sl, tl, hl) {
return "https://translate.google.com/translate?"\
"hl=" hl "&sl=" sl "&tl=" tl "&u=" uri
yandex is much more complex because the site has a translation limit for each visitor. it also requires user input 'captcha' to open service, also urls in the trans script are old and incorrect. I am learning the api for yandex.

stemsee

EDIT harldy yad related anymore![/code]

stemsee

#692 Post by stemsee »

My retro version, still with yandex. with engine icons
Attachments
trans_tray.sfs.gz
fake.gz
(52 KiB) Downloaded 128 times

User avatar
josejp2424
Posts: 556
Joined: Sun 01 Aug 2010, 22:35
Contact:

trans_tray

#693 Post by josejp2424 »

stemsee wrote:My retro version, still with yandex. with engine icons
I like your version.

Thank you.

mfb

#694 Post by mfb »

Hi stemsee,

Thank you very much for your all-that's-needed sfs @ two posts above this one.

The shot below shows the output from the German (in my clipboard):
Also mein erstes Problem war schon, das ich das Deutsche Sprachpaket
having chosen output using Google, Bing and Yandex in Danish, Dutch, English and Esperanto.

-------------------------------------------------

I seem to recall you are fluent in 6 or 7 languages, Argolance, Fredx181 and Vovchik also have multi-language fluency and are also star app-makers who have already directed their minds to language translation issues.

My thoughts, tongue-in-cheek, are:

* would be good to auto-fast-remove the sfs on tray exit
* and (perhaps) to add a right-click Preferences section
for say unticking "exit confirmation"
Ticking full screen display
Choosing a male or female voice
* Additional selection of text to speech
* Translating a lengthy piece (e.g. a book) with progress indicator.
* Save and restore (with alternative options)

and the miracle of including any original pictures in the output.

As regards the "auto-fast-remove" Forum member seaside has already facilitated this and MochiMoppel has done it for pets (your sfs could be easily converted to a pet for any user who needs or prefers that).

This thread may not be the most appropriate place to implement any such thoughts - and Argolance and Vovchik have already provided alternative translation apps elsewhere (so perhaps they might add links and brief comments)

My special thanks to all with honourable mention above.
Attachments
ex German.jpg
(93.42 KiB) Downloaded 659 times

stemsee

#695 Post by stemsee »

mfb wrote:Hi stemsee,

Thank you very much for your all-that's-needed sfs @ two posts above this one.
you're welcome
I
seem to recall you are fluent in 6 or 7 languages, Argolance, Fredx181 and Vovchik also have multi-language fluency and are also star app-makers who have already directed their minds to language translation issues.
are you a stalker? :lol:
yes, 7 and counting. I have also learnt the Russian, Greek and Hebrew alphabets. I tried Sanskrit grammar but didn't get far, at least not as far as with welsh!!! My 6 year old son learnt to read and speak Welsh phonetics in 2 weeks (you'd think the school would notice an absolute genius and get him into a private school as by law there are places reserved for poor talented kids .... England is however even more corrupt and racist than USA, China and Russia put together! Truth is stranger than fiction). Now he is 10 and learning the drums by computer gaming method - speaks Spanish, Welsh, English and Chinese! Still no place in school though, 'coz we be cheeky!!
My thoughts, tongue-in-cheek, are:

* would be good to auto-fast-remove the sfs on tray exit
* and (perhaps) to add a right-click Preferences section
for say unticking "exit confirmation"
Ticking full screen display
Choosing a male or female voice
* Additional selection of text to speech
* Translating a lengthy piece (e.g. a book) with progress indicator.
* Save and restore (with alternative options)

and the miracle of including any original pictures in the output.

As regards the "auto-fast-remove" Forum member seaside has already facilitated this and MochiMoppel has done it for pets (your sfs could be easily converted to a pet for any user who needs or prefers that).
Only this?! Nothing else? Are you sure you're not GCMartin in disguise? :lol:

Sfs unload on exit .... easy
rightclick menu with more options - easy
Voice translation is more interesting for me, and embedded images - probably requires yad --html
Progress indicator - easy .... progress indicator with real progress indication ... FRED!!?
Lengthy translations - easy - simply reiterate after 3000 characters or alternate between different engines.
Save and Restore and with EDITs - easy
'Alternative options' what the hell does that mean???
This thread may not be the most appropriate place to implement any such thoughts
no shiite!
- and Argolance and Vovchik have already provided alternative translation apps elsewhere (so perhaps they might add links and brief comments)
please do...
My special thanks to all with honourable mention above.
and me!

What's it worth to you? :roll:

stemsee

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

#696 Post by fredx181 »

Nice stemsee ! I like the tray icon change.

Attached my 'take', included the tray icon change, but difference is that .svg icons are used.
I like vovchiks's "self contained" approach, so converted the .png icons to .svg and added the .svg codes in the script (is rather large now because of that)
(used the java based program for converting to .svg from here: https://github.com/jankovicsandras/imagetracerjava)
Also removed Yandex and added some extra's to the Menu, "Help" and "Install/Upgrade trans"

Fred
Attachments
2019-08-23-134304_659x712_scrot_559x604.jpg
(105.45 KiB) Downloaded 542 times
trans_tray2.gz
Remove fake .gz and make executable
(109.68 KiB) Downloaded 141 times

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#697 Post by Argolance »

Bonjour,

All this is very exciting! :D

@josejp2424
I don't know why you said you were:
josejp2424 wrote:amused by your comments
Be assured I don't take this the wrong way. I'm rather glad I entertained you but it is true and seems to have gone unnoticed:
argolance wrote:By default, the middle mouse button closes the notification icon and therefore, the "exit" menu entry may not be necessary, unless the central button is disabled.
This may not have been clearly expressed: a click with the middle button of the mouse on the systray icon closes it. So there is one of the two possibilities to exit that is useless. It seems (to me) that the exit with the middle button should be disabled in the yad script... especially since it is easy to click it by accident!

Cordialement.

stemsee

#698 Post by stemsee »

fredx181 wrote:Nice stemsee ! I like the tray icon change.

Attached my 'take', included the tray icon change, but difference is that .svg icons are used.
I wanted to do that, but after editing just the normal png files for ages, I couldn't be bothered. So thnx
(used the java based program for converting to .svg from here: https://github.com/jankovicsandras/imagetracerjava)
Thanx again .... this will be useful.
Also removed Yandex and added some extra's to the Menu, "Help" and "Install/Upgrade trans"

Fred
Good start on menu extras. Save/export translation as pdf or txt will be nice. It's looking good!

Argolance, I agree --disable-middle should be used if the exit in menu stays. I like the exit in menu, actually.

stemsee

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

New topic for trans_tray

#699 Post by fredx181 »

Hi All, I'm having the feeling that this "trans_tray" development is not over yet :wink:
That's why I opened new topic here:
http://murga-linux.com/puppy/viewtopic.php?t=116794

Also fine for me personally to continue here, btw, but I thought it's better to have its own thread for trans_tray, to not further "pollute" this thread, after all its purpose is for yad - tips.
So... see you there, or not... :)

Fred

stemsee

#700 Post by stemsee »

Hi Misko

Can you help with this? I am trying to cat a file into a pipe. But it's not showing anything.

Code: Select all

function savedtranstexts (){
	rm -f /tmp/TP
	stxtp=/tmp/TP
	mkfifo -m 755 $stxtp 
	exec 4<> $stxtp
clr=`echo -e '\f' >/tmp/TP`
yad --plug=$$ --tabnum=1 --list --item-separator=" " --column="Saved Trans:CBE" `ls $HOME/Trans-Text*` --select-action='bash -c "$clr";cat $1 >$stxtp"'  & 
yad --plug=$$ --tabnum=2 --editable --text-info <&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=hori

}; export -f savedtranstexts

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:

Post Reply