I copied one function from others that translate a word which select by "xsel". But I need to press a binded key. I want it automatically. (It means sdcv will automatically translate current word after I double click on word or select this text word.)
bellowing is that code.
-- {{{ sdcv/stardict
awful.key({ modkey }, "d", function ()
local f = io.popen("xsel -o")
local new_word = f:read("*a")
f:close()
if frame ~= nil then
naughty.destroy(frame)
frame = nil
if old_word == new_word then
return
end
end
old_word = new_word
local fc = ""
local f = io.popen("sdcv -n --utf8-output -u '朗道英汉字典5.0' -u 'WordNet'
"..new_word)
for line in f:lines() do
fc = fc .. line .. '\n'
end
f:close()
frame = naughty.notify({ title = '<span color="blue" font="DejaVu Sans Mono
bold 12">' ..new_word.. '</span>', text = '<span font="DejaVu Sans Mono bold
9">' ..fc..'</span>', timeout = 30, position = "top_left", width = 700, fg =
"black", bg = "white" })
-- {{{ TTS
-- using spawn_with_shell because of the pipe ;)
awful.util.spawn_with_shell( "sleep 0.6 ; echo \""..new_word.."\" |
pronounce.sh " )
-- awful.util.spawn_with_shell( "ncmpcpp pause ; echo
\""..new_word.."\" | espeak" )
-- }}}
end),
awful.key({ modkey, "Shift" }, "d", function ()
awful.prompt.run({prompt = "Dict: "}, mypromptbox[mouse.screen].widget,
function(cinword)
naughty.destroy(frame)
if cinword == "" then
return
end
local fc = ""
local f = io.popen("sdcv -n --utf8-output -u '朗道英汉字典5.0' -u 'WordNet'
"..cinword)
for line in f:lines() do
fc = fc .. line .. '\n'
end
f:close()
-- frame = naughty.notify({ text = fc, timeout = 30, width = 320 })
frame = naughty.notify({ title = '<span color="red" font="DejaVu Sans Mono
bold 12">' ..cinword.. '</span>', text = '<span font="DejaVu Sans Mono bold
9">' ..fc..'</span>', timeout = 30, position = "top_left", width = 700, fg =
"black", bg = "white" })
-- {{{ TTS
awful.util.spawn_with_shell( "sleep 0.6 ; echo \""..cinword.."\" |
pronounce.sh " )
-- }}}
end, nil, awful.util.getdir("cache").."/dict")
end),
-- }}}
--
>> stardiviner << =>GPG: 5D9F64D8 Twitter: @numbchild
http://stardiviner.dyndns-blog.com/author.html
-- {{{ sdcv/stardict
awful.key({ modkey }, "d", function ()
local f = io.popen("xsel -o")
local new_word = f:read("*a")
f:close()
if frame ~= nil then
naughty.destroy(frame)
frame = nil
if old_word == new_word then
return
end
end
old_word = new_word
local fc = ""
local f = io.popen("sdcv -n --utf8-output -u '朗道英汉字典5.0' -u 'WordNet'
"..new_word)
for line in f:lines() do
fc = fc .. line .. '\n'
end
f:close()
frame = naughty.notify({ title = '<span color="blue" font="DejaVu Sans Mono
bold 12">' ..new_word.. '</span>', text = '<span font="DejaVu Sans Mono bold
9">' ..fc..'</span>', timeout = 30, position = "top_left", width = 700, fg =
"black", bg = "white" })
-- {{{ TTS
-- using spawn_with_shell because of the pipe ;)
awful.util.spawn_with_shell( "sleep 0.6 ; echo \""..new_word.."\" |
pronounce.sh " )
-- awful.util.spawn_with_shell( "ncmpcpp pause ; echo
\""..new_word.."\" | espeak" )
-- }}}
end),
awful.key({ modkey, "Shift" }, "d", function ()
awful.prompt.run({prompt = "Dict: "}, mypromptbox[mouse.screen].widget,
function(cinword)
naughty.destroy(frame)
if cinword == "" then
return
end
local fc = ""
local f = io.popen("sdcv -n --utf8-output -u '朗道英汉字典5.0' -u 'WordNet'
"..cinword)
for line in f:lines() do
fc = fc .. line .. '\n'
end
f:close()
-- frame = naughty.notify({ text = fc, timeout = 30, width = 320 })
frame = naughty.notify({ title = '<span color="red" font="DejaVu Sans Mono
bold 12">' ..cinword.. '</span>', text = '<span font="DejaVu Sans Mono bold
9">' ..fc..'</span>', timeout = 30, position = "top_left", width = 700, fg =
"black", bg = "white" })
-- {{{ TTS
awful.util.spawn_with_shell( "sleep 0.6 ; echo \""..cinword.."\" |
pronounce.sh " )
-- }}}
end, nil, awful.util.getdir("cache").."/dict")
end),
-- }}}
signature.asc
Description: Digital signature
