YAD - Tips
Dear all,
I think the exit button in the popup is useful. If you are testing versions, or just cleaning up, it is useful. If you accidentally click it, which might happen once in a while, there is nothing stopping you from restarting the script, either via a possible menu entry, via a desktop file or via a click in ROX. I would leave it where it is, since it has a purpose, at least for me.
With kind regards,
vovchik
I think the exit button in the popup is useful. If you are testing versions, or just cleaning up, it is useful. If you accidentally click it, which might happen once in a while, there is nothing stopping you from restarting the script, either via a possible menu entry, via a desktop file or via a click in ROX. I would leave it where it is, since it has a purpose, at least for me.
With kind regards,
vovchik
- josejp2424
- Posts: 556
- Joined: Sun 01 Aug 2010, 22:35
- Contact:
button exit
I understand you very well what you say. It's fine for me too.vovchik wrote:Dear all,
I think the exit button in the popup is useful. If you are testing versions, or just cleaning up, it is useful. If you accidentally click it, which might happen once in a while, there is nothing stopping you from restarting the script, either via a possible menu entry, via a desktop file or via a click in ROX. I would leave it where it is, since it has a purpose, at least for me.
With kind regards,
vovchik
but I am looking at it from the end user perspective.
It is not practical
- Argolance
- Posts: 3767
- Joined: Sun 06 Jan 2008, 22:57
- Location: PORT-BRILLET (Mayenne - France)
- Contact:
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.josejp2424 wrote:I understand you very well what you say. It's fine for me too.
but I am looking at it from the end user perspective.
It is not practical
What a shame that improvements and features are lost from one version to another due to a lack of coordination between the different jobs. I wonder if it would not be wise to open a new topic dedicated to this project. I must admit that by putting the little script online, I didn't think it would generate so much interest and enthusiasm.
This forum is really amazing.
Cheers!
- josejp2424
- Posts: 556
- Joined: Sun 01 Aug 2010, 22:35
- Contact:
tran_tray
I am amused by your commentsArgolance 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.josejp2424 wrote:I understand you very well what you say. It's fine for me too.
but I am looking at it from the end user perspective.
It is not practical
What a shame that improvements and features are lost from one version to another due to a lack of coordination between the different jobs. I wonder if it would not be wise to open a new topic dedicated to this project. I must admit that by putting the little script online, I didn't think it would generate so much interest and enthusiasm.
This forum is really amazing.
Cheers!
Maybe we should open a poll question about this EXIT matter
It's easy to remove from menu, btw, just delete the selected blue showing on pic below
Fred
It's easy to remove from menu, btw, just delete the selected blue showing on pic below
Fred
- Attachments
-
- 2019-08-20-093859_987x98_scrot_787x78.png
- Delete the blue for no EXIT entry in menu
- (44.73 KiB) Downloaded 424 times
How about re-coding to allow two or three instances, so translating from say Chinese to English and Chinese to Dutch and Chinese to Spanish will be automatic. And/or allow comparison of translations by three different services.
Last edited by stemsee on Tue 20 Aug 2019, 14:12, edited 2 times in total.
Hi All,
As a compromise for the EXIT menu entry issue here's new trans_tray, which gives a yes/no dialog "Are you sure ... ... ?" when clicking on Exit.
Also made small fix for when canceling (or clicking Ok without selecting language) the "Select target language" list dialog, previously it switched to (default) English, now language stays on what it was before, as it should be IMO.
@stemsee
Fred
As a compromise for the EXIT menu entry issue here's new trans_tray, which gives a yes/no dialog "Are you sure ... ... ?" when clicking on Exit.
Also made small fix for when canceling (or clicking Ok without selecting language) the "Select target language" list dialog, previously it switched to (default) English, now language stays on what it was before, as it should be IMO.
@stemsee
Probably in theory it's possible looking at the options of trans, but.. phew... to implement that in this script, it will be quite a challengeHow about re-coding to allow two or three instances, so translating from say Chinese to English and Chinese to Dutch and Chinese to Spanish will be automatic. And/or allow comparison of translations by three different services.
Fred
- Attachments
-
- trans_tray.gz
- Remove fake .gz and make executable
- (6.62 KiB) Downloaded 95 times
Last edited by fredx181 on Tue 20 Aug 2019, 17:55, edited 1 time in total.
- josejp2424
- Posts: 556
- Joined: Sun 01 Aug 2010, 22:35
- Contact:
trans_tray
I like the new output dialog.fredx181 wrote:Hi All,
As a compromise for the EXIT menu entry issue here's new trans_tray, which gives a yes/no dialog "Are you sure ... ..." when clicking on Exit.
Also made small fix for when canceling (or clicking Ok without selecting language) the "Select target language" list dialog, previously it switched to (default) English, now language stays on what it was before, as it should be IMO.
@stemseeProbably in theory it's possible looking at the options of trans, but.. phew... to implement that in this script, it will be quite a challengeHow about re-coding to allow two or three instances, so translating from say Chinese to English and Chinese to Dutch and Chinese to Spanish will be automatic. And/or allow comparison of translations by three different services.
Fred
this is better to avoid closing by mistake
- Attachments
-
- exit.jpg
- exit button
- (31.45 KiB) Downloaded 347 times
I cannot fnd trans' executable! please post a copy.
here is a version i cannot test, allows multiple target languages. Maybe needs tweaking.
here is a version i cannot test, allows multiple target languages. Maybe needs tweaking.
Code: Select all
#!/bin/bash
running=`ps -e | grep trans_tray | wc -l`
[[ "$running" -gt 4 ]] && exit
export PROG=$(basename $0)
nl="
"
export ICON="/tmp/trans-tray.svg"
if [ ! -e "$ICON" ]; then
SVG="<""svg height='100' width='100'>
<path style='fill:skyblue;stroke:blue;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:skyblue;stroke:blue;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-tray.svg
fi
trans_paste () {
#set -x
export TLANG=$(cat $HOME/.trans_target_lang 2> /dev/null)
[ -z "$TLANG" ] && export TLANG="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=" 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
cnt=1
xclip -o | for i in $TLANG
do
case $cnt in
1) ENGINE=google;;
2) ENGINE=bing;;
3) ENGINE=yandex;;
esac
trans -e $ENGINE -b -tl $i
export cnt=$((cnt + 1))
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) >(xclip -i)
}
export -f trans_paste
get_menu () {
export TARGETLANG=$(cat $HOME/.trans_target_lang 2> /dev/null)
[ -z "$TARGETLANG" ] && export TARGETLANG="English - en"
export ENGINE=$(cat /tmp/_trans_engine_ 2> /dev/null)
if [ -z "$ENGINE" ]; then
export CHECKG="!gtk-ok" # set google default
else
unset CHECKG CHECKB CHECKY
case $ENGINE in
google) export CHECKG="!gtk-ok";;
bing) export CHECKB="!gtk-ok";;
yandex) export CHECKY="!gtk-ok";;
esac
fi
exec 3<> $PIPE
GET_MENU="Google!bash -c set_google$CHECKG|Bing!bash -c set_bing$CHECKB|Yandex!bash -c set_yandex$CHECKY|Select target language, currently: $TARGETLANG!bash -c set_target_language!gtk-edit|Exit!bash -c quit_tray!gtk-quit"
echo menu:"${GET_MENU}" >&3
} ; export -f get_menu
set_google () {
echo "google" > /tmp/_trans_engine_
#export CHECKG="!gtk-ok"
get_menu
} ; export -f set_google
set_bing () {
echo "bing" > /tmp/_trans_engine_
#export CHECKB="!gtk-ok"
get_menu
} ; export -f set_bing
set_yandex () {
echo "yandex" > /tmp/_trans_engine_
#export CHECKY="!gtk-ok"
get_menu
} ; export -f set_yandex
quit_tray () {
yad --title="Exit ?" --center --borders=6 --window-icon=$ICON --text=" Are you sure to exit $PROG ? \n " --button="gtk-no:1" --button="gtk-yes:0"
if [ $? -eq 0 ]; then
echo "quit" >$PIPE
rm -f $PIPE
exit
fi
}
export -f quit_tray
# add handler to manage process shutdown
function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
trap on_exit EXIT
set_target_language () {
LANGUAGES='
Afrikaans - af
Albanian - sq
Amharic - am
Arabic - ar
Armenian - hy
Azerbaijani - az
Basque - eu
Belarusian - be
Bengali - bn
Bosnian - bs
Bulgarian - bg
Cantonese - yue
Catalan - ca
Cebuano - ceb
Chichewa - ny
Chinese(Simple) - zh-CN
Chinese(Trad) - zh-TW
Corsican - co
Croatian - hr
Czech - cs
Danish - da
Dutch - nl
English - en
Esperanto - eo
Estonian - et
Fijian - fj
Filipino - tl
Finnish - fi
French - fr
Frisian - fy
Galician - gl
Georgian - ka
German - de
Greek - el
Gujarati - gu
Haitian-Creole - ht
Hausa - ha
Hawaiian - haw
Hebrew - he
Hindi - hi
Hmong - hmn
Hmong-Daw - mww
Hungarian - hu
Icelandic - is
Igbo - ig
Indonesian - id
Irish - ga
Italian - it
Japanese - ja
Javanese - jv
Kannada - kn
Kazakh - kk
Khmer - km
Klingon - tlh
Korean - ko
Kurdish - ku
Kyrgyz - ky
Lao - lo
Latin - la
Latvian - lv
Lithuanian - lt
Luxembourgish - lb
Macedonian - mk
Malagasy - mg
Malay - ms
Malayalam - ml
Maltese - mt
Maori - mi
Marathi - mr
Mongolian - mn
Myanmar - my
Nepali - ne
Norwegian - no
Pashto - ps
Persian - fa
Polish - pl
Portuguese - pt
Punjabi - pa
Queretaro-Otomi - otq
Romanian - ro
Russian - ru
Samoan - sm
Scots-Gaelic - gd
Serbian(Cyr) - sr-Cyrl
Serbian(Latin) - sr-Latn
Sesotho - st
Shona - sn
Sindhi - sd
Sinhala - si
Slovak - sk
Slovenian - sl
Somali - so
Spanish - es
Sundanese - su
Swahili - sw
Swedish - sv
Tahitian - ty
Tajik - tg
Tamil - ta
Tatar - tt
Telugu - te
Thai - th
Tongan - to
Turkish - tr
Udmurt - udm
Ukrainian - uk
Urdu - ur
Uzbek - uz
Vietnamese - vi
Welsh - cy
Xhosa - xh
Yiddish - yi
Yoruba - yo
Yucatec-Maya - yua
Zulu - zu
'
TARGETLANG=$(yad --borders 6 --separator=" " \
--center --height 700 --width="350" --list --multiple \
--title="Target language for translation" \
--text=" <b>Select target language</b> \n Press on keyboard: ctrl+f to do a search, e.g. 'french' " \
--search-column=1 --hide-column=2 \
--print-column=0 --column " Language" \
--column " dummy " --column " Locale" $LANGUAGES \
--button="gtk-cancel:1" --button="gtk-ok:0")
if [ $? -eq 0 ] && [ -n "$TARGETLANG" ]; then
echo $TARGETLANG > $HOME/.trans_target_lang
export TARGETLANG=$(cat $HOME/.trans_target_lang 2> /dev/null)
get_menu
fi
}
export -f set_target_language
export PIPE="/tmp/TRANS_PIPE.$RANDOM"
mkfifo $PIPE
get_menu
POPUP_TEXT="<b>Left-click for Trans-Paste""$nl""Right-click for Menu</b>"
yad --notification --kill-parent --listen \
--image="$ICON" \
--text="$POPUP_TEXT" \
--text-align=center \
--command="bash -c trans_paste" <&3; ypd-$$="$YAD_PID"
- josejp2424
- Posts: 556
- Joined: Sun 01 Aug 2010, 22:35
- Contact:
tran_tray
I'm going to test thanks stemseestemsee wrote:I cannot fnd trans' executable! please post a copy.
here is a version i cannot test, allows multiple target languages. Maybe needs tweaking.
Code: Select all
#!/bin/bash running=`ps -e | grep trans_tray | wc -l` [[ "$running" -gt 4 ]] && exit export PROG=$(basename $0) nl=" " export ICON="/tmp/trans-tray.svg" if [ ! -e "$ICON" ]; then SVG="<""svg height='100' width='100'> <path style='fill:skyblue;stroke:blue;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:skyblue;stroke:blue;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-tray.svg fi trans_paste () { #set -x export TLANG=$(cat $HOME/.trans_target_lang 2> /dev/null) [ -z "$TLANG" ] && export TLANG="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=" 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 cnt=1 xclip -o | for i in $TLANG do case $cnt in 1) ENGINE=google;; 2) ENGINE=bing;; 3) ENGINE=yandex;; esac trans -e $ENGINE -b -tl $i export cnt=$((cnt + 1)) 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) >(xclip -i) } export -f trans_paste get_menu () { export TARGETLANG=$(cat $HOME/.trans_target_lang 2> /dev/null) [ -z "$TARGETLANG" ] && export TARGETLANG="English - en" export ENGINE=$(cat /tmp/_trans_engine_ 2> /dev/null) if [ -z "$ENGINE" ]; then export CHECKG="!gtk-ok" # set google default else unset CHECKG CHECKB CHECKY case $ENGINE in google) export CHECKG="!gtk-ok";; bing) export CHECKB="!gtk-ok";; yandex) export CHECKY="!gtk-ok";; esac fi exec 3<> $PIPE GET_MENU="Google!bash -c set_google$CHECKG|Bing!bash -c set_bing$CHECKB|Yandex!bash -c set_yandex$CHECKY|Select target language, currently: $TARGETLANG!bash -c set_target_language!gtk-edit|Exit!bash -c quit_tray!gtk-quit" echo menu:"${GET_MENU}" >&3 } ; export -f get_menu set_google () { echo "google" > /tmp/_trans_engine_ #export CHECKG="!gtk-ok" get_menu } ; export -f set_google set_bing () { echo "bing" > /tmp/_trans_engine_ #export CHECKB="!gtk-ok" get_menu } ; export -f set_bing set_yandex () { echo "yandex" > /tmp/_trans_engine_ #export CHECKY="!gtk-ok" get_menu } ; export -f set_yandex quit_tray () { yad --title="Exit ?" --center --borders=6 --window-icon=$ICON --text=" Are you sure to exit $PROG ? \n " --button="gtk-no:1" --button="gtk-yes:0" if [ $? -eq 0 ]; then echo "quit" >$PIPE rm -f $PIPE exit fi } export -f quit_tray # add handler to manage process shutdown function on_exit() { echo "quit" >&3 rm -f $PIPE } trap on_exit EXIT set_target_language () { LANGUAGES=' Afrikaans - af Albanian - sq Amharic - am Arabic - ar Armenian - hy Azerbaijani - az Basque - eu Belarusian - be Bengali - bn Bosnian - bs Bulgarian - bg Cantonese - yue Catalan - ca Cebuano - ceb Chichewa - ny Chinese(Simple) - zh-CN Chinese(Trad) - zh-TW Corsican - co Croatian - hr Czech - cs Danish - da Dutch - nl English - en Esperanto - eo Estonian - et Fijian - fj Filipino - tl Finnish - fi French - fr Frisian - fy Galician - gl Georgian - ka German - de Greek - el Gujarati - gu Haitian-Creole - ht Hausa - ha Hawaiian - haw Hebrew - he Hindi - hi Hmong - hmn Hmong-Daw - mww Hungarian - hu Icelandic - is Igbo - ig Indonesian - id Irish - ga Italian - it Japanese - ja Javanese - jv Kannada - kn Kazakh - kk Khmer - km Klingon - tlh Korean - ko Kurdish - ku Kyrgyz - ky Lao - lo Latin - la Latvian - lv Lithuanian - lt Luxembourgish - lb Macedonian - mk Malagasy - mg Malay - ms Malayalam - ml Maltese - mt Maori - mi Marathi - mr Mongolian - mn Myanmar - my Nepali - ne Norwegian - no Pashto - ps Persian - fa Polish - pl Portuguese - pt Punjabi - pa Queretaro-Otomi - otq Romanian - ro Russian - ru Samoan - sm Scots-Gaelic - gd Serbian(Cyr) - sr-Cyrl Serbian(Latin) - sr-Latn Sesotho - st Shona - sn Sindhi - sd Sinhala - si Slovak - sk Slovenian - sl Somali - so Spanish - es Sundanese - su Swahili - sw Swedish - sv Tahitian - ty Tajik - tg Tamil - ta Tatar - tt Telugu - te Thai - th Tongan - to Turkish - tr Udmurt - udm Ukrainian - uk Urdu - ur Uzbek - uz Vietnamese - vi Welsh - cy Xhosa - xh Yiddish - yi Yoruba - yo Yucatec-Maya - yua Zulu - zu ' TARGETLANG=$(yad --borders 6 --separator=" " \ --center --height 700 --width="350" --list --multiple \ --title="Target language for translation" \ --text=" <b>Select target language</b> \n Press on keyboard: ctrl+f to do a search, e.g. 'french' " \ --search-column=1 --hide-column=2 \ --print-column=0 --column " Language" \ --column " dummy " --column " Locale" $LANGUAGES \ --button="gtk-cancel:1" --button="gtk-ok:0") if [ $? -eq 0 ] && [ -n "$TARGETLANG" ]; then echo $TARGETLANG > $HOME/.trans_target_lang export TARGETLANG=$(cat $HOME/.trans_target_lang 2> /dev/null) get_menu fi } export -f set_target_language export PIPE="/tmp/TRANS_PIPE.$RANDOM" mkfifo $PIPE get_menu POPUP_TEXT="<b>Left-click for Trans-Paste""$nl""Right-click for Menu</b>" yad --notification --kill-parent --listen \ --image="$ICON" \ --text="$POPUP_TEXT" \ --text-align=center \ --command="bash -c trans_paste" <&3; ypd-$$="$YAD_PID"
Thanks stemsee, I modified your script to make it work with multiple languages selected, but could not figure out how to run the different translators after each other.
Right click on "the self-contained executable" and select: Save link as"
(depends on gawk)
@All anyone has opinion about the following ? :
In the "trans_paste" function there was originally at the end ">(xclip -i)" (I commented it out now below)
I've found that if you left-click the icon second or third time the output becomes very messy, because it loads xclip with the translated text (which can be handy but causes the mess if you click second or third time).
I'd say for this program it's better without the ">(xclip -i)".
P.S. At the moment the Google translator doesn't work for me, no idea why, Bing works.
Fred
It's here: https://github.com/soimort/translate-shell#installationI cannot fnd trans' executable! please post a copy.
Right click on "the self-contained executable" and select: Save link as"
(depends on gawk)
@All anyone has opinion about the following ? :
In the "trans_paste" function there was originally at the end ">(xclip -i)" (I commented it out now below)
I've found that if you left-click the icon second or third time the output becomes very messy, because it loads xclip with the translated text (which can be handy but causes the mess if you click second or third time).
I'd say for this program it's better without the ">(xclip -i)".
P.S. At the moment the Google translator doesn't work for me, no idea why, Bing works.
Code: Select all
#!/bin/bash
export PROG=$(basename $0)
running=`ps -e | grep -w "$PROG" | wc -l`
[[ "$running" -gt 2 ]] && exit # run only one instance
nl="
"
export ICON="/tmp/trans-tray.svg"
if [ ! -e "$ICON" ]; then
SVG="<""svg height='100' width='100'>
<path style='fill:skyblue;stroke:blue;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:skyblue;stroke:blue;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-tray.svg
fi
trans_paste () {
#set -x
export TLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null | awk '{print $NF}' | tr '\n' ' ' | sed 's/.$//')
export _TLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null | awk '{print $1}' | tr '\n' '+' | sed 's/.$//')
[ -z "$TLANG" ] && export TLANG="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 i in $TLANG
do
xclip -o | trans -e $ENGINE -b -tl $i
echo -----------------------------------------
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) #>(xclip -i)
}
export -f trans_paste
get_menu () {
export TARGETLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null | awk '{print $1}' | tr '\n' '+' | sed 's/.$//')
[ -z "$TARGETLANG" ] && export TARGETLANG="English"
export ENGINE=$(cat /tmp/_trans_engine_ 2> /dev/null)
if [ -z "$ENGINE" ]; then
export CHECKG="!gtk-ok" # set google default
else
unset CHECKG CHECKB CHECKY
[ "$ENGINE" = "google" ] && export CHECKG="!gtk-ok"
[ "$ENGINE" = "bing" ] && export CHECKB="!gtk-ok"
[ "$ENGINE" = "yandex" ] && export CHECKY="!gtk-ok"
fi
exec 3<> $PIPE
GET_MENU="Google!bash -c set_google$CHECKG|Bing!bash -c set_bing$CHECKB|Yandex!bash -c set_yandex$CHECKY|Select target language, currently: $TARGETLANG!bash -c set_target_language!gtk-edit|Exit!bash -c quit_tray!gtk-quit"
echo menu:"${GET_MENU}" >&3
} ; export -f get_menu
set_google () {
echo "google" > /tmp/_trans_engine_
#export CHECKG="!gtk-ok"
get_menu
} ; export -f set_google
set_bing () {
echo "bing" > /tmp/_trans_engine_
#export CHECKB="!gtk-ok"
get_menu
} ; export -f set_bing
set_yandex () {
echo "yandex" > /tmp/_trans_engine_
#export CHECKY="!gtk-ok"
get_menu
} ; export -f set_yandex
quit_tray () {
yad --title="Exit ?" --center --borders=6 --window-icon=$ICON --text=" Are you sure to exit $PROG ? \n " --button="gtk-no:1" --button="gtk-yes:0"
if [ $? -eq 0 ]; then
echo "quit" >$PIPE
rm -f $PIPE
exit
fi
}
export -f quit_tray
# add handler to manage process shutdown
function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
trap on_exit EXIT
set_target_language () {
LANGUAGES='
Afrikaans - af
Albanian - sq
Amharic - am
Arabic - ar
Armenian - hy
Azerbaijani - az
Basque - eu
Belarusian - be
Bengali - bn
Bosnian - bs
Bulgarian - bg
Cantonese - yue
Catalan - ca
Cebuano - ceb
Chichewa - ny
Chinese(Simple) - zh-CN
Chinese(Trad) - zh-TW
Corsican - co
Croatian - hr
Czech - cs
Danish - da
Dutch - nl
English - en
Esperanto - eo
Estonian - et
Fijian - fj
Filipino - tl
Finnish - fi
French - fr
Frisian - fy
Galician - gl
Georgian - ka
German - de
Greek - el
Gujarati - gu
Haitian-Creole - ht
Hausa - ha
Hawaiian - haw
Hebrew - he
Hindi - hi
Hmong - hmn
Hmong-Daw - mww
Hungarian - hu
Icelandic - is
Igbo - ig
Indonesian - id
Irish - ga
Italian - it
Japanese - ja
Javanese - jv
Kannada - kn
Kazakh - kk
Khmer - km
Klingon - tlh
Korean - ko
Kurdish - ku
Kyrgyz - ky
Lao - lo
Latin - la
Latvian - lv
Lithuanian - lt
Luxembourgish - lb
Macedonian - mk
Malagasy - mg
Malay - ms
Malayalam - ml
Maltese - mt
Maori - mi
Marathi - mr
Mongolian - mn
Myanmar - my
Nepali - ne
Norwegian - no
Pashto - ps
Persian - fa
Polish - pl
Portuguese - pt
Punjabi - pa
Queretaro-Otomi - otq
Romanian - ro
Russian - ru
Samoan - sm
Scots-Gaelic - gd
Serbian(Cyr) - sr-Cyrl
Serbian(Latin) - sr-Latn
Sesotho - st
Shona - sn
Sindhi - sd
Sinhala - si
Slovak - sk
Slovenian - sl
Somali - so
Spanish - es
Sundanese - su
Swahili - sw
Swedish - sv
Tahitian - ty
Tajik - tg
Tamil - ta
Tatar - tt
Telugu - te
Thai - th
Tongan - to
Turkish - tr
Udmurt - udm
Ukrainian - uk
Urdu - ur
Uzbek - uz
Vietnamese - vi
Welsh - cy
Xhosa - xh
Yiddish - yi
Yoruba - yo
Yucatec-Maya - yua
Zulu - zu
'
TARGETLANG=$(yad --borders 6 --separator=" " \
--center --height 700 --width="350" --list --multiple \
--title="Target language for translation" \
--text=" <b>Select target language</b> \n Press on keyboard: ctrl+f to do a search, e.g. 'french' " \
--search-column=1 --hide-column=2 \
--print-column=0 --column " Language" \
--column " dummy " --column " Locale" $LANGUAGES \
--button="gtk-cancel:1" --button="gtk-ok:0")
if [ $? -eq 0 ] && [ -n "$TARGETLANG" ]; then
echo "$TARGETLANG" > $HOME/.trans_target_lang2
export TARGETLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null)
get_menu
fi
}
export -f set_target_language
export PIPE="/tmp/TRANS_PIPE.$RANDOM"
mkfifo $PIPE
get_menu
POPUP_TEXT="<b>Left-click for Trans-Paste""$nl""Right-click for Menu</b>"
yad --notification --kill-parent --listen \
--image="$ICON" \
--text="$POPUP_TEXT" \
--text-align=center \
--command="bash -c trans_paste" <&3; ypd-$$="$YAD_PID"
- Attachments
-
- 2019-08-21-200339_602x629_scrot.png
- French+German+Spanish
- (66.43 KiB) Downloaded 227 times
That's why I let it run three instances, then one can choose any number of languages to translate for each instance of the three tray menus.fredx181 wrote:Thanks stemsee, I modified your script to make it work with multiple languages selected, but could not figure out how to run the different translators after each other.
However I will add a simple edit to allow one instance to do all three engines (I think!?).
thanks for trans link.
ok here it's working. I think that choosing the engines same way as choosing the languages would be better. As it is all 3 engines are used with google last, or one selected engine is used. Tested with 4 selected languages.
Needed only a nested loop; with the outer loop for each engine.
Needed only a nested loop; with the outer loop for each engine.
Code: Select all
#!/bin/bash
export PROG=$(basename $0)
running=`ps -e | grep -w "$PROG" | wc -l`
[[ "$running" -gt 2 ]] && exit # run only one instance
nl="
"
export ICON="/tmp/trans-tray.svg"
if [ ! -e "$ICON" ]; then
SVG="<""svg height='100' width='100'>
<path style='fill:skyblue;stroke:blue;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:skyblue;stroke:blue;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-tray.svg
fi
trans_paste () {
#set -x
export TLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null | awk '{print $NF}' | tr '\n' ' ' | sed 's/.$//')
export _TLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null | awk '{print $1}' | tr '\n' '+' | sed 's/.$//')
[ -z "$TLANG" ] && export TLANG="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
for i in $TLANG
do
xclip -o | trans -e $ex -b -tl $i
echo ---------------^$ex $i^-------------------
done; 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
get_menu () {
export TARGETLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null | awk '{print $1}' | tr '\n' '+' | sed 's/.$//')
[ -z "$TARGETLANG" ] && export TARGETLANG="English"
export ENGINE=$(cat /tmp/_trans_engine_ 2> /dev/null)
if [ -z "$ENGINE" ]; then
export CHECKG="!gtk-ok" # set google default
else
unset CHECKG CHECKB CHECKY CHECKA
[ "$ENGINE" = "yandex bing google" ] && export CHECKG="!gtk-ok" CHECKB="!gtk-ok" CHECKY="!gtk-ok" CHECKA="!gtk-ok"
[ "$ENGINE" = "google" ] && export CHECKG="!gtk-ok"
[ "$ENGINE" = "bing" ] && export CHECKB="!gtk-ok"
[ "$ENGINE" = "yandex" ] && export CHECKY="!gtk-ok"
fi
exec 3<> $PIPE
GET_MENU="Google!bash -c set_google$CHECKG|Bing!bash -c set_bing$CHECKB|Yandex!bash -c set_yandex$CHECKY|All!bash -c set_all$CHECKA|Select target language, currently: $TARGETLANG!bash -c set_target_language!gtk-edit|Exit!bash -c quit_tray!gtk-quit"
echo menu:"${GET_MENU}" >&3
} ; export -f get_menu
set_google () {
echo "google" > /tmp/_trans_engine_
#export CHECKG="!gtk-ok"
get_menu
} ; export -f set_google
set_bing () {
echo "bing" > /tmp/_trans_engine_
#export CHECKB="!gtk-ok"
get_menu
} ; export -f set_bing
set_all () {
echo "yandex bing google" > /tmp/_trans_engine_
#export CHECKB="!gtk-ok"
get_menu
} ; export -f set_all
set_yandex () {
echo "yandex" > /tmp/_trans_engine_
#export CHECKY="!gtk-ok"
get_menu
} ; export -f set_yandex
quit_tray () {
yad --title="Exit ?" --center --borders=6 --window-icon=$ICON --text=" Are you sure to exit $PROG ? \n " --button="gtk-no:1" --button="gtk-yes:0"
if [ $? -eq 0 ]; then
echo "quit" >$PIPE
rm -f $PIPE
exit
fi
}
export -f quit_tray
# add handler to manage process shutdown
function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
trap on_exit EXIT
set_target_language () {
LANGUAGES='
Afrikaans - af
Albanian - sq
Amharic - am
Arabic - ar
Armenian - hy
Azerbaijani - az
Basque - eu
Belarusian - be
Bengali - bn
Bosnian - bs
Bulgarian - bg
Cantonese - yue
Catalan - ca
Cebuano - ceb
Chichewa - ny
Chinese(Simple) - zh-CN
Chinese(Trad) - zh-TW
Corsican - co
Croatian - hr
Czech - cs
Danish - da
Dutch - nl
English - en
Esperanto - eo
Estonian - et
Fijian - fj
Filipino - tl
Finnish - fi
French - fr
Frisian - fy
Galician - gl
Georgian - ka
German - de
Greek - el
Gujarati - gu
Haitian-Creole - ht
Hausa - ha
Hawaiian - haw
Hebrew - he
Hindi - hi
Hmong - hmn
Hmong-Daw - mww
Hungarian - hu
Icelandic - is
Igbo - ig
Indonesian - id
Irish - ga
Italian - it
Japanese - ja
Javanese - jv
Kannada - kn
Kazakh - kk
Khmer - km
Klingon - tlh
Korean - ko
Kurdish - ku
Kyrgyz - ky
Lao - lo
Latin - la
Latvian - lv
Lithuanian - lt
Luxembourgish - lb
Macedonian - mk
Malagasy - mg
Malay - ms
Malayalam - ml
Maltese - mt
Maori - mi
Marathi - mr
Mongolian - mn
Myanmar - my
Nepali - ne
Norwegian - no
Pashto - ps
Persian - fa
Polish - pl
Portuguese - pt
Punjabi - pa
Queretaro-Otomi - otq
Romanian - ro
Russian - ru
Samoan - sm
Scots-Gaelic - gd
Serbian(Cyr) - sr-Cyrl
Serbian(Latin) - sr-Latn
Sesotho - st
Shona - sn
Sindhi - sd
Sinhala - si
Slovak - sk
Slovenian - sl
Somali - so
Spanish - es
Sundanese - su
Swahili - sw
Swedish - sv
Tahitian - ty
Tajik - tg
Tamil - ta
Tatar - tt
Telugu - te
Thai - th
Tongan - to
Turkish - tr
Udmurt - udm
Ukrainian - uk
Urdu - ur
Uzbek - uz
Vietnamese - vi
Welsh - cy
Xhosa - xh
Yiddish - yi
Yoruba - yo
Yucatec-Maya - yua
Zulu - zu
'
TARGETLANG=$(yad --borders 6 --separator=" " \
--center --height 700 --width="350" --list --multiple \
--title="Target language for translation" \
--text=" <b>Select target language</b> \n Press on keyboard: ctrl+f to do a search, e.g. 'french' " \
--search-column=1 --hide-column=2 \
--print-column=0 --column " Language" \
--column " dummy " --column " Locale" $LANGUAGES \
--button="gtk-cancel:1" --button="gtk-ok:0")
if [ $? -eq 0 ] && [ -n "$TARGETLANG" ]; then
echo "$TARGETLANG" > $HOME/.trans_target_lang2
export TARGETLANG=$(cat $HOME/.trans_target_lang2 2> /dev/null)
get_menu
fi
}
export -f set_target_language
export PIPE="/tmp/TRANS_PIPE.$RANDOM"
mkfifo $PIPE
get_menu
POPUP_TEXT="<b>Left-click for Trans-Paste""$nl""Right-click for Menu</b>"
yad --notification --kill-parent --listen \
--image="$ICON" \
--text="$POPUP_TEXT" \
--text-align=center \
--command="bash -c trans_paste" <&3
- Attachments
-
- trans.png
- (163.59 KiB) Downloaded 195 times
Last edited by stemsee on Wed 21 Aug 2019, 23:20, edited 2 times in total.
Create a continuous digital clock
Hello, I would like to insert a continuous digital clock into a YAD title with --text-info. Can somebody help me with it?
Thanks in advance
achim
Thanks in advance
achim
Last edited by achim on Thu 22 Aug 2019, 01:42, edited 1 time in total.
Nice work stemsee, working fine for me !!
I assume you mean the 'trans' script must have a bug ? (or maybe it's because of recent changes at the yandex end).
Hopefully it gets updated soon so yandex works again.
Fred
Google works again for me now, yes yandex often fails for me too.yandex isnt working for me. Google not working for you. Script must have a bug!
I assume you mean the 'trans' script must have a bug ? (or maybe it's because of recent changes at the yandex end).
Hopefully it gets updated soon so yandex works again.
Fred
- misko_2083
- Posts: 114
- Joined: Tue 08 Nov 2016, 13:42
Re: Create a continuous digital clock
Install/use wmctrlachim wrote:Hello, I would like to insert a continuous digital clock into a YAD title with --text-info. Can somebody help me with it?
Thanks in advance
achim
Code: Select all
#!/bin/bash
win_class="Achim"
yad --text-info --class="${win_class}" --title="Achim: $(date '+%T')" --width=300 & achims_pid=$!
trap "kill -s SIGUSR1 $achims_pid" EXIT
declare achim_xid
# need some time to register window class with X
while [[ ${achim_xid} == "" ]]; do
# get Xwindow id
achim_xid="$(wmctrl -lx | grep -e "yad.${win_class}" | grep -oE "[0-9a-z]{10}")"
done
# convert to decimal number
achim_xid="$(echo $((${achim_xid})))"
while true
do
wmctrl -i -r "${achim_xid}" -N "Achim: $(date '+%T')" 2>/dev/null || break
sleep 1
done
Last edited by misko_2083 on Thu 22 Aug 2019, 11:55, edited 1 time in total.
Hi Fred et al
yes, trans script might have bug.
I want to implement another version which uses yad --notebook with tabs for each engines' result. My first effort failed! would be nice is all.
Also in the engine loop newline after do, by adding tray icon can show which engine is translating....of course need icons first.
Also the should be at the head instead of underlining each translation in case of a large body of text.
regards
stemsee
EDIT hi Misko
wouldn'tbe better?
yes, trans script might have bug.
I want to implement another version which uses yad --notebook with tabs for each engines' result. My first effort failed! would be nice is all.
Also in the engine loop newline after do, by adding
Code: Select all
echo "icon:/usr/share/pixmaps/$ex.png >$PIPE"
Also the
Code: Select all
echo -----^$ex $i^-----
Code: Select all
echo -----$ex $i-----
stemsee
EDIT hi Misko
wouldn't
Code: Select all
while sleep 1; do