Skip to content

Commit

Permalink
Version 21.11
Browse files Browse the repository at this point in the history
* Added more dictionaries;
* Changed the search routine to not be sensitive to capitalization;
* Changed the presentation of results, now allowing you to choose to search again, copy the result to clipboard or exit;
* The extra is provided only with the English, Portuguese and between the two languages dictionaries, and it is possible to download the others using a button on the interface;
* The dictionaries are stored at www.tiflotecnia.net.
  • Loading branch information
ruifontes committed Nov 20, 2021
1 parent d99f2b7 commit 54056e4
Show file tree
Hide file tree
Showing 23 changed files with 34,059 additions and 703,086 deletions.
43 changes: 26 additions & 17 deletions addon/doc/pt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,51 @@

## Informações
* Autores: Rui Fontes, Ângelo Abrantes e Abel Passos do Nascimento Jr.
* Actualizado em 16/10/2021
* Actualizado em 19/11/2021
* Descarregar [versão estável][1]
* Compatibilidade: NVDA versão 2019.3 e posteriores


## Apresentação
Este extra fornece uma forma rápida de acesso, até agora, a 17 dicionários:
* Inglês * Português e Português * Inglês;
* Francês * português e português * francês;
* Alemão * Português e Português * Alemão;
* Italiano * Português e Português * Italiano;
* Espanhol * * português e português * espanhol;
Este extra fornece uma forma rápida de acesso, até agora, a 21 dicionários:
* Inglês-Português e Português-Inglês;
* Francês-Português e Português-Francês;
* Alemão-Português e Português-Alemão;
* Italiano-Português e Português-Italiano;
* Espanhol-Português e português-espanhol;
* Inglês-espanhol;
* Inglês (Concise Oxford dictionary);
* Português (significados);
* Português (sinónimos);
* Inglês (sinónimos);
* Espanhol (RAE);
* Química;
* Medicina;
* Português * significados;
* Português * sinónimos;
* Filosofia de Nicola Abbagnano;
* Psicologia por Raul Mesquita e outro.
* Psicologia por Raul Mesquita e outro;
* Informática

Para não sobrecarregar o extra, são apenas disponibilizados os dicionários de português, inglês e entre estes dois idiomas.
Os restantes poderão ser descarregados através do próprio extra.
Estamos receptivos a incluir outros dicionários. Portanto, se desejar acrescentar um dicionário, contacte um dos autores.


## Nota importante
Por favor, lembrem-se que os substantivos em alemão devem ter a primeira letra em maiúsculas...
Note também que em alguns dicionários a primeira letra, ou todo o termo, podem estar em maiúsculas!


## Comando
O comando para invocar o add-on é Control+Shift+F6.
O comando para invocar o extra é Control+Shift+F6.
É possível alterá-lo no diálogo Definir comandos, na secção Dicionários.


## Alterações

### Versão 21.11
* Adicionados mais dicionários;
* Alterada a rotina de pesquisa para não ser sensível à capitalização;
* Modificada a apresentação de resultados, permitindo agora optar por nova pesquisa, copiar o resultado para a área de transferência ou sair;
* O extra é fornecido apenas com os dicionários de inglês e português, e entre os dois idiomas, sendo possível descarregar os restantes através de um botão colocado na interface;
* Os dicionários estão armazenados em www.tiflotecnia.net.


### Versão 21.10
* Lançamento inicial

[1]: https://github.com/ruifontes/Dictionaries/releases/download/21.10/dictionaries-21.10.nvda-addon
[1]: https://github.com/ruifontes/Dictionaries/releases/download/21.11/dictionaries-21.11.nvda-addon
246 changes: 204 additions & 42 deletions addon/globalPlugins/dictionaries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from gui import guiHelper
import ui
import api
import urllib.request
# For update process
from . update import *
# Necessary For translation
Expand All @@ -23,46 +24,59 @@
addonHandler.initTranslation()

#Global variables
filepath = os.path.join (os.path.dirname(__file__), "dictionaries") #caminho da pasta dos dicionários
filepath = os.path.join (os.path.dirname(__file__), "dictionaries") #Path of dictionaries folder

dict = {
_("english-portuguese") : "inglês-português.TXT",
_("french-portuguese") : "francês-português.txt",
_("german-portuguese") : "alemão-português.txt",
_("italian-portuguese") : "italiano-português.txt",
_("spanish-portuguese") : "espanhol-português.txt",
_("portuguese-english") : "português-inglês.txt",
_("portuguese-french") : "português-francês.txt",
_("portuguese-german") : "português-alemão.TXT",
_("portuguese-italian") : "português-italiano.txt",
_("portuguese-spanish") : "português-espanhol.txt",
_("english-portuguese") : "ingles-portugues.txt",
_("french-portuguese") : "frances-portugues.txt",
_("german-portuguese") : "alemao-portugues.txt",
_("italian-portuguese") : "italiano-portugues.txt",
_("spanish-portuguese") : "espanhol-portugues.txt",
_("portuguese-english") : "portugues-ingles.txt",
_("portuguese-french") : "portugues-frances.txt",
_("portuguese-german") : "portugues-alemao.txt",
_("portuguese-italian") : "portugues-italiano.txt",
_("portuguese-spanish") : "portugues-espanhol.txt",
_("Englis (Concise Oxford dictionary)") : "azdictionary.txt",
_("portuguese - meanings (in portuguese)") : "português-significados.txt",
_("portuguese - synonyms (in portuguese)") : "português-sinómimos.txt",
_("Chemical (in portuguese)") : "dicionário de química.txt",
_("Medical (in portuguese)") : "Dicionário Médico.txt",
_("Philosophy by Nicola Abbagnano (in portuguese)") : "Dicionário de Filosofia - Nicola Abbagnano.txt",
_("Psychology by Raul Mesquita and other (in portuguese)") : "dicionário de psicologia - Raul Mesquita e outro.txt"
_("portuguese - meanings (in portuguese)") : "portugues-significados.txt",
_("portuguese - synonyms (in portuguese)") : "portugues-sinomimos.txt",
_("Chemical (in portuguese)") : "dicionario_de_quimica.txt",
_("Medical (in portuguese)") : "dicionario_medico.txt",
_("Philosophy by Nicola Abbagnano (in portuguese)") : "dicionario_de_filosofia.txt",
_("Psychology by Raul Mesquita and other (in portuguese)") : "dicionario_de_psicologia.txt",
_("Spanish - RAE (in spanish)") : "diccionario-de-la-lengua-espanhola-rae.txt",
_("Tecnical Informatic (in portuguese)") : "dicionario_tecnico_de_informatica.txt",
_("Englis synonyms dictionary)") : "ingles-sinonimos.txt",
_("Englis Spanish)") : "ingles-espanhol.txt"
}

dictList = list(dict.keys())
missingDicts = []
availableDictsList = []
dictToUse = ""
wordToSearch = ""
ourLine = ""


class GlobalPlugin(globalPluginHandler.GlobalPlugin):
# Creating the constructor of the newly created GlobalPlugin class.
def __init__(self):
# Call of the constructor of the parent class.
super(globalPluginHandler.GlobalPlugin, self).__init__()
#. Translators Dialog title
title = _("Dictionaries")
# Calling the update process...
_MainWindows = Initialize()
_MainWindows.start()

#defining a script with decorator:
@script(
gesture="kb:Control+shift+F6",
description= _("LEARNING with NVDA"),
description= _("Main window to access several dictionaries"),
category= _("Dictionaries")
)
def script_exp1(self, event):
#To call the class "MyDialog":
#Calling the class "MyDialog" to select the dictionary to use or to download more.
gui.mainFrame._popupSettingsDialog(MyDialog)


Expand All @@ -73,60 +87,81 @@ def __init__(self, *args, **kwds):
#. Translators Dialog title
self.SetTitle(_("Dictionaries"))

#. Translators StaticText with instructions for the user:
label_1 = wx.StaticText(self, wx.ID_ANY, _("Choose the dictionary and press Enter"))
#Filter the dictionaries present on dicts folder
global missingDicts, availableDictsList, dictList
availableDictsList = os.listdir(filepath)
missingDicts = []
dictList = list(dict.keys())
n = 0
while n < len(dictList):
if dict.get(dictList[n]) not in availableDictsList: # If true dict is not present...
missingDicts.append(dictList[n]) # Join to missing dicts list...
del dictList[n] # Delete from available dicts list
n -= 1 # To allow to check all dicts since we have deleted the item with number n...
n += 1

sizer_1 = wx.BoxSizer(wx.VERTICAL)
#. Translators StaticText with instructions for the user:
label_1 = wx.StaticText(self, wx.ID_ANY, _("Choose the dictionary and press Enter"))
sizer_1.Add(label_1, 0, 0, 0)

self.choice_1 = wx.Choice(self, wx.ID_ANY, choices = dictList)
self.choice_1.SetFocus()
self.choice_1.SetSelection(0)
sizer_1.Add(self.choice_1, 0, 0, 0)
global choice_1
choice_1 = wx.Choice(self, wx.ID_ANY, choices = dictList)
choice_1.SetFocus()
choice_1.SetSelection(0)
sizer_1.Add(choice_1, 0, 0, 0)

sizer_2 = wx.StdDialogButtonSizer()
sizer_1.Add(sizer_2, 0, wx.ALIGN_RIGHT | wx.ALL, 4)

self.button_OK = wx.Button(self, wx.ID_OK, "")
self.button_OK.SetDefault()
sizer_2.AddButton(self.button_OK)
self.button_1 = wx.Button(self, wx.ID_OK, "")
self.button_1.SetDefault()
sizer_2.Add(self.button_1, 0, 0, 0)

#. Translators Button to allow the download of more dictionmaries
self.button_2 = wx.Button(self, wx.ID_ANY, _("Download more..."))
sizer_2.Add(self.button_2, 0, 0, 0)

self.button_CANCEL = wx.Button(self, wx.ID_CANCEL, "")
sizer_2.AddButton(self.button_CANCEL)

sizer_2.Realize()

self.SetSizer(sizer_1)
sizer_1.Fit(self)

self.SetAffirmativeId(self.button_OK.GetId())
self.SetAffirmativeId(self.button_1.GetId())
self.SetAffirmativeId(self.button_2.GetId())
self.SetEscapeId(self.button_CANCEL.GetId())

self.Layout()
self.CentreOnScreen()

self.Bind(wx.EVT_BUTTON, self.allButons, self.button_OK)
self.Bind(wx.EVT_BUTTON, self.allButtons, self.button_1)
self.Bind(wx.EVT_BUTTON, self.downloadMore, self.button_2)

def allButons(self, event):
def allButtons(self, event):
global dictToUse, wordToSearch, ourLine
event.Skip()
var3 = os.path.join(filepath, dict.get(self.choice_1.GetStringSelection())) # Get the path of selected dictionary
dictToUse = choice_1.GetStringSelection() # Get the selected dictionary
var3 = os.path.join(filepath, dict.get(choice_1.GetStringSelection())) # Get the path of selected dictionary
#. Translators Asking user to enter the text to search
wordToSearch = "€" + wx.GetTextFromUser(_("Enter the word or expression to search for:"), _("Dictionaries"))
with open(var3, "r", encoding = "UTF-8") as f: # Open the selected dictionary file
ourLine = f.readline() # Reads the first line where it is the length of the file
totalLines = int(ourLine) # convverts to a numerical value
x = 0 # Line counter
ourLine = ""
while not ourLine.startswith(wordToSearch) and x<totalLines: #Read all lines untill find our word or get to file end
while not ourLine.startswith(wordToSearch.lower()) and x<totalLines: #Read all lines untill find our word or get to file end
x += 1 # Counter increment
ourLine = f.readline() # When the line starts with our word ends the search
ourLine = f.readline().lower() # When the line starts with our word ends the search
if x==totalLines: # Found the end of file and the word do not exists...
#. Translators message informing the word do not exist
if gui.messageBox(
_("%s not found in the dictionary of %s.\nPlease note that some dictionaries may have the terms first letter in uppercase or even the all word...\n") %(wordToSearch[1:], self.choice_1.GetStringSelection())+
_("%s not found in the dictionary of %s.\n") %(wordToSearch[1:], dictToUse)+
"\n"+_("Do you want to search another word?"),
caption = _("Dictionaries"),
style = wx.YES | wx.NO) == wx.YES:
self.allButons(event)
MyDialog.allButtons(self, event)
else:
return
else: # If the word was found, lets get the meaning.
Expand All @@ -136,8 +171,135 @@ def allButons(self, event):
line1 = f.readline(x)
if "---" not in line1: # When false end of cycle
ourLine = ourLine + line1 # As it is not the end of the definition, add to variable
x = len(wordToSearch) # To remove the desired word of the first line
#. Translators Message with the meaning of the word searched.
msgTitle = _("Here is the meaning of %s in the dictionary %s:") %(wordToSearch[1:], self.choice_1.GetStringSelection())
ui.browseableMessage(ourLine[x:], title = msgTitle)
api.copyToClip(ourLine[x:])
y = len(wordToSearch) # To remove the desired word of the first line
ourLine = ourLine[y:].strip() # To clean the string for garbage in begining and ending
# Call the window showing the results
gui.mainFrame._popupSettingsDialog(MyDialog1)

def downloadMore(self, event):
event.Skip()
#self.Destroy()
# Calling the download window
gui.mainFrame._popupSettingsDialog(MyDialog2)


class MyDialog1(wx.Dialog):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE
wx.Dialog.__init__(self, *args, **kwds)
#. Translators Dialog title
self.SetTitle(_("Dictionaries"))

sizer_1 = wx.BoxSizer(wx.VERTICAL)

#. Translators Static text announcing the results
label_1 = wx.StaticText(self, wx.ID_ANY, _("Here is the meaning of %s in the dictionary %s:") %(wordToSearch[1:], dictToUse))
sizer_1.Add(label_1, 0, 0, 0)

self.text_ctrl_1 = wx.TextCtrl(self, wx.ID_ANY, ourLine, size = (550, 300), style=wx.TE_MULTILINE | wx.TE_READONLY)
self.text_ctrl_1.SetFocus()
sizer_1.Add(self.text_ctrl_1, 0, 0, 0)

sizer_2 = wx.StdDialogButtonSizer()
sizer_1.Add(sizer_2, 0, wx.ALIGN_RIGHT | wx.ALL, 4)

#. Translators Name of button to perform another search
self.button_1 = wx.Button(self, wx.ID_ANY, _("Search again"))
self.button_1.SetDefault()
sizer_2.Add(self.button_1, 0, 0, 0)

#. Translators Name of button that allows to copy results to clipboard
self.button_SAVE = wx.Button(self, wx.ID_ANY, _("Copy to clipboard"))
sizer_2.Add(self.button_SAVE, 0, 0, 0)

self.button_CLOSE = wx.Button(self, wx.ID_CLOSE, "")
sizer_2.AddButton(self.button_CLOSE)

sizer_2.Realize()

self.SetSizer(sizer_1)
sizer_1.Fit(self)

self.SetAffirmativeId(self.button_1.GetId())
self.Bind(wx.EVT_BUTTON, self.searchAgain, self.button_1)
self.SetEscapeId(self.button_CLOSE.GetId())
self.Bind(wx.EVT_BUTTON, self.copyToClip, self.button_SAVE)

self.Layout()
self.CentreOnScreen()

def searchAgain(self, event):
event.Skip()
# Calling the window to search another entry
MyDialog.allButtons(self, event)

def copyToClip(self, event):
event.Skip()
# Copy result to clipboard
api.copyToClip(ourLine)


class MyDialog2(wx.Dialog):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE
wx.Dialog.__init__(self, *args, **kwds)
#. Translators Dialog title
self.SetTitle(_("Dictionaries"))

sizer_1 = wx.BoxSizer(wx.VERTICAL)

#. Translators Asking user to choose the dictionary to download
label_1 = wx.StaticText(self, wx.ID_ANY, _("Choose the dictionary to download and press Enter"))
sizer_1.Add(label_1, 0, 0, 0)

self.choice_2 = wx.Choice(self, wx.ID_ANY, choices = missingDicts)
self.choice_2.SetFocus()
self.choice_2.SetSelection(0)
sizer_1.Add(self.choice_2, 0, 0, 0)

sizer_2 = wx.StdDialogButtonSizer()
sizer_1.Add(sizer_2, 0, wx.ALIGN_RIGHT | wx.ALL, 4)

self.button_1 = wx.Button(self, wx.ID_OK, "")
self.button_1.SetDefault()
sizer_2.AddButton(self.button_1)

self.button_CANCEL = wx.Button(self, wx.ID_CANCEL, "")
sizer_2.AddButton(self.button_CANCEL)

sizer_2.Realize()

self.SetSizer(sizer_1)
sizer_1.Fit(self)

self.SetAffirmativeId(self.button_1.GetId())
self.SetEscapeId(self.button_CANCEL.GetId())

self.Layout()
self.CentreOnScreen()

self.Bind(wx.EVT_BUTTON, self.download, self.button_1)
self.Bind(wx.EVT_BUTTON, self.quit, self.button_CANCEL)

def download(self, event):
event.Skip()
urlRepos = "https://www.tiflotecnia.net/dict/" # Online repository of dicts
urlN = dict.get(self.choice_2.GetStringSelection()) # Get the file name of selected dictionary to download
urlName = urlRepos + urlN # Complete URL of the dictionary file...
file = os.path.join(filepath, urlN) # Complete path where to save the dictionary

self.dialogActive = True
#. Translators: Message dialog box asking confirmation to download
if gui.messageBox(_("Are you sure you want to download the %s dictionary from %s?") %(self.choice_2.GetStringSelection(), urlName), _("Dictionaries"), style=wx.ICON_QUESTION|wx.YES_NO) == wx.YES:
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
urllib.request.urlretrieve(urlName, file)
ui.message(_("Downloading... Please wait..."))
# Calling the main window to choose the dict to use or to download more
gui.mainFrame._popupSettingsDialog(MyDialog)

def quit(self, event):
event.Skip()
# Calling the main window to choose the dict to use or to download more
gui.mainFrame._popupSettingsDialog(MyDialog)
Loading

0 comments on commit 54056e4

Please sign in to comment.