Skip to content

Commit

Permalink
Fix bugs.
Browse files Browse the repository at this point in the history
Fixed connection via proxy server;
Change deprecated wx.ICON_INFO to wx.ICON_INFORMATION in message boxes;
The object YandexFreeTranslate is now created once.
  • Loading branch information
alekssamos committed Nov 10, 2020
1 parent 6ac82ed commit b405b35
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Дополнение Яндекс.Переводчик для NVDA

[Скачать версию 2020.09.04](https://github.com/alekssamos/YandexTranslate/releases/latest/download/YandexTranslate-2020.09.04.nvda-addon)
[Скачать версию 2020.11.10](https://github.com/alekssamos/YandexTranslate/releases/latest/download/YandexTranslate-2020.11.10.nvda-addon)

После установки зайдите в NVDA меню, Параметры, Жесты ввода, назначте удобные вам сочетания клавиш для YandexTranslate. Или используйте уже предустановленные.

Expand Down
8 changes: 3 additions & 5 deletions addon/globalPlugins/yandexTranslate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def wrapper(self, gesture):
script(self, gesture)
return wrapper

yt = YandexFreeTranslate()
class YandexTranslateSettingsDialog(gui.SettingsDialog):
title = _("Yandex Translate Settings")

Expand Down Expand Up @@ -128,13 +129,12 @@ def postInit(self):

def onGenerate_new_key(self, event):
try:
yt = YandexFreeTranslate()
conf["key"] = yt.regenerate_key()
gui.messageBox(_("A new key is created successfully")+"\n"+conf["key"], "", style=wx.OK | wx.ICON_INFO)
gui.messageBox(_("A new key is created successfully")+"\n"+conf["key"], "", style=wx.OK | wx.ICON_INFORMATION)
except Exception as identifier:
text = _("Failed to get a new key. Check your internet connection, wait a bit or go to Yandex, enter the captcha and try again.")
ui.message(text)
log.error(sys.exc_info()[1])
log.debug(sys.exc_info()[1])
gui.messageBox(text, _("Error saving settings"), style=wx.OK | wx.ICON_ERROR)
import webbrowser
webbrowser.open_new("https://translate.yandex.ru/")
Expand Down Expand Up @@ -236,7 +236,6 @@ def _HTTPRequest(self):
log.debug("cache: True")
return True, _cache[cacheKey]

yt = YandexFreeTranslate()
if conf["useProxy"]:
yt.setProxy(conf["proxy_protocol"],
conf["proxy_host"], conf["proxy_port"], conf["proxy_username"], conf["proxy_password"])
Expand Down Expand Up @@ -274,7 +273,6 @@ def __init__(self):
pass

try:
yt = YandexFreeTranslate()
if conf["key"] == "": conf["key"] = yt.get_key()
except Exception as identifier:
pass
Expand Down
6 changes: 4 additions & 2 deletions addon/globalPlugins/yandexTranslate/yandexfreetranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _parse_sid(self):
try:
return re.search(r'''SID[\s]?[:][\s]?['"]([^'"]+)['"]''', page).group(1)
except AttributeError:
raise YandexFreeTranslateError("blocked or not found")
raise YandexFreeTranslateError("blocked or not found \n"+str(page))
def _save_key(self, key):
with open(self.keyfilename, "w", encoding="utf8") as f:
f.write(key)
Expand All @@ -101,7 +101,9 @@ def _get_key(self):
return key
def get_key(self): return self._get_key()
def regenerate_key(self):
if os.path.isfile(self.keyfilename): os.rename(self.keyfilename, self.keyfilename+".back")
try:
if os.path.isfile(self.keyfilename): os.rename(self.keyfilename, self.keyfilename+".back")
except FileExistsError: pass
return self._get_key()
def __init__(self):
if not os.path.isfile(self.keyfilename) and os.path.isfile(self.keyfilename+".back"):
Expand Down
2 changes: 1 addition & 1 deletion buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Translators: Long description to be shown for this add-on on add-on information from add-ons manager
"addon_description": _("""Translates text using service Yandex Translate."""),
# version
"addon_version": "2020.09.04",
"addon_version": "2020.11.10",
# Author(s)
"addon_author": u"alekssamos <[email protected]>",
# URL for the add-on documentation support
Expand Down

0 comments on commit b405b35

Please sign in to comment.