Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced input mode: implementation of suggestions #111

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions addon/globalPlugins/brailleExtender/advancedinput.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
# 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 @@ -177,24 +177,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 @@ -320,6 +322,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 @@ -377,17 +380,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 @@ -410,7 +419,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 @@ -433,6 +446,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
Loading