Skip to content

Commit

Permalink
various fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
AAClause committed Apr 24, 2020
1 parent ccf57f2 commit 98cbce1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
20 changes: 14 additions & 6 deletions addon/globalPlugins/brailleExtender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,11 +867,13 @@ def script_switchInputBrailleTable(self, gesture):
usableIn=usableIn,
e=newGroup
)
table = brailleTablesExt.getTable(newGroup.members[0] if newGroup else config.conf["braille"]["inputTable"])
if table: brailleInput.handler._table = table
if not res: raise RuntimeError("error")
self.reloadBrailleTables()
utils.refreshBD()
dictionaries.setDictTables()
desc = (newGroup.name + (" (%s)" % _("group") if len(newGroup.members) > 1 else '') if newGroup else _("Default"))
desc = (newGroup.name + (" (%s)" % _("group") if len(newGroup.members) > 1 else '') if newGroup else _("Default") + " (%s)" % brailleInput.handler.table.displayName)
ui.message(_("Input: %s") % desc)

script_switchInputBrailleTable.__doc__ = _("Switch between your favorite input braille tables including groups")
Expand All @@ -893,24 +895,30 @@ def script_switchOutputBrailleTable(self, gesture):
self.reloadBrailleTables()
utils.refreshBD()
dictionaries.setDictTables()
desc = (newGroup.name + (" (%s)" % _("group") if len(newGroup.members) > 1 else '') if newGroup else _("Default"))
desc = (newGroup.name + (" (%s)" % _("group") if len(newGroup.members) > 1 else '') if newGroup else (_("Default") + " (%s)" % brailleTablesExt.fileName2displayName([config.conf["braille"]["translationTable"]])[0]))
ui.message(_("Output: %s") % desc)

script_switchOutputBrailleTable.__doc__ = _("Switch between your favorite output braille tables including groups")

def script_currentBrailleTable(self, gesture):
inTable = brailleInput.handler.table.displayName
ouTable = brailleTablesExt.listTablesDisplayName()[brailleTablesExt.listTablesFileName().index(config.conf["braille"]["translationTable"])]
inTable = None
ouTable = None
if brailleTablesExt.groupEnabled():
i = brailleTablesExt.getGroup(brailleTablesExt.USABLE_INPUT)
o = brailleTablesExt.getGroup(brailleTablesExt.USABLE_OUTPUT)
if i: inTable = i.name
if o: ouTable = o.name
if not inTable: inTable = brailleInput.handler.table.displayName
if not ouTable: ouTable = brailleTablesExt.listTablesDisplayName()[brailleTablesExt.listTablesFileName().index(config.conf["braille"]["translationTable"])]
if ouTable == inTable:
braille.handler.message(_("I⣿O:{I}").format(I=inTable, O=ouTable))
speech.speakMessage(_("Input and output: {I}.").format(I=inTable, O=ouTable))
else:
braille.handler.message(_("I:{I} ⣿ O: {O}").format(I=inTable, O=ouTable))
speech.speakMessage(_("Input: {I}; Output: {O}").format(I=inTable, O=ouTable))
return

script_currentBrailleTable.__doc__ = _(
"Announce the current input and output braille tables")
"Announce the current input and output braille tables and/or groups")

def script_brlDescChar(self, gesture):
utils.currentCharDesc()
Expand Down
9 changes: 7 additions & 2 deletions addon/globalPlugins/brailleExtender/brailleTablesExt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
POSITION_NEXT = "n"
POSITIONS = [POSITION_CURRENT, POSITION_PREVIOUS, POSITION_NEXT]

USABLE_INPUT = "i"
USABLE_OUTPUT = "o"
USABLE_INPUT = 'i'
USABLE_OUTPUT = 'o'
USABLE_LIST = [USABLE_INPUT, USABLE_OUTPUT]

GroupTables = namedtuple("GroupTables", ("name", "members", "usableIn"))
Expand Down Expand Up @@ -78,6 +78,11 @@ def getCustomBrailleTables():

def isContractedTable(fileName):
return fileName in listTablesFileName(listContractedTables())
def getTable(fileName, tables=None):
if not tables: tables = listTables()
for table in tables:
if table.fileName == fileName: return table
return None

def getTablesFilenameByID(l: List[int], tables=None) -> List[int]:
tablesFileName = [table.fileName for table in (tables or listTables())]
Expand Down
42 changes: 27 additions & 15 deletions addon/globalPlugins/brailleExtender/dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,40 @@
}
DIRECTION_LABELS_ORDERING = (DIRECTION_BOTH, DIRECTION_FORWARD, DIRECTION_BACKWARD)

dictTables = []
invalidDictTables = set()
inputTables = []
outputTables = []
invalidTables = set()

def checkTable(path):
global invalidDictTables
global invalidTables
tablesString = b",".join([x.encode("mbcs") if isinstance(x, str) else bytes(x) for x in [path]])
if not louis.liblouis.lou_checkTable(tablesString):
log.error("Can't compile: tables %s" % path)
invalidDictTables.add(path)
invalidTables.add(path)
return False
return True

def getValidPathsDict():
def getValidPathsDict(usableIn):
types = ["tmp", "table", "default"]
paths = [getPathDict(type_) for type_ in types]
paths = [getPathDict(type_, usableIn) for type_ in types]
valid = lambda path: os.path.exists(path) and os.path.isfile(path) and checkTable(path)
return [path for path in paths if valid(path)]

def getPathDict(type_):
if brailleTablesExt.groupEnabled(): return ''
if type_ == "table": path = os.path.join(configDir, "brailleDicts", config.conf["braille"]["translationTable"])
def getPathDict(type_, usableIn):
groupEnabled = brailleTablesExt.groupEnabled()
g = brailleTablesExt.getGroup(usableIn=usableIn)
table = os.path.join(configDir, "brailleDicts", config.conf["braille"]["inputTable"]) if usableIn == brailleTablesExt.USABLE_INPUT else config.conf["braille"]["translationTable"]
if type_ == "table":
if groupEnabled and g and g.members:
if len(g.members) == 1: path = os.path.join(configDir, "brailleDicts", g.members[0])
else: path = ''
else: path = os.path.join(configDir, "brailleDicts", table)
elif type_ == "tmp": path = os.path.join(configDir, "brailleDicts", "tmp")
else: path = os.path.join(configDir, "brailleDicts", "default")
else:
if groupEnabled and g and g.members:
if len(g.members) == 1: path = os.path.join(configDir, "brailleDicts", "default")
else: path = ''
else: path = os.path.join(configDir, "brailleDicts", "default")
return "%s.cti" % path

def getDictionary(type_):
Expand Down Expand Up @@ -99,18 +110,19 @@ def saveDict(type_, dict_):
return True

def setDictTables():
global dictTables
dictTables = getValidPathsDict()
invalidDictTables.clear()
global inputTables, outTable
inputTables = getValidPathsDict(brailleTablesExt.USABLE_INPUT)
outputTables = getValidPathsDict(brailleTablesExt.USABLE_OUTPUT)
invalidTables.clear()

def notifyInvalidTables():
if invalidDictTables:
if invalidTables:
dicts = {
getPathDict("default"): "default",
getPathDict("table"): "table",
getPathDict("tmp"): "tmp"
}
msg = _("One or more errors are present in dictionaries tables. Concerned dictionaries: %s. As a result, these dictionaries are not loaded.") % ", ".join([dicts[path] for path in invalidDictTables if path in dicts])
msg = _("One or more errors are present in dictionaries tables. Concerned dictionaries: %s. As a result, these dictionaries are not loaded.") % ", ".join([dicts[path] for path in invalidTables if path in dicts])
wx.CallAfter(gui.messageBox, msg, _("Braille Extender"), wx.OK|wx.ICON_ERROR)

def removeTmpDict():
Expand Down
2 changes: 1 addition & 1 deletion addon/globalPlugins/brailleExtender/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def getCurrentBrailleTables(input_=False, brf=False):
else:
tables = []
app = appModuleHandler.getAppModuleForNVDAObject(api.getNavigatorObject())
if brailleInput.handler._table.fileName == config.conf["braille"]["translationTable"] and app and app.appName != "nvda": tables += dictionaries.dictTables
if brailleInput.handler._table.fileName == config.conf["braille"]["translationTable"] and app and app.appName != "nvda": tables += dictionaries.inputTables if input_ else dictionaries.outputTables
if input_:
mainTable = os.path.join(brailleTables.TABLES_DIR, brailleInput.handler._table.fileName)
group = brailleTablesExt.getGroup(usableIn='i')
Expand Down

0 comments on commit 98cbce1

Please sign in to comment.