Skip to content

Commit

Permalink
Release 1.6
Browse files Browse the repository at this point in the history
1. 新增翻译结果拷贝功能:对于正向翻译、反向翻译、剪贴板正向翻译、剪贴板反向翻译,可通过双击手势拷贝翻译结果到剪贴板。
2. 设置界面联动“使用共享密钥”复选框:当勾选“使用共享密钥”复选框,禁用私有密钥输入框。
  • Loading branch information
huaiyinfeilong committed May 30, 2023
1 parent 5933848 commit 43ab76f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
7 changes: 6 additions & 1 deletion addon/doc/zh_CN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

* 翻译刚才听到的内容:NVDA+W
* 反向翻译刚才听到的内容:NVDA+SHIFT+W
* 循环切换自动翻译模式(禁用、常规、反向):NVDA+F8
* 正向翻译剪贴板中的内容:NVDA+CONTROL+W
* 反向翻译剪贴板中的内容:NVDA+CONTROL+SHIFT+W
* 复制翻译结果到剪贴板:双击上述手势
* 循环切换自动翻译模式(禁用、常规、反向):NVDA+F8

## 反馈联络

Expand All @@ -21,6 +22,10 @@

## 升级日志

### Version 1.6

* 新增翻译结果拷贝功能。对于正向翻译、反向翻译、剪贴板正向翻译、剪贴板反向翻译,可通过双击手势拷贝翻译结果到剪贴板。

### Version 1.5

* 设置中增加“使用共享密钥”开关,您可以选择使用共享密钥或您自己的私钥。个人私钥申请地址:
Expand Down
42 changes: 42 additions & 0 deletions addon/globalPlugins/baiduTranslation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def makeSettings(self, sizer):
self.usingShareKeyCheckBox = helper.addItem(
wx.CheckBox(self, label=_(using_share_key_label))
)
self.usingShareKeyCheckBox.Bind(wx.EVT_CHECKBOX, self.onUsingShareKeyCheckBoxChange)
self.usingShareKeyCheckBox.SetValue(config.conf["baiduTranslation"]["usingShareKey"])
# Translators: The label for my APP ID textbox
my_app_id_label = _("My APP ID")
Expand All @@ -82,6 +83,15 @@ def makeSettings(self, sizer):
wx.TextCtrl,
)
self.myAppSecretTextCtrl.SetValue(config.conf["baiduTranslation"]["myAppSecret"])
enabled = not self.usingShareKeyCheckBox.IsChecked()
self.myAppIdTextCtrl.Enable(enabled)
self.myAppSecretTextCtrl.Enable(enabled)


def onUsingShareKeyCheckBoxChange(self, event):
enabled = not self.usingShareKeyCheckBox.IsChecked()
self.myAppIdTextCtrl.Enable(enabled)
self.myAppSecretTextCtrl.Enable(enabled)

def onSave(self):
config.conf["baiduTranslation"]["autoFromLang"] = self.autoFromLangOption.IsChecked()
Expand Down Expand Up @@ -112,6 +122,10 @@ def onSave(self):
class GlobalPlugin(globalPluginHandler.GlobalPlugin):
def __init__(self):
super(globalPluginHandler.GlobalPlugin, self).__init__()
# 翻译结果缓存,用以翻译结果拷贝,当拷贝成功后此缓存将被清空
self._translationResult = ""
# 是否拷贝翻译结果标志
self._copyFlag = False
confspec = {
"from": "string(default='en')",
"to": "string(default='zh')",
Expand Down Expand Up @@ -146,6 +160,10 @@ def terminate(self):
description=_("Translate what you just heard"),
gesture="kb:NVDA+W")
def script_translate(self, gesture):
repeatCount = scriptHandler.getLastScriptRepeatCount()
if repeatCount == 1:
self._copyTranslationResultToClipboard()
return
self._playSound()
if config.conf["baiduTranslation"]["autoFromLang"]:
from_language = "auto"
Expand All @@ -160,6 +178,10 @@ def script_translate(self, gesture):
description=_("Reverse translate what you just heard"),
gesture="kb:NVDA+SHIFT+W")
def script_reverseTranslate(self, gesture):
repeatCount = scriptHandler.getLastScriptRepeatCount()
if repeatCount == 1:
self._copyTranslationResultToClipboard()
return
self._playSound(True)
from_language = config.conf["baiduTranslation"]["from"]
to_language = config.conf["baiduTranslation"]["to"]
Expand Down Expand Up @@ -190,6 +212,10 @@ def script_switchAutomaticTranslationMode(self, gesture):
description=_("Translate the content in the clipboard"),
gesture="kb:NVDA+CONTROL+W")
def script_clipboardTranslation(self, gesture):
repeatCount = scriptHandler.getLastScriptRepeatCount()
if repeatCount == 1:
self._copyTranslationResultToClipboard()
return
self.clipboard_translation()

@scriptHandler.script(
Expand All @@ -198,6 +224,10 @@ def script_clipboardTranslation(self, gesture):
description=_("Reverse translate the content in the clipboard"),
gesture="kb:NVDA+CONTROL+SHIFT+W")
def script_clipboardReverseTranslation(self, gesture):
repeatCount = scriptHandler.getLastScriptRepeatCount()
if repeatCount == 1:
self._copyTranslationResultToClipboard()
return
self.clipboard_translation(True)

def clipboard_translation(self, reverse=False):
Expand All @@ -217,6 +247,11 @@ def clipboard_translation(self, reverse=False):
def _onResult(self, data):
if data is not None:
self._speak([data])
if self._copyFlag is True:
api.copyToClip(data)
# 拷贝完成清空缓存并重置拷贝标志
self._translationResult = ""
self._copyFlag = False

def speak(self, sequence, *args, **kwargs):
self._data = ""
Expand Down Expand Up @@ -244,3 +279,10 @@ def _playSound(self, reverse_translate=False):
filename = "translate.wav"
sound_filename = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "sound", filename))
nvwave.playWaveFile(sound_filename)

def _copyTranslationResultToClipboard(self):
if self._translationResult != "":
api.copyToClip(self._translationResult)
self._translationResult = ""
else:
self._copyFlag = True
2 changes: 1 addition & 1 deletion buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _(arg):
# Translators: Long description to be shown for this add-on on add-on information from add-ons manager
"addon_description": _("An NVDA add-on that provides baidu translation"),
# version
"addon_version": "1.5",
"addon_version": "1.6",
# Translators: Author(s)
"addon_author": "huaiyinfeilong <huaiyinfeilong@163.com>",
# URL for the add-on documentation support
Expand Down
7 changes: 6 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ An NVDA plugin that provides Baidu translation.

* Translate what you just heard: NVDA+W
* Reverse translate what you just heard: NVDA+SHIFT+W
* Cycle through automatic translation modes (disabled, normal, reverse): NVDA+F8
* Translate clipboard contents forward: NVDA+CONTROL+W
* Reverse translate clipboard content: NVDA+CONTROL+SHIFT+W
*Copy translation results to clipboard: Double click on the above gesture
* Cycle through automatic translation modes (disabled, normal, reverse): NVDA+F8

## Feedback Contact

Expand All @@ -21,6 +22,10 @@ Any comments and suggestions are welcome to communicate:

## Upgrade log

### Version 1.6

* Add translation result copying function. For forward translation, reverse translation, clipboard forward translation, and clipboard reverse translation, the translation results can be copied to the clipboard by double clicking the gesture.

### Version 1.5

* Added "Use shared key" switch in settings, you can choose to use shared key or your own private key. Personal private key application address:
Expand Down

0 comments on commit 43ab76f

Please sign in to comment.