Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 05 Dec 2019, 13:52
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
YAD - Tips
Post new topic   Reply to topic View previous topic :: View next topic
Page 45 of 54 [805 Posts]   Goto page: Previous 1, 2, 3, ..., 43, 44, 45, 46, 47, ..., 52, 53, 54 Next
Author Message
vovchik


Joined: 23 Oct 2006
Posts: 1512
Location: Ukraine

PostPosted: Mon 19 Aug 2019, 17:14    Post subject:  

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
Back to top
View user's profile Send private message 
josejp2424


Joined: 01 Aug 2010
Posts: 518

PostPosted: Mon 19 Aug 2019, 17:22    Post subject: button exit
Subject description: button exit
 

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


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

_________________
Shiba Inu | Pupjibaro jessie | My Blog
Back to top
View user's profile Send private message Visit poster's website 
Argolance


Joined: 06 Jan 2008
Posts: 3715
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Mon 19 Aug 2019, 17:50    Post subject:  

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

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.

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. Very Happy

Cheers!

_________________

A second life for your PCs...
Back to top
View user's profile Send private message Visit poster's website 
josejp2424


Joined: 01 Aug 2010
Posts: 518

PostPosted: Mon 19 Aug 2019, 18:00    Post subject: tran_tray
Subject description: trans_tray
 

Argolance wrote:
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

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.

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. Very Happy

Cheers!


I am amused by your comments Very Happy Very Happy Very Happy

_________________
Shiba Inu | Pupjibaro jessie | My Blog
Back to top
View user's profile Send private message Visit poster's website 
fredx181


Joined: 11 Dec 2013
Posts: 4196
Location: holland

PostPosted: Tue 20 Aug 2019, 03:42    Post subject:  

Maybe we should open a poll question about this EXIT matter Laughing Laughing
It's easy to remove from menu, btw, just delete the selected blue showing on pic below

Fred
2019-08-20-093859_987x98_scrot_787x78.png
 Description   Delete the blue for no EXIT entry in menu
 Filesize   44.73 KB
 Viewed   341 Time(s)

2019-08-20-093859_987x98_scrot_787x78.png


_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2539
Location: In The Way

PostPosted: Tue 20 Aug 2019, 09:35    Post subject:    

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, 10:12; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2539
Location: In The Way

PostPosted: Tue 20 Aug 2019, 09:35    Post subject:  

duplicate
Back to top
View user's profile Send private message MSN Messenger 
fredx181


Joined: 11 Dec 2013
Posts: 4196
Location: holland

PostPosted: Tue 20 Aug 2019, 13:34    Post subject:  

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
Quote:
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.


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 challenge Rolling Eyes

Fred
trans_tray.gz
Description  Remove fake .gz and make executable
gz

 Download 
Filename  trans_tray.gz 
Filesize  6.62 KB 
Downloaded  29 Time(s) 

_________________
Dog Linux website
Tinylinux blog by wiak

Last edited by fredx181 on Tue 20 Aug 2019, 13:55; edited 1 time in total
Back to top
View user's profile Send private message 
josejp2424


Joined: 01 Aug 2010
Posts: 518

PostPosted: Tue 20 Aug 2019, 13:54    Post subject: trans_tray
Subject description: trans_tray
 

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.

@stemsee
Quote:
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.


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 challenge Rolling Eyes

Fred


I like the new output dialog.
this is better to avoid closing by mistake
exit.jpg
 Description   exit button
 Filesize   31.45 KB
 Viewed   263 Time(s)

exit.jpg


_________________
Shiba Inu | Pupjibaro jessie | My Blog
Back to top
View user's profile Send private message Visit poster's website 
vovchik


Joined: 23 Oct 2006
Posts: 1512
Location: Ukraine

PostPosted: Tue 20 Aug 2019, 17:13    Post subject:  

Dear fredx181,

The close dialog is fine. Thanks....

With kind regards,
vovchik
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2539
Location: In The Way

PostPosted: Wed 21 Aug 2019, 02:00    Post subject:  

I cannot fnd trans' executable! please post a copy.

here is a version i cannot test, allows multiple target languages. Maybe needs tweaking.

Code:
#!/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"
Back to top
View user's profile Send private message MSN Messenger 
josejp2424


Joined: 01 Aug 2010
Posts: 518

PostPosted: Wed 21 Aug 2019, 09:26    Post subject: tran_tray
Subject description: trans_tray
 

stemsee 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:
#!/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"

I'm going to test thanks stemsee

_________________
Shiba Inu | Pupjibaro jessie | My Blog
Back to top
View user's profile Send private message Visit poster's website 
fredx181


Joined: 11 Dec 2013
Posts: 4196
Location: holland

PostPosted: Wed 21 Aug 2019, 14:11    Post subject:  

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.
Quote:
I cannot fnd trans' executable! please post a copy.

It's here: https://github.com/soimort/translate-shell#installation
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:
#!/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"


Fred
2019-08-21-200339_602x629_scrot.png
 Description   French+German+Spanish
 Filesize   66.43 KB
 Viewed   154 Time(s)

2019-08-21-200339_602x629_scrot.png


_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2539
Location: In The Way

PostPosted: Wed 21 Aug 2019, 17:50    Post subject:  

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.


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.

However I will add a simple edit to allow one instance to do all three engines (I think!?).

thanks for trans link.
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2539
Location: In The Way

PostPosted: Wed 21 Aug 2019, 18:37    Post subject:  

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.

Code:
#!/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

trans.png
 Description   
 Filesize   163.59 KB
 Viewed   114 Time(s)

trans.png


Last edited by stemsee on Wed 21 Aug 2019, 19:20; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger 
Display posts from previous:   Sort by:   
Page 45 of 54 [805 Posts]   Goto page: Previous 1, 2, 3, ..., 43, 44, 45, 46, 47, ..., 52, 53, 54 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1270s ][ Queries: 12 (0.0162s) ][ GZIP on ]