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

The time now is Thu 19 Sep 2019, 08:25
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Development of 'trans_tray' (translation program)
Post new topic   Reply to topic View previous topic :: View next topic
Page 5 of 7 [100 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, 7 Next
Author Message
stemsee

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

PostPosted: Wed 04 Sep 2019, 04:40    Post subject:  

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


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Wed 04 Sep 2019, 14:30    Post subject:  

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:

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

_________________
Dog Linux website
Tinylinux blog by wiak

Last edited by fredx181 on Thu 05 Sep 2019, 07:19; edited 1 time in total
Back to top
View user's profile Send private message 
stemsee

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

PostPosted: Wed 04 Sep 2019, 23:02    Post subject:  

hi Fred

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

'Print' I am looking into it.

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


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Thu 05 Sep 2019, 07:24    Post subject:  

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

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

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

PostPosted: Thu 05 Sep 2019, 09:12    Post subject:  

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

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

PostPosted: Thu 05 Sep 2019, 09:54    Post subject:  

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


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Thu 05 Sep 2019, 15:24    Post subject:  

stemsee wrote:
added to save functions because that's when refresh is needed, no need for manual refresh


Yes, good idea, then refresh works for me being outside the savedtranstexts function with path to pipes (instead of variables):
Code:
function refresh (){
      echo -e '\f' >/tmp/trans_tray/PT
      echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >/tmp/trans_tray/PT
}; export -f refresh

And also in save functions by using path to pipes:
Code:
[[ -e "/tmp/trans_tray/TP" && -e "/tmp/trans_tray/PT" ]] && refresh


Here's attached trans_tray4 with newest experiments for testing.
Also Yandex included, but I still have my doubts about it.

Does Yandex work for anyone ?
(for me it works only 1 out of 10 times)

stemsee wrote:
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.


Sounds complicated, I'm not even sure to understand what you mean exactly Smile Rolling Eyes

Fred
trans_tray4.gz
Description  for testing, remove fake .gz and make executable
gz

 Download 
Filename  trans_tray4.gz 
Filesize  41.56 KB 
Downloaded  25 Time(s) 

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

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

PostPosted: Fri 06 Sep 2019, 04:15    Post subject:  

Scenario .... youre on facebook chatting with a tall leggy blond from China. She messages you in Chinese and you respond in Chinese. You need to translate from Chinese to English to understand her love letter, then you translate from English to Chinese to return her love interest. How many clicks does it take to achieve this right now??…….at least 20! with dual panes, each editable for input/typing, and each with its own translate to language file, each sends for translate and the returned translation appears in its own pane. so one pane is en to ch, the other is ch to en. in this mode just using translate to selection gui we accept the first two languages selected 'en ch sp', we take 'en ch' and set up the dual pane notebook.

edit: doing this on a web translator like google requires either 2 tabs or two windows.

edit2: ok, i'll start it off.
Back to top
View user's profile Send private message MSN Messenger 
stemsee

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

PostPosted: Fri 06 Sep 2019, 06:14    Post subject:  

Fred

My yandex is working almost normally. it is slower than the other two, and fewer languages are supported, it seems. Did you change trans script http > https....even though it is coded to try both, better be sure?

refresh is working perfectly now!

icon changes for google+bing and google+bing+yandex (blue > red) very nice. And the yandex .svg is great!

$ONTOP|!$ONTOP is working for all windows ... very nice feature.
Back to top
View user's profile Send private message MSN Messenger 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Fri 06 Sep 2019, 12:37    Post subject:  

stemsee wrote:
Scenario .... youre on facebook chatting with a tall leggy blond from China. She messages you in Chinese and you respond in Chinese. You need to translate from Chinese to English to understand her love letter,
...
...


Ah.., now I understand ! Laughing
Would be great if you can accomplish that, I guess you intent as separate entry from tray Menu ?

Yandex seems to have a limit of 2 translations per hour (first 2 always work for me, the third not, then after +/- an hour it works again)

Fred

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

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

PostPosted: Fri 06 Sep 2019, 19:20    Post subject:  

fredx181 wrote:

Ah.., now I understand ! Laughing
Would be great if you can accomplish that, I guess you intent as separate entry from tray Menu ?


I do chat with leggy blonds in China (accomplished)!! Yes menu entry is 'dialogue'.
2019-09-07-172239_332x362_scrot.png
 Description   
 Filesize   35.28 KB
 Viewed   131 Time(s)

2019-09-07-172239_332x362_scrot.png

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

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

PostPosted: Sat 07 Sep 2019, 13:24    Post subject:  

Hi Fred

can you have a play around, as your code has to drive it. Needs run__acmd & run_bcmd. Re-use functions or rename?
Code:
function trans_dialogue () {
export TLANG=$(cat $HOME/.trans_tray/.trans_target_lang2 2> /dev/null)
export _TLANG=$(cat $HOME/.trans_tray/.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 $HOME/.trans_tray/_trans_engine_2 2> /dev/null)
[ -z "$ENGINE" ] && ENGINE=google

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

export fpipe="/tmp/trans_tray/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_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
bash -c refresh
}
export -f run_trans_save

function run_dtrans
{
    echo "3:@disable@"
export TLANG=$(cat $HOME/.trans_tray/.trans_target_lang2 2> /dev/null)
export _TLANG=$(cat $HOME/.trans_tray/.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 $HOME/.trans_tray/_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 "3:$run_cmd"
}; export -f run_dtrans
exec 5<> $fpipe
yad --plug="$fkey" --tabnum=1 --listen --form --field="<b>Translate to English</b> :LBL" "" --field="Input/paste:TXT" ""  --field="translation:TXT" ""  --field="Translate!gtk-refresh:fbtn" "$run_cmd" <&5 &
yad --plug="$fkey" --tabnum=2 --listen --form --field="<b>Translate to Chinese</b> :LBL" "" --field="Input/paste:TXT" ""  --field="translation:TXT" ""  --field="Translate!gtk-refresh:fbtn" "$run_cmd" <&5 &
yad --key=$fkey --title="dialogue mode" --paned --tab=AB --tab=BA --orient=hori &
rm -f /tmp/trans_tray/run_trans
}; export -f trans_dialogue
Back to top
View user's profile Send private message MSN Messenger 
technosaurus


Joined: 18 May 2008
Posts: 4859
Location: Blue Springs, MO

PostPosted: Sun 08 Sep 2019, 05:52    Post subject:  

Where is the microphone icon for input / text?
Pocket Sphinx
and the speaker icon for translation?
Espeak or Flite

I had a thread with pocket sphinx continuous and associated bash helpers, but the binary itself got lost when the forum lowered the limit on file size.

_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Sun 08 Sep 2019, 06:09    Post subject:  

Hi stemsee, attached transd1 and transd2.
For transd1 I modified your concept, (using the --cycle-read option), but not sure how to handle exactly because it reads from target language(s) set from tray menu.
So in both panes same target language(s).

Then I thought it might be better to have a dropdown combobox for to set language on top of each pane (transd2), doesn't read from target language set from tray-menu, so is in fact a standalone application.

Fred
transd1.gz
Description  fake .gz
gz

 Download 
Filename  transd1.gz 
Filesize  4.01 KB 
Downloaded  9 Time(s) 
transd2.gz
Description  fake .gz
gz

 Download 
Filename  transd2.gz 
Filesize  6.04 KB 
Downloaded  13 Time(s) 
2019-09-08-101300_602x529_scrot_502x441.png
 Description   transd1
 Filesize   53.66 KB
 Viewed   98 Time(s)

2019-09-08-101300_602x529_scrot_502x441.png

2019-09-08-110945_702x629_scrot_562x504.png
 Description   transd2
 Filesize   73.84 KB
 Viewed   100 Time(s)

2019-09-08-110945_702x629_scrot_562x504.png


_________________
Dog Linux website
Tinylinux blog by wiak

Last edited by fredx181 on Sun 08 Sep 2019, 06:56; edited 1 time in total
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4088
Location: holland

PostPosted: Sun 08 Sep 2019, 06:42    Post subject:  

Another experiment I've been working on earlier: strans, attached
This has a button to switch source <-> target language, perhaps useful to compare translations and easy circulate between different translations, not sure.
It identifies the source language not always correct, btw, may be confused sometimes by languages having common words.

p.s. at start it will receive input from xclip (if there is any)

Fred
demo.gif
 Description   
 Filesize   254.94 KB
 Viewed   77 Time(s)

demo.gif

strans.gz
Description  fake .gz, translate and/or switch between source and target language
gz

 Download 
Filename  strans.gz 
Filesize  6.58 KB 
Downloaded  13 Time(s) 

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 5 of 7 [100 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, 7 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

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


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