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

stemsee

#41 Post by stemsee »

Hi Fred

I just had an idea. Instead of redirecting to a file, for save on exit, it coud be directed to the pipe which feeds the dual pane, for the purpose of editing/saving. Any thoughts?

stemsee

stemsee

#42 Post by stemsee »

Hi Fred

Do you think we could add a delete button in the dual pane saved texts viewer, to deleted selected?

stemsee

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

#43 Post by fredx181 »

Thanks stemsee !
Since I almost finished new trans_tray with added 'Preferences' to Menu, I added choice to close the window when clicking Save (and then edits will be saved the way you suggested)
Hi Fred

I just had an idea. Instead of redirecting to a file, for save on exit, it coud be directed to the pipe which feeds the dual pane, for the purpose of editing/saving. Any thoughts?
....
....
Do you think we could add a delete button in the dual pane saved texts viewer, to deleted selected?
No idea if possible, if you know how please share, maybe then for later version, for now I've made new trans_tray, coming up next post.

Fred

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

#44 Post by fredx181 »

Hi All, here's new trans_tray (trans_tray3, attached below), thanks to stemsee for his latest suggestions. Many changes:

- The main translation window stays open now everytime the tray icon is clicked.
(this means you can do multiple translations in same window (and save all))
- Added 'Clear' button to main translation window. (so it can be emptied)
- Added 'Preferences" entry to Menu. (see pic below)
(with choices e.g. 'on-top', confirmation when Exit and more)
- Changed 'Type or paste text to be translated' to a paned dialog.
- All configurations, icons, saved-texts are now in ~/.trans_tray (and temp files in /tmp/trans_tray)
- Changed 'which' to 'busybox which' in the script for to make it work on Fatdog (thanks stemsee)
- Compatible now with yad compiled with gtk3 (previously button text wasn't always displayed correct, using gtk3)

EDIT: @stemsee, didn't do more with geometry saving (still only the main window), btw I found that with paned windows the --geometry option doesn't work properly, specially when using gtk3

EDIT2: Got a report through PM that on Busterpup the 'bing' translator doesnn't work.
Reason is that Busterpup has included older trans version, and the "Install/Upgrade trans" option didn't work properly to upgrade to the newest, so... re-attached with fix for that (using curl now to download/upgrade trans).
At the same time made some other small fixes, icons etc...
(the code for creating the google.svg icon was enormous, made it 10x smaller, so script is only 30kb now)

Fred
Attachments
trans_tray3.gz
(updated, see above EDIT2) New 'trans_tray3', many changes, remove fake .gz and make executable
(29.61 KiB) Downloaded 179 times
2019-09-01-140349_1167x601_scrot_767x395.jpg
Translate WebPage
(78.98 KiB) Downloaded 318 times
2019-09-01-124039_617x545_scrot_517x457.jpg
New 'trans_tray3', added Preferences and more changes
(52.21 KiB) Downloaded 318 times
Last edited by fredx181 on Sun 01 Sep 2019, 16:55, edited 4 times in total.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#45 Post by vovchik »

Dear Fred,

Great work. Trans_tray has certainly come a long way in a very short time. And it is very useful and flexible. Thanks!

With kind regards,
vovchik

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

#46 Post by fredx181 »

Needed a fix, so re-attached here, (see EDIT2):
http://murga-linux.com/puppy/viewtopic. ... 83#1035783
(got report few hours ago through PM about problems on Busterpup, which has old 'trans' included)

@vovchik, thanks !

Fred

stemsee

#47 Post by stemsee »

Hi Fred

Can you get this refresh savedtexts list to work properly?

Code: Select all

function savedtranstexts (){
   rm -f /tmp/trans_tray/TP
   stxtp=/tmp/trans_tray/TP
   mkfifo -m 755 $stxtp
   exec 4<> $stxtp
   rm -f /tmp/trans_tray/PT
   export ptxts=/tmp/trans_tray/PT
   mkfifo -m 755 $ptxts
   exec 6<> $ptxts
function refresh (){
   echo -e '\f' >$ptxts
   echo $(ls $HOME/.trans_tray/savedtexts/* | tr ' ' '\n') >$ptxts
}; export -f refresh
trap "rm -f $stxtp" EXIT

yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
    $(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
    --select-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; cat  "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP \"" <&6  &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &

WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal

}; export -f savedtranstexts
On my version I have retained yandex, and added Roman - rm as a translation option (for pinyin).

stemsee

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

#48 Post by fredx181 »

Hi stemsee, this change in function refresh works for me (using the same as is in the list code)

Code: Select all

function refresh (){
   echo -e '\f' >$ptxts
   echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh
Fred

stemsee

#49 Post by stemsee »

yes, i got up too early....i thought about it after posting and realised the same version. In fact I had tried that first but i had two versions of the same script open and edited the wrong one so I didn't see it work...ha ha

Code: Select all

function savedtranstexts (){
   rm -f /tmp/trans_tray/TP
   stxtp=/tmp/trans_tray/TP
   mkfifo -m 755 $stxtp
   exec 4<> $stxtp
   rm -f /tmp/trans_tray/PT
   export ptxts=/tmp/trans_tray/PT
   mkfifo -m 755 $ptxts
   exec 6<> $ptxts
function refresh (){
   echo -e '\f' >$ptxts
for f in $HOME/.trans_tray/savedtexts/trans-*_*
do 
[[ -f "${f}" ]] && echo "${f##*/}" >$ptxts
done
}; export -f refresh
trap "rm -f $stxtp" EXIT

yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
    $(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
    --select-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; cat  "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP \"" <&6  &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &

WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal

}; export -f savedtranstexts
Also in my version $ONTOP is applied to every windows so all are on-top or none.

stemsee

#50 Post by stemsee »

hi Fred

howabout --dclick-action deletes selected saved text.

Code: Select all

function savedtranstexts (){
   rm -f /tmp/trans_tray/TP
   stxtp=/tmp/trans_tray/TP
   mkfifo -m 755 $stxtp
   exec 4<> $stxtp
   rm -f /tmp/trans_tray/PT
   export ptxts=/tmp/trans_tray/PT
   mkfifo -m 755 $ptxts
   exec 6<> $ptxts
function refresh (){
   echo -e '\f' >$ptxts
for f in $HOME/.trans_tray/savedtexts/trans-*_*
do 
[[ -f "${f}" ]] && echo "${f##*/}" >$ptxts
done
}; export -f refresh
trap "rm -f $stxtp" EXIT

yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
    $(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
    --dclick-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; rm -f  "%s" ; bash -c refresh\"" \
    --select-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; cat  "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP \"" <&6  &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &

WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 --button="Refresh!gtk-refresh:bash -c refresh" $ONTOP --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal

}; export -f savedtranstexts


Post Reply