From 03415f6b249e4cf3faa0b48bc7b71f178ac17b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Tue, 14 Feb 2017 17:42:46 -0600 Subject: [PATCH] Added extras panel in account settings, added OCR Language selection for #107 --- src/controller/settings.py | 3 ++- src/extra/ocr/OCRSpace.py | 4 +++ src/wxUI/dialogs/configuration.py | 45 +++++++++---------------------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/controller/settings.py b/src/controller/settings.py index 79dc51b1..ae8be63c 100644 --- a/src/controller/settings.py +++ b/src/controller/settings.py @@ -11,6 +11,7 @@ import application from wxUI.dialogs import configuration from wxUI import commonMessageDialogs from extra.autocompletionUsers import settings +from extra.ocr import OCRSpace from pubsub import pub import logging import config_utils @@ -164,7 +165,7 @@ class accountSettingsController(globalSettingsController): self.dialog.set_value("sound", "indicate_audio", self.config["sound"]["indicate_audio"]) self.dialog.set_value("sound", "indicate_geo", self.config["sound"]["indicate_geo"]) self.dialog.set_value("sound", "indicate_img", self.config["sound"]["indicate_img"]) - self.dialog.create_extras() + self.dialog.create_extras(OCRSpace.translatable_langs) self.dialog.realize() self.dialog.set_title(_(u"Account settings for %s") % (self.user,)) self.response = self.dialog.get_response() diff --git a/src/extra/ocr/OCRSpace.py b/src/extra/ocr/OCRSpace.py index 3f66fc0b..9249b484 100644 --- a/src/extra/ocr/OCRSpace.py +++ b/src/extra/ocr/OCRSpace.py @@ -2,6 +2,10 @@ """ original module taken and modified from https://github.com/ctoth/cloudOCR""" import requests +translatable_langs = [_(u"Detect automatically"), _(u"Danish"), _(u"Dutch"), _(u"English"), _(u"Finnish"), _(u"French"), _(u"German"), _(u"Hungarian"), _(u"Korean"), _(u"Italian"), _(u"Japanese"), _(u"Polish"), _(u"Portuguese"), _(u"Russian"), _(u"Spanish"), _(u"Turkish")] +short_langs = ["", "da", "du", "en", "fi", "fr", "de", "hu", "ko", "it", "ja", "pl", "pt", "ru", "es", "tr"] +OcrLangs = ["", "dan", "dut", "eng", "fin", "fre", "ger", "hun", "kor", "ita", "jpn", "pol", "por", "rus", "spa", "tur"] + class APIError(Exception): pass diff --git a/src/wxUI/dialogs/configuration.py b/src/wxUI/dialogs/configuration.py index aada89b0..9adbaf28 100644 --- a/src/wxUI/dialogs/configuration.py +++ b/src/wxUI/dialogs/configuration.py @@ -294,38 +294,19 @@ class sound(wx.Panel): def get(self, control): return getattr(self, control).GetStringSelection() -class servicesPanel(wx.Panel): - def __init__(self, parent): - super(servicesPanel, self).__init__(parent) +class extrasPanel(wx.Panel): + def __init__(self, parent, ocr_languages=[], translation_languages=[]): + super(extrasPanel, self).__init__(parent) mainSizer = wx.BoxSizer(wx.VERTICAL) - apiKeyLabel = wx.StaticText(self, -1, _(u"If you have a SndUp account, enter your API Key here. If your API Key is invalid, {0} will fail to upload. If there is no API Key here, {0} will upload annonymously.").format(application.name,)) - self.apiKey = wx.TextCtrl(self, -1) - dc = wx.WindowDC(self.apiKey) - dc.SetFont(self.apiKey.GetFont()) - self.apiKey.SetSize(dc.GetTextExtent("0"*100)) - apiKeyBox = wx.BoxSizer(wx.HORIZONTAL) - apiKeyBox.Add(apiKeyLabel, 0, wx.ALL, 5) - apiKeyBox.Add(self.apiKey, 0, wx.ALL, 5) - mainSizer.Add(apiKeyBox, 0, wx.ALL, 5) -# self.pocketBtn = wx.Button(self, -1) -# mainSizer.Add(self.pocketBtn, 0, wx.ALL, 5) + OCRBox = wx.StaticBox(self, label=_(u"Language for OCR")) + self.ocr_lang = wx.ListBox(self, -1, choices=ocr_languages) + self.ocr_lang.SetSize(self.ocr_lang.GetBestSize()) + ocrLanguageSizer = wx.StaticBoxSizer(OCRBox, wx.HORIZONTAL) + ocrLanguageSizer.Add(self.ocr_lang, 0, wx.ALL, 5) + mainSizer.Add(ocrLanguageSizer, 0, wx.ALL, 5) + self.SetSizer(mainSizer) - def set_pocket(self, active=True): - if active == True: - self.pocketBtn.SetLabel(_(u"Disconnect your Pocket account")) - else: - self.pocketBtn.SetLabel(_(u"Connect your Pocket account")) - - def show_pocket_dialog(self): - return wx.MessageDialog(self, _(u"The authorization request will be opened in your browser. You only need to do this once. Do you want to continue?"), _(u"Pocket Authorization"), wx.YES_NO).ShowModal() - - def show_pocket_authorization_error(self): - wx.MessageDialog(self, _(u"Error during authorization. Try again later."), _(u"Error!"), wx.ICON_ERROR).ShowModal() - - def get_pocket_status(self): - return self.pocketBtn.GetLabel() - class configurationDialog(baseDialog.BaseWXDialog): def set_title(self, title): self.SetTitle(title) @@ -363,9 +344,9 @@ class configurationDialog(baseDialog.BaseWXDialog): self.sound = sound(self.notebook, output_devices, input_devices, soundpacks) self.notebook.AddPage(self.sound, _(u"Sound")) - def create_services(self): - self.services = servicesPanel(self.notebook) - self.notebook.AddPage(self.services, _(u"Services")) + def create_extras(self, ocr_languages=[], translator_languages=[]): + self.extras = extrasPanel(self.notebook, ocr_languages, translator_languages) + self.notebook.AddPage(self.extras, _(u"Extras")) def realize(self): self.sizer.Add(self.notebook, 0, wx.ALL, 5)