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

#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


stemsee

#51 Post by stemsee »

here is my version

includes xclip (x64), trans, trans_tray (4)
Attachments
trans_tray-stemsV4.sfs.gz
(80 KiB) Downloaded 113 times

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

#52 Post by fredx181 »

Hi stemsee, here's with Delete button (with dclick-action works also, but I thought that this is better):

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 "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh

function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
rm -f /tmp/trans_tray/sel-file
}; export -f delete

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" ; echo "%s" >/tmp/trans_tray/sel-file; 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="Delete!gtk-delete:bash -c delete"  --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal --buttons-layout=spread

}; export -f savedtranstexts
EDIT: best to add a message if nothing selected in delete function

Fred

stemsee

#53 Post by stemsee »

Hi Fred

The button is better. More difficult to accidentally delete needed translations.

Maybe the dclick function could be to open in external editor, or print as pdf.

stemsee

EDIT: maybe you could add to preferences the ability to set a default text editor as variable $TEXTEDITOR. I will hardcode geany for myself, as dclick open in editor.

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

#54 Post by misko_2083 »

stemsee wrote:Hi Fred
Maybe the dclick function could be to open in external editor,
Or internal

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 "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh

function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
rm -f /tmp/trans_tray/sel-file
}; export -f delete

function edit_traslation (){
   cd "$HOME/.trans_tray/savedtexts"
   cat "$1" | yad  --title="Edit: $1" --editable --text-info --listen --on-top > /tmp/Trans-Text-tmp
   if [ $? -eq 0 ]
   then
      mv /tmp/Trans-Text-tmp "$1"
      rm -f /tmp/Trans-Text-tmp
      echo -e '\f' >/tmp/TP
      cat  "$1" >/tmp/TP
      echo -e '\n' >/tmp/TP
   fi
}; export -f edit_traslation 

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 "edit_traslation "%s""" \
    --select-action="bash -c "echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "%s" >/tmp/trans_tray/sel-file; 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="Delete!gtk-delete:bash -c delete"  --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal --buttons-layout=spread

}; export -f savedtranstexts
If it's necessary to asign several options to the right click,
you can use the list dialog that opens at mouse pointer (also --on-top) and lists those options.

Make that dialog close when unfocused and it will emulate the context menu, sort of, behaviour.
Edit: here's with the menu.

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 "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh

function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
rm -f /tmp/trans_tray/sel-file
}; export -f delete

function menu_action () {
  # figure out what was selected
  case "$2" in
     "edit")  cd "$HOME/.trans_tray/savedtexts"
             cat "$1" | yad  --width=600 --height=400 --title="Edit: $1" --editable --text-info --listen --on-top > /tmp/Trans-Text-tmp
              if [ $? -eq 0 ]
              then
                  mv /tmp/Trans-Text-tmp "$1"
                  rm -f /tmp/Trans-Text-tmp
                  echo -e '\f' >/tmp/TP
                  cat  "$1" >/tmp/TP
                  echo -e '\n' >/tmp/TP
               fi
               ;;
     "print") yad --text "Print action activated" --on-top;;
     "delete") yad --text "Delete action activated" --on-top;;
   esac
      
}; export -f menu_action

function menu (){
   yad  --list --width=200 --height=100 --mouse \
        --column action --no-headers "edit" "print" "delete" \
        --close-on-unfocus --on-top --no-buttons --undecorated \
        --select-action="bash -c "menu_action "$1" "%s"""
}; export -f menu

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 "menu "%s""" \
    --select-action="bash -c "echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "%s" >/tmp/trans_tray/sel-file; 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="Delete!gtk-delete:bash -c delete"  --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal --buttons-layout=spread

}; export -f savedtranstexts
Note, after a menu/list item is activated, either focus needs to change or the menu/list dialog has to be closed, e.g. with SIGUSR1.

stemsee

#55 Post by stemsee »

Thanks misko

that's very useful. I will play with these options for awhile to see what I can come up with.

stem

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

#56 Post by fredx181 »

Thanks Misko !! We have a lot to choose from now, here's another, inspired by your "internal" code but with Edit button instead of double-click:

Code: Select all

function savedtranstexts (){
   rm -f /tmp/trans_tray/sel-file
   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 "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh

function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
rm -f /tmp/trans_tray/sel-file
}; export -f delete

function edit_translation (){
EDIT="$(cat /tmp/trans_tray/sel-file 2> /dev/null)"
[ -z "$EDIT" ] && exit
   cd "$HOME/.trans_tray/savedtexts"
   cat "$EDIT" | yad  --title="Edit: $EDIT" --window-icon=gtk-save --editable --text-info --width=700 --height=540 --wrap --listen --on-top --button="Cancel!gtk-cancel:1" --button="Save!gtk-save:0" > /tmp/trans_tray/Trans-Text-tmp
   if [ $? -eq 0 ]
   then
      mv /tmp/trans_tray/Trans-Text-tmp "$EDIT"
      rm -f /tmp/trans_tray/Trans-Text-tmp
      echo -e '\f' >/tmp/trans_tray/TP
      cat  "$EDIT" >/tmp/trans_tray/TP
      echo -e '\n' >/tmp/trans_tray/TP
   fi
}; export -f edit_translation

trap "rm -f $stxtp $ptxts" 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" ; echo "%s" >/tmp/trans_tray/sel-file; 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"
TEXT="  <b>Select an item from the list</b>"
yad --center --text="$TEXT" --window-icon=gtk-save --width=700 --height=540 --button="Edit!gtk-edit:bash -c edit_translation" --button="Delete!gtk-delete:bash -c delete"  --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal --buttons-layout=spread

}; export -f savedtranstexts 
@stemsee which one do you prefer ?

Fred

stemsee

#57 Post by stemsee »

Hi Fred

It's a no brainer! The versatility and future possibilities with the list menu opening at mouse is just awesome. If three more buttons are added on the other hand then minimum geometries are imposed.

In fact refresh and delete buttons should be moved to this list menu. Giving back that lovely clean look we started with.

stemsee

EDIT: But edit is already possible in dual pane window. The limited editing possibilities in yad are not worth employing more than already is the case. geany, swriter, wps etc take it to the next level and beyond.

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

#58 Post by fredx181 »

stemsee wrote:Hi Fred

It's a no brainer! The versatility and future possibilities with the list menu opening at mouse is just awesome. If three more buttons are added on the other hand then minimum geometries are imposed.

In fact refresh and delete buttons should be moved to this list menu. Giving back that lovely clean look we started with.
.
Ok! Would you mind making that ?, so we add it to next version then.
EDIT: Maybe best to put some text on top that says double-click brings up menu.
EDIT: But edit is already possible in dual pane window. The limited editing possibilities in yad are not worth employing more than already is the case. geany, swriter, wps etc take it to the next level and beyond
I may be missing something, which dual pane window you mean ?

Btw, how is Yandex working for you ?, for me it works only sometimes.

EDIT: Tried your sfs version and your use of $ONTOP is a good idea to implement in next version but doesn't work well how you did, this works to set it where needed:

Code: Select all

. $HOME/.trans_tray/prefs
[ "$ON_TOP" = "TRUE" ] && ONTOP="--on-top"
Fred

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

#59 Post by fredx181 »

Just experimenting :) Using misko's menu option by only select rather than double-clicking it (has small delay to avoid clicking on menu item when accidentally double-clicking (but maybe delay needs to be increased)):

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 "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh

function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
rm -f /tmp/trans_tray/sel-file
}; export -f delete

function menu_action () {
  # figure out what was selected

  case "$2" in
     "edit")  cd "$HOME/.trans_tray/savedtexts"
             cat "$1" | yad  --width=600 --height=400 --title="Edit: $1" --editable --text-info --listen --on-top > /tmp/Trans-Text-tmp
              if [ $? -eq 0 ]
              then
                  mv /tmp/Trans-Text-tmp "$1"
                  rm -f /tmp/Trans-Text-tmp
                  echo -e '\f' >/tmp/trans_tray/TP
                  cat  "$1" >/tmp/trans_tray/TP
                  echo -e '\n' >/tmp/trans_tray/TP
               fi
               ;;
     "print") yad --text "Print action activated" --on-top;;
     "delete") yad --text "Delete action activated" --on-top;;
   esac
     
}; export -f menu_action

function menu (){
 echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "$1" >/tmp/trans_tray/sel-file; cat  "$1" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP
sleep 0.5
   yad --title=savedtranstextsmenu --list --width=200 --height=100 --mouse \
        --column action --no-headers "edit" "print" "delete" \
        --close-on-unfocus --on-top --no-buttons --undecorated \
        --select-action="bash -c \"menu_action "$1" "%s"\""
}; export -f menu

trap "rm -f $stxtp $ptxts" 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 \"menu "%s"\"" <&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="Delete!gtk-delete:bash -c delete"  --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal --buttons-layout=spread

}; export -f savedtranstexts
Fred

stemsee

#60 Post by stemsee »

fredx181 wrote: EDIT: Tried your sfs version and your use of $ONTOP is a good idea to implement in next version but doesn't work well how you did, this works to set it where needed:

Code: Select all

. $HOME/.trans_tray/prefs
[ "$ON_TOP" = "TRUE" ] && ONTOP="--on-top"
Fred
should it be exported?

Code: Select all

. $HOME/.trans_tray/prefs
[ "$ON_TOP" = "TRUE" ] && export ONTOP="--on-top"
I already implemented the list. And made refresh a 2 second loop. Also added echo -e '\f' to preview pane.

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 (){
	[ -f /tmp/trans_tray/fresh ] && exit
   [ ! -f /tmp/trans_tray/fresh ] && touch /tmp/trans_tray/fresh
	while sleep 2
	do
	   echo -e '\f' >$ptxts
	   echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
   done

}; export -f refresh

function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
echo -e '\f' >$stxtp
rm -f /tmp/trans_tray/sel-file
}; export -f delete

function menu_action () {
  # figure out what was selected
  case "$2" in
     "edit")  cd "$HOME/.trans_tray/savedtexts"
             cat "$1" | yad  --width=600 --height=400 --title="Edit: $1" --editable --text-info --mouse --listen --on-top > /tmp/Trans-Text-tmp
              if [ $? -eq 0 ]
              then
                  mv /tmp/Trans-Text-tmp "$1"
                  rm -f /tmp/Trans-Text-tmp
                  echo -e '\f' >/tmp/TP
                  cat  "$1" >/tmp/TP
                  echo -e '\n' >/tmp/TP
               fi
               ;;
     "print") yad --text "Print action activated" --mouse $ONTOP;;
     "delete") bash -c delete;;
     "refresh") bash -c refresh;;
     "ext.editor") cd "$HOME/.trans_tray/savedtexts"
     EDITOR=$(yad --window-icon="/tmp/trans_tray/all.svg" $ONTOP --mouse --entry --text="Enter the editor to use e.g. geany")
     "$EDITOR" "$1";;
     "copy") cd "$HOME/.trans_tray/savedtexts"
		yad --window-icon="/tmp/trans_tray/all.svg" $ONTOP --mouse --file --save --text="Copy to location / rename";;
   esac
     
}; export -f menu_action

function menu (){
   yad  --list --width=200 --height=100 --mouse \
        --column action --no-headers "delete" "refresh" "print" "external editor" "copy" "internal edit" \
        --close-on-unfocus $ONTOP --no-buttons --undecorated \
        --select-action="bash -c "menu_action "$1" "%s"""
}; export -f menu

trap "rm -f $stxtp" EXIT

yad --plug=$$ --tabnum=1 --list --text="Double click raises menu" --item-separator=" " --listen --column="Saved Trans" \
    $(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
   --dclick-action="bash -c "menu "%s""" \
    --select-action="bash -c "echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "%s" >/tmp/trans_tray/sel-file; 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 $ONTOP --no-buttons --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal

}; export -f savedtranstexts
Last edited by stemsee on Wed 04 Sep 2019, 11:53, edited 1 time in total.

stemsee

#61 Post by stemsee »

Hi Fred

It would be nice to add renaming to the popup list menu, and save location. but renaming should be limited to the suffix or a copy, otherwise savedtexts preview wont pick it up. I say this because now I am looking for song lyrics on the internet and the quickest way to copy and save is by selecting and clicking the tray icon for translation, but they are in English and the translation is set to english so nothing gets done, which is good in this case. Howabout adding a notepad mode without translation for such use?? In which case instead of prefix 'trans' use 'note'.

stemsee

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

#62 Post by fredx181 »

Hi stemsee, following up on your code I've made some additions/changes.
- Dialog to choose default editor (to be used when clicking 'edit')
- Close double-click menu when clicked on item (perhaps personal, for me very annoying if it stays open (needing extra click to un-focus)
- Sync content of main text-info window when edit made by using external editor.

What to with the 'copy' and 'print' option I'm not sure of.

Code: Select all

mkdir /tmp/trans_tray
function savedtranstexts (){
rm -f /tmp/trans_tray/fresh
   rm -f /tmp/trans_tray/TP
   export 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 (){
  [ -f /tmp/trans_tray/fresh ] && exit
   [ ! -f /tmp/trans_tray/fresh ] && touch /tmp/trans_tray/fresh
   while [ -e "$ptxts" ]
   do
      echo -e '\f' >$ptxts
      echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts

sleep 2
   done
exit
}; export -f refresh

function delete (){
rm -f /tmp/trans_tray/fresh
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh &
echo -e '\f' >$stxtp
rm -f /tmp/trans_tray/sel-file
}; export -f delete

function menu_action () {
MENU_PID=$(cat /tmp/trans_tray/sttmenu_pid)
  # figure out what was selected
  case "$2" in
     "edit") kill $MENU_PID;
EDITOR=$(cat $HOME/.trans_tray/text-editor 2> /dev/null)
[ -z "$EDITOR" ] && EDITOR="internal editor"

if [ "$EDITOR" = "internal editor" ]; then
 cd "$HOME/.trans_tray/savedtexts"
             cat "$1" | yad --window-icon="/tmp/trans_tray/all.svg" --width=600 --height=400 --title="Edit: $1" --editable --text-info --listen --wrap --on-top > /tmp/Trans-Text-tmp
              if [ $? -eq 0 ]
              then
                  mv /tmp/Trans-Text-tmp "$1"
                  rm -f /tmp/Trans-Text-tmp
                  echo -e '\f' >/tmp/trans_tray/TP
                  cat  "$1" >/tmp/trans_tray/TP
                  echo -e '\n' >/tmp/trans_tray/TP
               fi
else
cd "$HOME/.trans_tray/savedtexts"
$EDITOR "$1"
       echo -e '\f' >/tmp/trans_tray/TP
       cat  "$1" >/tmp/trans_tray/TP
       echo -e '\n' >/tmp/trans_tray/TP
fi
               ;;
     "print") kill $MENU_PID; yad --text "Print action activated" --mouse $ONTOP;;
     "delete") kill $MENU_PID; bash -c delete;;
     "refresh") kill $MENU_PID; bash -c refresh;;
     "select editor") kill $MENU_PID;
 EDITOR=$(yad --center --window-icon="/tmp/trans_tray/all.svg" --title="Select editor" --form --field="Select or type texteditor:CBE" "internal editor!geany!leafpad!mousepad!gedit!kwrite!kate!joe!pluma" $ONTOP)
EDITOR="`echo $EDITOR | cut -d "|" -f 1`"
[ -z "$EDITOR" ] && exit
echo $EDITOR > $HOME/.trans_tray/text-editor;;
     "copy") kill $MENU_PID; cd "$HOME/.trans_tray/savedtexts"
      yad --window-icon="/tmp/trans_tray/all.svg" $ONTOP --mouse --file --width=600 --height=400 --save --text="Copy to location / rename";;
   esac     
}; export -f menu_action

function menu (){
   yad  --list --width=200 --height=160 --mouse \
        --column action --no-headers "delete" "edit" "refresh" "copy" "print" "select editor" \
        --close-on-unfocus $ONTOP --no-buttons --undecorated \
        --select-action="bash -c \"menu_action "$1" "%s"\"" &
 echo $! > /tmp/trans_tray/sttmenu_pid
}; export -f menu

trap "rm -f $stxtp $ptxts" EXIT

yad --plug=$$ --tabnum=1 --list --text="Double click raises menu" --item-separator=" " --listen --column="Saved Trans" \
    $(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
   --dclick-action="bash -c \"menu "%s"\"" \
    --select-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "%s" >/tmp/trans_tray/sel-file; 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 $ONTOP --no-buttons --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal
exit
}; export -f savedtranstexts
EDIT: A little later edited code, refresh in delete function didn't work, works now but possibly can be improved.
EDIT2: The while loop in refresh hangs after closing the main dialog, should be killed but don't know how yet, or maybe better remove that feature.
EDIT3: Edited the code above so it shouldn't leave hanging process now (e.g. bash -c refresh while loop).

Fred
Last edited by fredx181 on Thu 05 Sep 2019, 11:19, edited 1 time in total.

stemsee

#63 Post by stemsee »

hi Fred

Better add refresh to save code! Or leave it as a manual thing.

'Print' I am looking into it.

stemsee

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

#64 Post by fredx181 »

stemsee wrote:hi Fred

Better add refresh to save code! Or leave it as a manual thing.

'Print' I am looking into it.

stemsee
Hi stemsee, edited the code in my previous post, see at EDIT3.
Btw, I'm not sure that I like the constant refreshing, it causes flickering. IMO better without the while loop, to manually refresh.

Fred

stemsee

#65 Post by stemsee »

Hi Fred

the flashing is annoying.

added to save functions because that's when refresh is needed, no need for manual refresh, unless creating files manually!!!

I know I'm getting lazy supplying code :lol:

Code: Select all

t_save () {
DATE=$(date +"%Y%m%d_%H%M%S")
. $HOME/.trans_tray/prefs
   if [ "$SAVE_CLOSE" = "TRUE" ]; then
   sayonara
   mv -f /tmp/trans_tray/run_trans_edit  $HOME/.trans_tray/savedtexts/trans-$DATE
   else
   cp -a /tmp/trans_tray/run_trans  $HOME/.trans_tray/savedtexts/trans-$DATE
   fi
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to ~/.trans_tray/savedtexts/trans-$DATE </b>" --geometry=500x35-40-70 --undecorated --timeout 4 --no-buttons $ONTOP
[ -e "$stxtp" && -e "$ptxts" ] && bash -c refresh
}; export -f t_save
and

Code: Select all

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_tray/savedtexts/trans-$DATE
yad --title="Translation saved" --borders=6 --window-icon=$ICON --text="  <b>Saved to ~/.trans_tray/savedtexts/trans-$DATE </b>" --geometry=500x35-40-70 --undecorated --timeout 5 --no-buttons
[ -e "$stxtp" && -e "$ptxts" ] && bash -c refresh
}
export -f run_trans_save
EDIT: one useful feature we should add, is the ability to have dual paned type input text from english (or some native language) with translation to say spanish (or to many), and main trans window also open translating from Spanish to English (or to many). This would be conversation/dialogue mode.

maybe in dual pane mode it could switch/reverse the two languages after pressing translate button. So to summarize, select two languages A and B. Then have the ability to translate A > B and B > A. Simultaneously in two windows or alternating in one window.

Only needs to have two different target language files/variables!

Post Reply