YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
achim
Posts: 48
Joined: Thu 13 Apr 2017, 19:36
Location: Germany

Create a continuous digital clock

#681 Post by achim »

Hello misko_2083,

your code works great.

Thank you for your help!

achim

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

#682 Post by fredx181 »

Hi stemsee, good luck with the notebook version, don't think I can help, didn't do much with that.
Also the
Code:
echo -----^$ex $i^-----
should be at the head instead of underlining each translation in case of a large body of text.
Code:
echo -----$ex $i-----
Yes, would be much better, also I like showing the full language names, so made the "trans_paste" function this(see pic):

Code: Select all

trans_paste () {
#set -x
export TLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null)
export _TLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null | awk '{print $1}' | tr '\n' '+' | sed 's/.$//')
[ -z "$TLANG" ] && export TLANG="English - en"
export ENGINE=$(cat /tmp/_trans_engine_ 2> /dev/null)
[ -z "$ENGINE" ] && ENGINE=google
echo "Using $ENGINE for translating"
ICON="/tmp/trans-paste.svg"
if [ ! -e "$ICON" ]; then
   SVG="<""svg height='100' width='100'>
     <path style='fill:red;stroke:darkred;stroke-width:3;'
     d='M 93,62 C 83,82 65,96 48,96 32,96 19,89 15,79 L 5,90 5,53
     40,53 29,63 c 0,0 5,14 26,14 16,0 38,-15 38,-15 z'/>
     <path style='fill:red;stroke:darkred;stroke-width:3;'
     d='M 5,38 C 11,18 32,4 49,4 65,4 78,11 85,21 L 95,10 95,47
     57,47 68,37 C 68,37 63,23 42,23 26,23 5,38 5,38 z'/>
   </svg>"
   echo "$SVG" > /tmp/trans-paste.svg
fi
HELP=" Translating to $_TLANG... \n Press <b>ESC</b> key or click <b>EXIT</b> to dismiss."
MYTITLE="Trans"
BUT="<span color='darkblue'><b>Exit</b></span>"
FONT="Mono 12"
TWIDTH=$(xdpyinfo  | grep 'dimensions:' | cut -d' ' -f7 | cut -d'x' -f1)
SWIDTH=$(( $TWIDTH - 600 ))
#echo $SWIDTH
for ex in $ENGINE
do
while read i; do
echo " >  $ex translation to $(echo $i | awk '{print $1}'):"
xclip -o | trans -e $ex -b -tl $(echo $i | awk '{print $NF}')
done <<< "$TLANG"; done | tee >(yad \
--window-icon="$ICON" \
--text-align=center \
--title="$MYTITLE" \
--geometry=600x600+$SWIDTH+100 \
--fore="black" --back="#fef1e0" \
--margins=5 \
--button="$BUT" \
--text="$HELP" \
--fontname="$FONT" \
--text-info  --wrap)
}
export -f trans_paste
Fred
Attachments
2019-08-22-143328_600x629_scrot.png
(61.75 KiB) Downloaded 325 times

stemsee

#683 Post by stemsee »

Hi Fred

Is it possible to make the headings a different text color? If not I prefer the previous style!

The new code is difficult to understand, for me!

However _ _ _ _ _ Each to their own_ _ _ _ _ :lol:

stemsee

EDIT: I just discovered that google web translate has a character limit of about 3900! Maybe the script could be made to chunk xclip data accordingly?

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

#684 Post by fredx181 »

stemsee wrote:Is it possible to make the headings a different text color? If not I prefer the previous style!
I'm almost sure that's not possible with the --text-info dialog. (e.g.cannot use <span...> etc..), but correct me if I'm wrong.
What exactly do you prefer then as "previous style" ?

EDIT:
EDIT: I just discovered that google web translate has a character limit of about 3900! Maybe the script could be made to chunk xclip data accordingly?
Mmm.. that's a pity, not sure yet how to handle that.
BTW, I think it's better to remove Yandex from the translator choices, it really doesn't work well.

Fred

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

#685 Post by misko_2083 »

stemsee wrote: EDIT hi Misko

wouldn't

Code: Select all

while sleep 1; do
be better?
Depends on the moment. :)
fredx181 wrote:
stemsee wrote:Is it possible to make the headings a different text color? If not I prefer the previous style!
I'm almost sure that's not possible with the --text-info dialog. (e.g.cannot use <span...> etc..), but correct me if I'm wrong.
What exactly do you prefer then as "previous style" ?

EDIT:
EDIT: I just discovered that google web translate has a character limit of about 3900! Maybe the script could be made to chunk xclip data accordingly?
how about html? :)

Code: Select all

 echo "<h3>heading</h3><font color=red>some text</font>" | yad --html

stemsee

#686 Post by stemsee »

Hi Fred, Misko et al

yad --html sounds like an interesting development!

by previous I meant the middle style.... not just _ _ _ _ dashes, but with $ex $i and placed as heading of translated text. I found that my eyes could more easily search and find each translated language section. but that's just my experience.

Indeed remove yandex ... maybe replace?? ... DeepL...?
stemsee

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

#687 Post by fredx181 »

misko wrote:how about html? Smile
Code:
echo "<h3>heading</h3><font color=red>some text</font>" | yad --html
Ok, thanks, never did anything with the yad --html option, I think the compiled yad has to be configured with that, most yad packages (for e.g. Puppy or others) don't have this option by default, I think.

@stemsee
The new code is difficult to understand, for me!
Not so difficult in fact, to explain:
At start of function:

Code: Select all

export TLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null)
$TLANG will output the full contents of $HOME/.trans_target_lang2
And further on:

Code: Select all

while read i; do
echo " >  $ex translation to $(echo $i | awk '{print $1}'):"
xclip -o | trans -e $ex -b -tl $(echo $i | awk '{print $NF}')
done <<< "$TLANG";
Will extract the full language name, e.g. Spanish : $ex translation to $(echo $i | awk '{print $1}')
and the locale code to be used by trans, e.g. es : trans -e $ex -b -tl $(echo $i | awk '{print $NF}')

EDIT:
by previous I meant the middle style.... not just _ _ _ _ dashes, but with $ex $i and placed as heading of translated text. I found that my eyes could more easily search and find each translated language section. but that's just my experience.
Ok, but how would you prefer exactly then as header, something like (or.. ?):
----- google translate to Bulgarian -----

I think deepl isn't supported by trans anymore.

Fred
Last edited by fredx181 on Thu 22 Aug 2019, 15:44, edited 1 time in total.

stemsee

#688 Post by stemsee »

fredx181 wrote: Ok, but how would you prefer exactly then as header, something like (or.. ?):
----- google translate to Bulgarian -----

Fred
Yes that's clearer!

EDIT 'tee >' is not needed

stemsee

#689 Post by stemsee »

I found the bug for google.

And I know why yandex is problematic.

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

#690 Post by fredx181 »

stemsee wrote:I found the bug for google.

And I know why yandex is problematic.
So... what did you find then ?

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 133 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 143 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

Post Reply