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

#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


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.

Post Reply