Skip to content

Commit

Permalink
Allow to define a replacement for a specific input braille table
Browse files Browse the repository at this point in the history
  • Loading branch information
AAClause committed Mar 26, 2022
1 parent aab7a59 commit 645a20c
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions addon/globalPlugins/brailleExtender/advancedinput.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# advancedinput.py
# Part of BrailleExtender addon for NVDA
# Copyright 2016-2021 André-Abush CLAUSE, released under GPL.
# Copyright 2016-2022 André-Abush CLAUSE, released under GPL.
import codecs
import json
import os
Expand Down Expand Up @@ -176,24 +176,26 @@ def getReplacements(abreviations, strict=False):
entry
for entry in advancedInputDictHandler.getEntries()
if entry.abreviation.startswith(abreviation)
and entry.table in [currentInputTable, "*"]
and entry.table in [currentInputTable, '*']
]
else:
out += [
entry
for entry in advancedInputDictHandler.getEntries()
if entry.abreviation == abreviation
and entry.table in [currentInputTable, "*"]
and entry.table in [currentInputTable, '*']
]
return out


def translateTable(tableFilename):
if tableFilename == "*":
return _("all tables")
for table in brailleTables.listTables():
def translateTable(tableFilename, return_index=False):
if tableFilename == '*':
return 0 if return_index else _("Any (all tables)")
for i, table in enumerate(brailleTables.listTables(), 1):
if not table.input:
continue
if table.fileName == tableFilename:
return table.displayName
return i if return_index else table.displayName
return tableFilename


Expand Down Expand Up @@ -319,6 +321,7 @@ def onEditClick(self, event):
entryDialog = DictionaryEntryDlg(self)
entryDialog.abreviationTextCtrl.SetValue(entry.abreviation)
entryDialog.replacementTextCtrl.SetValue(entry.replacement)
entryDialog.table.SetSelection(translateTable(entry.table, True))
while entryDialog.ShowModal() == wx.ID_OK:
self.entry = entryDialog.dictEntry
if not self._isValid(editIndex):
Expand Down Expand Up @@ -376,17 +379,23 @@ def __init__(self, parent=None, title=_("Edit Dictionary Entry")):
sHelper = gui.guiHelper.BoxSizerHelper(self, orientation=wx.VERTICAL)
# Translators: This is a label for an edit field in add dictionary
# entry dialog.
abreviationLabelText = _("&Abreviation")
abreviationLabelText = _("&Abreviation:")
self.abreviationTextCtrl = sHelper.addLabeledControl(
abreviationLabelText, wx.TextCtrl
)
# Translators: This is a label for an edit field in add dictionary
# entry dialog.
replacementLabelText = _("&Replace by")
replacementLabelText = _("&Replace by:")
self.replacementTextCtrl = sHelper.addLabeledControl(
replacementLabelText, wx.TextCtrl
)

label = _("Input table:")
choices = [translateTable('*')]
choices.extend([table.displayName for table in brailleTables.listTables() if table.input])
self.table = sHelper.addLabeledControl(label, wx.Choice, choices=choices)
self.table.SetSelection(0)

sHelper.addDialogDismissButtons(
self.CreateButtonSizer(wx.OK | wx.CANCEL))

Expand All @@ -409,7 +418,11 @@ def onOk(self, evt):
if msg:
return gui.messageBox(msg, addonName, wx.OK | wx.ICON_ERROR)
abreviation = getTextInBraille(abreviation)
newEntry = AdvancedInputDictEntry(abreviation, replacement, "*")
table = '*'
idx = self.table.GetSelection()
if idx > 0:
table = [table.fileName for table in brailleTables.listTables() if table.input][idx-1]
newEntry = AdvancedInputDictEntry(abreviation, replacement, table)
self.dictEntry = newEntry
evt.Skip()

Expand All @@ -432,6 +445,7 @@ def makeSettings(self, settingsSizer):
wx.TextCtrl,
value=config.conf["brailleExtender"]["advancedInputMode"]
["escapeSignUnicodeValue"],)


def onSave(self):
config.conf["brailleExtender"]["advancedInputMode"]["stopAfterOneChar"] = self.stopAdvancedInputModeAfterOneChar.IsChecked()
Expand Down

0 comments on commit 645a20c

Please sign in to comment.