Development of 'trans_tray' (translation program)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#21 Post by fredx181 »

Made a mistake with last trans_tray2, see EDIT and new attachment:
http://murga-linux.com/puppy/viewtopic. ... 38#1035338

Fred

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

#22 Post by fredx181 »

Experimented a bit by adding some more menu entries:
- Type or paste text to be translated, could be handy.
- Translate webpage
(see pics)

EDIT: 'default_web-browser' or 'defaultbrowser' or 'xdg-open' probably in most cases should work also when setting the browser in the "Translate webpage" dialog.

EDIT: Mmmm... few hours later... found that translating from menu "Type or paste text to be translated" didn't show any translation, sorry, should be fixed now, re-attached script below.

Fred
Attachments
trans_tray2.gz
Updated with fix, see EDIT, remove fake .gz and make executable
(115.56 KiB) Downloaded 142 times
2019-08-26-193601_636x484_scrot.png
Type or paste text to be translated
(93.21 KiB) Downloaded 385 times
2019-08-26-193827_840x404_scrot_740x356.png
Translate webpage
(169.93 KiB) Downloaded 381 times

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

#23 Post by fredx181 »

Again to quick with sharing, needed a fix, see EDIT:... and new attachment above.

Fred

stemsee

#24 Post by stemsee »

Hi Fred

I've been experiencing some drama at work.... So not been around. But I couldn't get my own geometry recording function to work after much effort. I can't wait to see how you did it (I'm on android phone right now! ) I guessed I might need unset WINDOWTITLE before each occurrence.

Your additional features and menu entries are great! You are 'FAST & FURIOUS'

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

#25 Post by fredx181 »

Hi stemsee,

For remembering geometry I just took over MochiMoppels's code http://murga-linux.com/puppy/viewtopic. ... 285#989285

Btw, I found that it can be simplified, this works too, (may give negative values for x or y, but yad can handle that):

Code: Select all

function sayonara {
   XWININFO=$(xwininfo -id $YAD_XID)
   echo "$XWININFO" | grep "\-geometry " | awk '{print $2}' > /tmp/yad_trans_geometry
   kill -s SIGUSR1 $YAD_PID
}; export -f sayonara
One thing I'm not happy about is that after a reboot the geometry isn't remembered anymore, so may be better to write to > $HOME/yad_trans_geometry

See you around soon !

Fred

stemsee

#26 Post by stemsee »

Hi Fred

Great optimisation.

I suggest using /tmp/trans_tray/ & $HOME/. trans_tray/{geometry, savedtexts} / as a policy in general. And then removal will be easier. I'm sure geometry recording will become a trend in future scripts and apps.

Stemsee

I just had a thought of adding some code that would give this app gettext formatting for ease of gettexting.... No idea what that might be though!

EDIT: It's really good the type what you want translated, but I will try to get that so that we have two panes which allow you to type your text in the left pane, and view translation/s in the right text-info pane so you can also see exactly what you typed and not just remember it. (I think I already did this in refdnd or something similar).

stemsee

#27 Post by stemsee »

fredx181 wrote:Hi stemsee,

For remembering geometry I just took over MochiMoppels's code http://murga-linux.com/puppy/viewtopic. ... 285#989285

Btw, I found that it can be simplified, this works too, (may give negative values for x or y, but yad can handle that):

Code: Select all

function sayonara {
   XWININFO=$(xwininfo -id $YAD_XID)
   echo "$XWININFO" | grep "\-geometry " | awk '{print $2}' > /tmp/yad_trans_geometry
   kill -s SIGUSR1 $YAD_PID
}; export -f sayonara
One thing I'm not happy about is that after a reboot the geometry isn't remembered anymore, so may be better to write to > $HOME/yad_trans_geometry

See you around soon !

Fred
Where/how is YAD_XID defined? How is it the correct window id is captured, if you have several yad windows open?

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

#28 Post by misko_2083 »

stemsee wrote: Where/how is YAD_XID defined? How is it the correct window id is captured, if you have several yad windows open?
It's in the manual

Code: Select all

man yad
       YAD_XID
              This variable sets to the value of current dialog's X Window  ID
              and  accessible in all dialog children. This variable is not set
              in print and notification dialogs, and in a dialogs  which  acts
              as a notebook or paned children.

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

#29 Post by fredx181 »

stemsee wrote:I suggest using /tmp/trans_tray/ & $HOME/. trans_tray/{geometry, savedtexts} / as a policy in general. And then removal will be easier. I'm sure geometry recording will become a trend in future scripts and apps.
Yes, that would be much better.
EDIT: It's really good the type what you want translated, but I will try to get that so that we have two panes which allow you to type your text in the left pane, and view translation/s in the right text-info pane so you can also see exactly what you typed and not just remember it. (I think I already did this in refdnd or something similar).
Would be nice !
fredx181 wrote:Btw, I found that it can be simplified, this works too, (may give negative values for x or y, but yad can handle that):
Code:
function sayonara {
XWININFO=$(xwininfo -id $YAD_XID)
echo "$XWININFO" | grep "\-geometry " | awk '{print $2}' > /tmp/yad_trans_geometry
kill -s SIGUSR1 $YAD_PID
}; export -f sayonara
Correction: found that the latest yad versions (0.41 and 0.42) won't handle negative values for x/y properly (version 0.38.2 does that well though) so better keep Mochi's code for remembering geometry .

Fred

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

#30 Post by fredx181 »

stemsee wrote:EDIT: It's really good the type what you want translated, but I will try to get that so that we have two panes which allow you to type your text in the left pane, and view translation/s in the right text-info pane so you can also see exactly what you typed and not just remember it. (I think I already did this in refdnd or something similar).
This works, with save option, only thing I cannot get done is that if you edit the translation that it will be saved too.

Code: Select all

#! /bin/bash

mkdir /tmp/trans_tray 2> /dev/null

export run_cmd='@bash -c "run_trans %1 %2"'

export fpipe="/tmp/run_trans.$RANDOM"
mkfifo "$fpipe"

trap "rm -f $fpipe" EXIT

fkey=$(($RANDOM * $$))

function run_trans_save {
[ ! -f /tmp/trans_tray/run_trans ] && exit
DATE=$(date +"%Y%m%d_%H%M%S")
cp -a /tmp/trans_tray/run_trans  $HOME/trans-$DATE
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to $HOME/trans-$DATE </b>" --geometry=350x35-40-70 --undecorated --timeout 5 --no-buttons
}
export -f run_trans_save

function run_trans
{
    echo "2:@disable@"
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 2> /dev/null)
[ -z "$ENGINE" ] && ENGINE=google
  echo -e '\f' >> "$fpipe"
[ -n "$1" ] && export TTEXT="$1" || exit
#echo "Using $ENGINE for translating"

for ex in $ENGINE
do
#echo "icon:/tmp/$ex.svg" >$PIPE
while read i; do
echo "----- $ex translate to $(echo $i | awk '{print $1}') -----"
echo -e "$TTEXT" | trans -e $ex -b -tl $(echo $i | awk '{print $NF}')
#echo ""
done <<< "$TLANG"; done | tee /tmp/trans_tray/run_trans >> "$fpipe"

    echo "2:$run_cmd"
}
export -f run_trans

exec 3<> $fpipe

yad --plug="$fkey" --tabnum=1 --form --field="Type some text to translate :TXT" "" --field="Translate!gtk-refresh:fbtn" "$run_cmd" &

yad --plug="$fkey" --tabnum=2 --text-info --editable --wrap --fore="black" --back="#FFF7EE" --margins=5 <&3 &

yad --paned --key="$fkey" --text="        <b>Translate to $_TLANG</b>" --button="Close!gtk-close:1" --button="Save!gtk-save:bash -c run_trans_save" --width=800 --height=600 \
    --title="Translate" --window-icon="gtk-refresh" --splitter=350 --orient=hor
rm -f /tmp/trans_tray/run_trans
#exec 3>&-
EDIT: few hours later, edited the code a little.

Fred
Attachments
2019-08-28-182611_802x629_scrot_702x551.png
(46.63 KiB) Downloaded 189 times

stemsee

#31 Post by stemsee »

Hi Fred

is this not possible?
EDIT Noo!

It didn't work!
Last edited by stemsee on Wed 28 Aug 2019, 22:52, edited 1 time in total.

stemsee

#32 Post by stemsee »

Hi Misko

Oh man!! :?

Fred
the way your geometry recording works right now is that without referencing windowtitles in the saved geometry only one window can have its geometry recorded and recalled, "Trans", or all windows can recall the geometry for one window. Seems like wasted potential.

stemsee

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

#33 Post by fredx181 »

Hi stemsee
Fred
the way your geometry recording works right now is that without referencing windowtitles in the saved geometry only one window can have its geometry recorded and recalled, "Trans", or all windows can recall the geometry for one window. Seems like wasted potential.
I'm not sure to understand, you mean that every window can/should make use of the 'geometry save' function ?

I've been experimenting some more and I'd like your opinion on the following:
With code below (very raw, just to demonstrate what I mean) the window with translation can stay open and gets cleared and again "filled'" with the translation every time clicking on the tray icon.
I like it because it's not opening new window again and again when icon clicked.
But disadvantage is that "save after edit" will be problematic, I think, maybe drop that feature ? Or do you see it as very important.

Code: Select all

trans_paste () {
set -x
export PPIPE="/tmp/TRANS_R"
mkfifo $PPIPE
exec 4<> $PPIPE
pyd=$(ps -eo pid,cmd | grep "yad --text-info --editable --wrap --fore=black" | grep -v grep | awk '{print $1}')

[ -z "$pyd" ] && yad --text-info --editable --wrap --fore="black" --back="#FFF7EE" --margins=5 --width=700 --height=600 <&4 &

  echo -e '\f' >> $PPIPE
export XCLIP=$(xclip -o)

(
echo "Translate to Dutch+French+Italian+Spanish"
echo "$XCLIP" | trans -e google -b -tl nl+fr+it+es
) >> $PPIPE

}
export -f trans_paste

export TPIPE="/tmp/TRANS_RUN.$RANDOM"
mkfifo $TPIPE
exec 3<> $TPIPE

POPUP_TEXT="<b>Left-click for Trans-Paste""$nl""Right-click for Menu</b>"

yad --notification --kill-parent --listen \
--image="gtk-ok" \
--text="$POPUP_TEXT" \
--text-align=center --icon-size=22 \
--command="bash -c trans_paste" <&3
Fred

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

#34 Post by fredx181 »

With workaround using xdotool (ugly, but works for me anyway) to make save after edit possible:

Code: Select all

xdo_save () {
set -x
export OLDXCLIP=$(xclip -o)
xdotool key --window '$(xdotool getactivewindow)' Ctrl+Up
xdotool key --window '$(xdotool getactivewindow)' Ctrl+a
XCLIP=$(xclip -o)
DATE=$(date +"%Y%m%d_%H%M%S")
echo "$XCLIP" > $HOME/trans-$DATE
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to $HOME/trans-$DATE </b>" --geometry=350x35-40-70 --undecorated --timeout 5 --no-buttons
echo "$OLDXCLIP" | xclip
xdotool key --window '$(xdotool getactivewindow)' Down
}
export -f xdo_save

trans_paste () {
set -x
export PPIPE="/tmp/TRANS_R"
mkfifo $PPIPE
exec 4<> $PPIPE
pyd=$(ps -eo pid,cmd | grep "yad --text-info --editable --wrap --fore=black" | grep -v grep | awk '{print $1}')

[ -z "$pyd" ] && yad --text-info --editable --wrap --fore="black" --back="#FFF7EE" --margins=5 --width=700 --height=600 --button="Save:bash -c xdo_save" <&4 &

  echo -e '\f' >> $PPIPE

export XCLIP=$(xclip -o)

(
echo "Translate to Dutch+French+Italian+Spanish"
echo "$XCLIP" | trans -e bing -b -tl nl+fr+it+es
) >> $PPIPE

}
export -f trans_paste

export TPIPE="/tmp/TRANS_RUN.$RANDOM"
mkfifo $TPIPE
exec 3<> $TPIPE

POPUP_TEXT="<b>Left-click for Trans-Paste""$nl""Right-click for Menu</b>"

yad --notification --kill-parent --listen \
--image="gtk-ok" \
--text="$POPUP_TEXT" \
--text-align=center --icon-size=22 \
--command="bash -c trans_paste" <&3
Fred

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

#35 Post by misko_2083 »

Hey Fred, that's too much and probably wouldn't work after Ctrl+s.
Reditect to temp file, copy it after if the save button is clicked.
You can check out the notes example for details on how editable text info Is used.
https://sourceforge.net/p/yad-dialog/wiki/Notes/

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

#36 Post by fredx181 »

misko_2083 wrote:Hey Fred, that's too much and probably wouldn't work after Ctrl+s.
Reditect to temp file, copy it after if the save button is clicked.
You can check out the notes example for details on how editable text info Is used.
https://sourceforge.net/p/yad-dialog/wiki/Notes/
Yes, I must admit, the way with xdotool is a very desperate attempt :lol:
But I still like the pipe thing with input stream such as I mentioned here:
http://murga-linux.com/puppy/viewtopic. ... 17#1035617
You know perhaps a solution to save the edited text when using it that way ?

Fred

stemsee

#37 Post by stemsee »

hI fred

I prefer the stay open window, for general use, but often I like to have various translations open in different windows, or maybe in the same window. In that case the echo -e '\f' >$TPIPE could be a button function. That way I could keep all my translations in one window and save them in one document, and I could also clear that page when I want and not have to worry about closing many different windows. So yes one always open window, but with manual clearing of accumulated translations.

yes, all windows could have geometry recording.

Drop that feature! So easy to open in the savedtexts preview and edit and save there.

But could we save/insert the original text as a heading for the saved translated text?

stemsee

Code: Select all

if [ -z $(which gxmessage) ]; then
MESSAGE=xmessage
else
MESSAGE=gxmessage
fi
ydep=yad
xdep=xclip
tdep=trans
deps=`busybox which ${ydep} ${xdep} ${tdep} | cut -f4 -d'/'`
if [ -z "$deps" ]; then
	msg=" You have $deps installed you must have $ydep $tdep and $xdep installed.\nIt's a dependency of this program.\n Run from icon right-click menu: 'Install/Upgrade trans'."
	echo $msg
	$MESSAGE "`echo -e $msg`"
fi
I always specify 'busybox which' because full which (FatDog) never has an empty return.

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

#38 Post by fredx181 »

stemsee wrote:I prefer the stay open window, for general use, but often I like to have various translations open in different windows, or maybe in the same window. In that case the echo -e '\f' >$TPIPE could be a button function. That way I could keep all my translations in one window and save them in one document, and I could also clear that page when I want and not have to worry about closing many different windows. So yes one always open window, but with manual clearing of accumulated translations.

yes, all windows could have geometry recording.

Drop that feature! So easy to open in the savedtexts preview and edit and save there.

But could we save/insert the original text as a heading for the saved translated text?
Thanks for the suggestions, stemsee, how about this ?, can you test ?
(just for the concept of "trans_paste" function) (EDIT: See EDIT below)

Code: Select all

mkdir /tmp/trans_tray 2> /dev/null

function sayonara {
   XWININFO=$(xwininfo -id $YAD_XID)
   ARRAY=(${XWININFO#* X: })
   AX=${ARRAY[0]}
   AY=${ARRAY[4]}
   RX=${ARRAY[8]}
   RY=${ARRAY[12]}
   W=${ARRAY[14]}
   H=${ARRAY[16]}
   X=$((AX-RX))
   Y=$((AY-RY))
   echo "$W"x"$H"+"$X"+"$Y" > /tmp/yad_trans_geometry
   rm -f /tmp/trans_tray/run_trans
   kill -s SIGUSR1 $YAD_PID
}; export -f sayonara

sayonara_save () {
DATE=$(date +"%Y%m%d_%H%M%S")
cp -a /tmp/trans_tray/run_trans  $HOME/trans-$DATE
#sayonara
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to $HOME/trans-$DATE </b>" --geometry=350x35-40-70 --undecorated --timeout 5 --no-buttons
}; export -f sayonara_save

trans_clear () {
  echo -e '\f' >> $PPIPE
rm -f /tmp/trans_tray/run_trans
}
export -f trans_clear

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"
[ -z "$_TLANG" ] && export _TLANG="English"
export ENGINE=$(cat /tmp/_trans_engine_2 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... \nPress <b>ESC</b> key or click <b>Exit</b> to dismiss, or click <b>Save</b> (if desired, edit text first)"
MYTITLE="Trans"
BUT="<span color='darkblue'><b>Exit</b></span>"
BUTSAVE="<span color='darkgreen'><b>Save</b></span>"
BUTCLEAR="<span color='darkred'><b>Clear</b></span>"
FONT="Mono 12"
if [ ! -e /tmp/yad_trans_geometry ]; then
TWIDTH=$(xdpyinfo  | grep 'dimensions:' | cut -d' ' -f7 | cut -d'x' -f1)
THEIGHT=$(xdpyinfo  | grep 'dimensions:' | cut -d' ' -f7 | cut -d'x' -f2)
SWIDTH=$(( $TWIDTH - 610 ))
SHEIGHT=$(( $THEIGHT - 610 ))
#echo $SWIDTH
#echo $SHEIGHT
export GEOMETRY="600x550+$SWIDTH+$SHEIGHT"
else
export GEOMETRY="$(cat /tmp/yad_trans_geometry 2>/dev/null)"
fi
export PPIPE="/tmp/TRANS_R"
mkfifo $PPIPE
exec 4<> $PPIPE

pyd=$(ps -eo pid,cmd | grep "yad --title=Trans --window-icon=/tmp/trans-paste.svg" | grep -v grep | awk '{print $1}')

if [ -z "$pyd" ]; then
yad --title="$MYTITLE" \
--window-icon="$ICON" \
--text-align=center \
--borders=6 \
--geometry="$GEOMETRY" \
--fore="black" --back="#fef1e0" \
--margins=5 \
--button="$BUTCLEAR:bash -c trans_clear" \
--button="$BUTSAVE:bash -c sayonara_save" \
--button="$BUT:bash -c sayonara" \
--text="Click <b>Save</b> for saving translation to a file \n Click <b>Clear</b> to clear the text" \
--fontname="$FONT" \
--text-info --wrap --editable --listen <&4 &
rm -f /tmp/trans_tray/run_trans
fi
(
xclip -o
echo
echo
echo "Translating to $_TLANG..."
for ex in $ENGINE
do
echo "icon:/tmp/$ex.svg" >$PIPE
while read i; do
echo " ----- $ex translate to $(echo $i | awk '{print $1}') -----"
xclip -o | trans -e $ex -b -tl $(echo $i | awk '{print $NF}')
echo
done <<< "$TLANG"; done
) | tee -a /tmp/trans_tray/run_trans >> $PPIPE

}
export -f trans_paste

export TPIPE="/tmp/TRANS_RUN.$RANDOM"
mkfifo $TPIPE
exec 3<> $TPIPE

POPUP_TEXT="<b>Left-click for Trans-Paste""$nl""Right-click for Menu</b>"

yad --notification --kill-parent --listen \
--image="gtk-ok" \
--text="$POPUP_TEXT" \
--text-align=center --icon-size=22 \
--command="bash -c trans_paste" <&3	
EDIT: Next day: made some changes to the code, e,g, "tee" should better be "tee -a" and added removal of /tmp/trans_tray/run_trans at some points.

Fred
Attachments
2019-08-31-000714_879x764_scrot_779x677.jpg
Window stays open everytime the icon clicked, added Clear button
(197.5 KiB) Downloaded 387 times

stemsee

#39 Post by stemsee »

Hi Fred

It works great,

with my added snippet of code, edits are also saved on exit.

Code: Select all

mkdir /tmp/trans_tray 2> /dev/null

function sayonara {
   XWININFO=$(xwininfo -id $YAD_XID)
   ARRAY=(${XWININFO#* X: })
   AX=${ARRAY[0]}
   AY=${ARRAY[4]}
   RX=${ARRAY[8]}
   RY=${ARRAY[12]}
   W=${ARRAY[14]}
   H=${ARRAY[16]}
   X=$((AX-RX))
   Y=$((AY-RY))
   echo "$W"x"$H"+"$X"+"$Y" > /tmp/yad_trans_geometry
   rm -f /tmp/trans_tray/run_trans
   kill -s SIGUSR1 $YAD_PID
}; export -f sayonara

sayonara_save () {
DATE=$(date +"%Y%m%d_%H%M%S")
cp -a /tmp/trans_tray/run_trans  $HOME/trans-$DATE
#sayonara
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to $HOME/trans-$DATE </b>" --geometry=350x35-40-70 --undecorated --timeout 5 --no-buttons
}; export -f sayonara_save

trans_clear () {
  echo -e '\f' >> $PPIPE
rm -f /tmp/trans_tray/run_trans
}
export -f trans_clear

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"
[ -z "$_TLANG" ] && export _TLANG="English"
export ENGINE=$(cat /tmp/_trans_engine_2 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... \nPress <b>ESC</b> key or click <b>Exit</b> to dismiss, or click <b>Save</b> (if desired, edit text first)"
MYTITLE="Trans"
BUT="<span color='darkblue'><b>Exit</b></span>"
BUTSAVE="<span color='darkgreen'><b>Save</b></span>"
BUTCLEAR="<span color='darkred'><b>Clear</b></span>"
FONT="Mono 12"
if [ ! -e /tmp/yad_trans_geometry ]; then
TWIDTH=$(xdpyinfo  | grep 'dimensions:' | cut -d' ' -f7 | cut -d'x' -f1)
THEIGHT=$(xdpyinfo  | grep 'dimensions:' | cut -d' ' -f7 | cut -d'x' -f2)
SWIDTH=$(( $TWIDTH - 610 ))
SHEIGHT=$(( $THEIGHT - 610 ))
#echo $SWIDTH
#echo $SHEIGHT
export GEOMETRY="600x550+$SWIDTH+$SHEIGHT"
else
export GEOMETRY="$(cat /tmp/yad_trans_geometry 2>/dev/null)"
fi
export PPIPE="/tmp/TRANS_R"
mkfifo $PPIPE
exec 4<> $PPIPE

pyd=$(ps -eo pid,cmd | grep "yad --title=Trans --window-icon=/tmp/trans-paste.svg" | grep -v grep | awk '{print $1}')

if [ -z "$pyd" ]; then
yad --title="$MYTITLE" \
--window-icon="$ICON" \
--text-align=center \
--borders=6 \
--geometry="$GEOMETRY" \
--fore="black" --back="#fef1e0" \
--margins=5 \
--button="$BUTCLEAR:bash -c trans_clear" \
--button="$BUTSAVE:bash -c sayonara_save" \
--button="$BUT:bash -c sayonara" \
--text="Click <b>Save</b> for saving translation to a file \n Click <b>Clear</b> to clear the text" \
--fontname="$FONT" \
--text-info --wrap --editable --listen >/tmp/trans <&4 &
rm -f /tmp/trans_tray/run_trans
fi
(
xclip -o
echo
echo
echo "Translating to $_TLANG..."
for ex in $ENGINE
do
echo "icon:/tmp/$ex.svg" >$PIPE
while read i; do
echo " ----- $ex translate to $(echo $i | awk '{print $1}') -----"
xclip -o | trans -e $ex -b -tl $(echo $i | awk '{print $NF}')
echo
done <<< "$TLANG"; done
) | tee -a /tmp/trans_tray/run_trans >> $PPIPE

}
export -f trans_paste

export TPIPE="/tmp/TRANS_RUN.$RANDOM"
mkfifo $TPIPE
exec 3<> $TPIPE

POPUP_TEXT="<b>Left-click for Trans-Paste""$nl""Right-click for Menu</b>"

yad --notification --kill-parent --listen \
--image="gtk-ok" \
--text="$POPUP_TEXT" \
--text-align=center --icon-size=22 \
--command="bash -c trans_paste" <&3 
stemsee

stemsee

#40 Post by stemsee »

this also saves edits, but only on exit

Code: Select all

eded=$(yad --title="$MYTITLE" \
--window-icon="$ICON" \
--text-align=center \
--borders=6 \
--geometry="$GEOMETRY" \
--fore="black" --back="#fef1e0" \
--margins=5 \
--button="$BUTCLEAR:bash -c trans_clear" \
--button="$BUTSAVE:bash -c sayonara_save" \
--button="$BUT:bash -c sayonara" \
--text="Click <b>Save</b> for saving translation to a file \n Click <b>Clear</b> to clear the text" \
--fontname="$FONT" \
--text-info --wrap --editable --listen <&4 &)
echo "$eded" >$HOME/transex

Post Reply