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

Improves tables feature #56

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8e1bea5
Braille tables improvements: groups, settings, etc.
AAClause May 29, 2020
d237460
Merge branch 'master' into tables
AAClause Jun 1, 2020
d48a042
Optimizes an import
AAClause Jun 1, 2020
fa9fdb8
Merge branch 'master' into tables
AAClause Jun 8, 2020
273712e
Fixes #61
AAClause Jun 22, 2020
e994939
Merge branch 'master' into tables
AAClause Jul 16, 2020
0dc2398
fixes a grammatical error: groups of tables -> table groups
AAClause Jul 17, 2020
c453760
Merge branch 'master' into tables
AAClause Jul 18, 2020
c20acd4
Merge branch 'master' into tables
AAClause Jul 20, 2020
c95fb28
Merge branch 'master' into tables
AAClause Jul 25, 2020
0a0dbd6
Format code, optimize 'import's
AAClause Jul 26, 2020
9c684ce
Add 2 'SetFocus()'s
AAClause Jul 26, 2020
b3322c1
Optimize 'import's
AAClause Jul 26, 2020
cd94a7a
Merge branch 'master' into tables
AAClause Aug 1, 2020
739d64a
Merge branch 'master' into tables
AAClause Aug 1, 2020
128a232
Merge branch 'master' into tables
AAClause Aug 12, 2020
9cc2dfa
Merge branch 'master' into tables
AAClause Aug 17, 2020
5669b27
Merge branch 'master' into tables
AAClause Sep 14, 2020
34804d7
Merge branch 'master' into tables
AAClause Sep 20, 2020
cd1ee8d
Small rewrites (to be continued)
AAClause Sep 24, 2020
348a6f7
WIP: Code refactoring
AAClause Oct 24, 2020
aeaacce
Merge branch 'master' into tables
AAClause Oct 26, 2020
7b4eba2
Merge branch 'master' into tables
AAClause Nov 7, 2020
d19f24a
Restore 'braille tables' settings
AAClause Nov 7, 2020
a8d2a75
Merge branch 'master' into tables
AAClause Jul 13, 2021
87de882
Merge branch 'master' into tables
AAClause Nov 11, 2022
26166c8
Various enhancements
AAClause Nov 13, 2022
9cbb910
Merge branch 'master' into tables
AAClause Apr 1, 2023
e6a99fa
Merge branch 'master' into tables
AAClause May 12, 2024
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
139 changes: 89 additions & 50 deletions addon/globalPlugins/brailleExtender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import api
import braille
import brailleInput
import brailleTables
import config
import globalCommands
import globalPluginHandler
Expand All @@ -30,8 +29,10 @@
from logHandler import log

from . import addoncfg

config.conf.spec["brailleExtender"] = addoncfg.getConfspec()
from . import advancedinput
from . import tablegroups
from . import huc
from . import documentformatting
from . import objectpresentation
Expand All @@ -42,6 +43,7 @@
from . import undefinedchars
from . import updatecheck
from . import utils
from .tablehelper import get_table_by_file_name
from .common import (addonName, addonURL, addonVersion, punctuationSeparator,
RC_NORMAL, RC_EMULATE_ARROWS_BEEP, RC_EMULATE_ARROWS_SILENT)

Expand Down Expand Up @@ -106,8 +108,7 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
_pGestures = OrderedDict()
rotorGES = {}
noKC = None
if not addoncfg.noUnicodeTable:
backupInputTable = brailleInput.handler.table
backupInputTable = brailleInput.handler.table
backupMessageTimeout = None

def __init__(self):
Expand All @@ -131,13 +132,14 @@ def __init__(self):
self.backup__addTextWithFields = braille.TextInfoRegion._addTextWithFields
self.backup__update = braille.TextInfoRegion.update
self.backup__getTypeformFromFormatField = braille.TextInfoRegion._getTypeformFromFormatField
self.backup__brailleTableDict = config.conf["braille"]["translationTable"]
braille.TextInfoRegion._addTextWithFields = documentformatting.decorator(braille.TextInfoRegion._addTextWithFields, "addTextWithFields")
braille.TextInfoRegion.update = documentformatting.decorator(braille.TextInfoRegion.update, "update")
braille.TextInfoRegion._getTypeformFromFormatField = documentformatting.decorator(braille.TextInfoRegion._getTypeformFromFormatField, "_getTypeformFromFormatField")
if config.conf["brailleExtender"]["reverseScrollBtns"]: self.reverseScrollBtns()
self.createMenu()

advancedinput.initialize()
tablegroups.initializeGroups()
if config.conf["brailleExtender"]["features"]["roleLabels"]:
rolelabels.loadRoleLabels()
objectpresentation.loadOrderProperties()
Expand All @@ -157,14 +159,13 @@ def event_gainFocus(self, obj, nextHandler):
rotorItem = 0
self.bindRotorGES()

if "tabSize_%s" % addoncfg.curBD not in config.conf["brailleExtender"].copy().keys(): self.onReload(None, 1)
if "tabSize_%s" % addoncfg.curBD not in config.conf["brailleExtender"]["tables"].copy().keys(): self.onReload(None, 1)
if self.hourDatePlayed: self.script_hourDate(None)
if self.autoTestPlayed: self.script_autoTest(None)
if braille.handler is not None and addoncfg.curBD != braille.handler.display.name:
addoncfg.curBD = braille.handler.display.name
self.onReload(None, 1)

if self.backup__brailleTableDict != config.conf["braille"]["translationTable"]: self.reloadBrailleTables()
nextHandler()

def event_foreground(self, obj, nextHandler):
Expand Down Expand Up @@ -209,13 +210,13 @@ def createMenu(self):
lambda event: wx.CallAfter(gui.mainFrame._popupSettingsDialog, settings.AddonSettingsDialog),
item
)
dictionariesMenu = wx.Menu()
self.submenu.AppendSubMenu(dictionariesMenu, _("Table &dictionaries"), _("'Braille dictionaries' menu"))
item = dictionariesMenu.Append(wx.ID_ANY, _("&Global dictionary"), _("A dialog where you can set global dictionary by adding dictionary entries to the list."))
tabledictionariesMenu = wx.Menu()
self.submenu.AppendSubMenu(tabledictionariesMenu, _("Table &dictionaries"), _("'Braille dictionaries' menu"))
item = tabledictionariesMenu.Append(wx.ID_ANY, _("&Global dictionary"), _("A dialog where you can set global dictionary by adding dictionary entries to the list."))
gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onDefaultDictionary, item)
item = dictionariesMenu.Append(wx.ID_ANY, _("&Table dictionary"), _("A dialog where you can set table-specific dictionary by adding dictionary entries to the list."))
item = tabledictionariesMenu.Append(wx.ID_ANY, _("&Table dictionary"), _("A dialog where you can set table-specific dictionary by adding dictionary entries to the list."))
gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onTableDictionary, item)
item = dictionariesMenu.Append(wx.ID_ANY, _("Te&mporary dictionary"), _("A dialog where you can set temporary dictionary by adding dictionary entries to the list."))
item = tabledictionariesMenu.Append(wx.ID_ANY, _("Te&mporary dictionary"), _("A dialog where you can set temporary dictionary by adding dictionary entries to the list."))
gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onTemporaryDictionary, item)

item = self.submenu.Append(wx.ID_ANY, _("Advanced &input mode dictionary..."), _("Advanced input mode configuration"))
Expand Down Expand Up @@ -243,10 +244,10 @@ def createMenu(self):
self.submenu_item = gui.mainFrame.sysTrayIcon.menu.Insert(2, wx.ID_ANY, "%s (%s)" % (_("&Braille Extender"), addonVersion), self.submenu)

def reloadBrailleTables(self):
self.backup__brailleTableDict = config.conf["braille"]["translationTable"]
tabledictionaries.setDictTables()
tabledictionaries.notifyInvalidTables()
if config.conf["brailleExtender"]["tabSpace"]:
patches.louis.liblouis.lou_free()
#tabledictionaries.setDictTables()
#tabledictionaries.notifyInvalidTables()
if config.conf["brailleExtender"]["tables"]["tabSpace"]:
liblouisDef = r"always \t " + ("0-" * addoncfg.getTabSize()).strip('-')
patches.louis.compileString(patches.getCurrentBrailleTables(), bytes(liblouisDef, "ASCII"))
undefinedchars.setUndefinedChar()
Expand All @@ -257,7 +258,7 @@ def onDefaultDictionary(evt):

@staticmethod
def onTableDictionary(evt):
outTable = addoncfg.tablesTR[addoncfg.tablesFN.index(config.conf["braille"]["translationTable"])]
outTable = tablegroups.listTablesDisplayName()[tablegroups.listTablesFileName().index(config.conf["braille"]["translationTable"])]
gui.mainFrame._popupSettingsDialog(tabledictionaries.DictionaryDlg, _("Table dictionary ({})").format(outTable), "table")

@staticmethod
Expand Down Expand Up @@ -561,7 +562,7 @@ def script_reportExtraInfos(self, gesture):

def script_getTableOverview(self, gesture):
inTable = brailleInput.handler.table.displayName
ouTable = addoncfg.tablesTR[addoncfg.tablesFN.index(config.conf["braille"]["translationTable"])]
ouTable = tablegroups.listTablesDisplayName()[tablegroups.listTablesFileName().index(config.conf["braille"]["translationTable"])]
t = (_(" Input table")+": %s\n"+_("Output table")+": %s\n\n") % (inTable+' (%s)' % (brailleInput.handler.table.fileName), ouTable+' (%s)' % (config.conf["braille"]["translationTable"]))
t += utils.getTableOverview()
ui.browseableMessage("<pre>%s</pre>" % t, _("Table overview (%s)") % brailleInput.handler.table.displayName, True)
Expand Down Expand Up @@ -735,47 +736,87 @@ def script_decreaseDelayAutoScroll(self, gesture):
script_decreaseDelayAutoScroll.__doc__ = _("Decrease braille autoscroll delay")

def script_switchInputBrailleTable(self, gesture):
if addoncfg.noUnicodeTable:
return ui.message(_("NVDA 2017.3 or later is required to use this feature"))
if len(addoncfg.inputTables) < 2:
return ui.message(_("You must choose at least two tables for this feature. Please fill in the settings"))
if not config.conf["braille"]["inputTable"] in addoncfg.inputTables:
addoncfg.inputTables.append(config.conf["braille"]["inputTable"])
tid = addoncfg.inputTables.index(config.conf["braille"]["inputTable"])
nID = tid + 1 if tid + 1 < len(addoncfg.inputTables) else 0
brailleInput.handler.table = brailleTables.listTables(
)[addoncfg.tablesFN.index(addoncfg.inputTables[nID])]
ui.message(_("Input: %s") % brailleInput.handler.table.displayName)
return
script_switchInputBrailleTable.__doc__ = _("Switches between configured braille input tables")
table = config.conf["braille"]["inputTable"]
usageIn = tablegroups.USAGE_INPUT
choices = tablegroups.TableGroups(
tablegroups.tablesToGroups(
tablegroups.getPreferredTables()[0] + tablegroups._groups.get_groups()[0],
usageIn
)
)
if len(choices) < 2:
return ui.message(_("Please fill at least two tables and/or groups of tables for this feature first"))
newGroup = tablegroups.getGroup(
position=tablegroups.POSITION_NEXT,
usageIn=usageIn,
choices=choices
)
if newGroup:
res = tablegroups.setTableOrGroup(
usageIn=usageIn,
e=newGroup
)
if not res:
log.error(f"Unable to set table or group (res={res}, usageIn={usageIn} newGroup={newGroup})")
ui.message(_(f"Unable to set table or group"))
return
brailleInput.handler.table = newGroup.members[0]
self.reloadBrailleTables()
utils.refreshBD()
#tabledictionaries.setDictTables()
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")

def script_switchOutputBrailleTable(self, gesture):
if addoncfg.noUnicodeTable:
return ui.message(_("NVDA 2017.3 or later is required to use this feature"))
if len(addoncfg.outputTables) < 2:
return ui.message(_("You must choose at least two tables for this feature. Please fill in the settings"))
if not config.conf["braille"]["translationTable"] in addoncfg.outputTables:
addoncfg.outputTables.append(config.conf["braille"]["translationTable"])
tid = addoncfg.outputTables.index(
config.conf["braille"]["translationTable"])
nID = tid + 1 if tid + 1 < len(addoncfg.outputTables) else 0
config.conf["braille"]["translationTable"] = addoncfg.outputTables[nID]
table = config.conf["braille"]["translationTable"]
usageIn = tablegroups.USAGE_OUTPUT
choices = tablegroups.TableGroups(
tablegroups.tablesToGroups(
tablegroups.getPreferredTables()[1] + tablegroups._groups.get_groups()[1],
usageIn
)
)
if len(choices) < 2:
return ui.message(_("Please fill at least two tables and/or groups of tables for this feature first"))
newGroup = tablegroups.getGroup(
position=tablegroups.POSITION_NEXT,
usageIn=usageIn,
choices=choices
)
if newGroup:
res = tablegroups.setTableOrGroup(
usageIn=usageIn,
e=newGroup
)
if not res:
log.error(f"Unable to set table or group (res={res}, usageIn={usageIn} newGroup={newGroup})")
ui.message(_(f"Unable to set table or group"))
return
self.reloadBrailleTables()
utils.refreshBD()
tabledictionaries.setDictTables()
ui.message(_("Output: %s") % addoncfg.tablesTR[addoncfg.tablesFN.index(config.conf["braille"]["translationTable"])])
return
script_switchOutputBrailleTable.__doc__ = _("Switches between configured braille output tables")
#tabledictionaries.setDictTables()
desc = (newGroup.name + (" (%s)" % _("group") if len(newGroup.members) > 1 else '') if newGroup else (_("Default") + " (%s)" % tablegroups.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 = addoncfg.tablesTR[addoncfg.tablesFN.index(config.conf["braille"]["translationTable"])]
inTable = None
ouTable = None
if tablegroups.groupEnabled():
i = tablegroups.getGroup(tablegroups.USAGE_INPUT)
o = tablegroups.getGroup(tablegroups.USAGE_OUTPUT)
if i: inTable = i.name
if o: ouTable = o.name
if not inTable: inTable = brailleInput.handler.table.displayName
if not ouTable: ouTable = tablegroups.listTablesDisplayName()[tablegroups.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__ = _("Reports the current braille input and output tables")

def script_brlDescChar(self, gesture):
Expand Down Expand Up @@ -1214,16 +1255,14 @@ def terminate(self):
braille.TextInfoRegion._getTypeformFromFormatField = self.backup__getTypeformFromFormatField
self.removeMenu()
rolelabels.discardRoleLabels()
if addoncfg.noUnicodeTable:
brailleInput.handler.table = self.backupInputTable
if self.hourDatePlayed:
self.hourDateTimer.Stop()
if addoncfg.noMessageTimeout:
config.conf["braille"]["noMessageTimeout"] = self.backupMessageTimeout
if braille.handler._auto_scroll:
braille.handler.toggle_auto_scroll()
if self.autoTestPlayed: self.autoTestTimer.Stop()
tabledictionaries.removeTmpDict()
#tabledictionaries.removeTmpDict()
advancedinput.terminate()
super().terminate()

Expand Down
40 changes: 12 additions & 28 deletions addon/globalPlugins/brailleExtender/addoncfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,12 @@

noMessageTimeout = True if 'noMessageTimeout' in config.conf["braille"] else False
outputTables = inputTables = None
preTable = []
postTable = []
preTables = []
postTables = []
if not os.path.exists(profilesDir): log.error('Profiles\' path not found')
else: log.debug('Profiles\' path (%s) found' % profilesDir)
try:
import brailleTables
tables = brailleTables.listTables()
tablesFN = [t[0] for t in brailleTables.listTables()]
tablesUFN = [t[0] for t in brailleTables.listTables() if not t.contracted and t.output]
tablesTR = [t[1] for t in brailleTables.listTables()]
noUnicodeTable = False
except BaseException:
noUnicodeTable = True

def getValidBrailleDisplayPrefered():
def getValidBrailleDisplayPreferred():
l = braille.getDisplayList()
l.append(("last", _("last known")))
return l
Expand Down Expand Up @@ -147,11 +138,6 @@ def getConfspec():
"backup_tetherTo": 'string(default="focus")',
"backup_autoTether": "boolean(default=True)",
},
"inputTableShortcuts": 'string(default="?")',
"inputTables": 'string(default="%s")' % config.conf["braille"]["inputTable"] + ", unicode-braille.utb",
"outputTables": "string(default=%s)" % config.conf["braille"]["translationTable"],
"tabSpace": "boolean(default=False)",
f"tabSize_{curBD}": "integer(min=1, default=2, max=42)",
"undefinedCharsRepr": {
"method": f"integer(min=0, default=8)",
"hardSignPatternValue": "string(default=??)",
Expand All @@ -166,7 +152,6 @@ def getConfspec():
"table": "string(default=current)",
"characterLimit": "integer(min=0, default=2048)",
},
"postTable": 'string(default="None")',
"viewSaved": "string(default=%s)" % NOVIEWSAVED,
"reviewModeTerminal": "boolean(default=True)",
"features": {
Expand Down Expand Up @@ -259,7 +244,7 @@ def getConfspec():
}
},
"quickLaunches": {},
"brailleTables": {},
"roleLabels": {},
"advancedInputMode": {
"stopAfterOneChar": "boolean(default=True)",
"escapeSignUnicodeValue": "string(default=⠼)",
Expand All @@ -268,6 +253,14 @@ def getConfspec():
"enabled": "boolean(default=False)",
"inputMethod": f"option({DOT_BY_DOT}, {BOTH_SIDES}, {ONE_SIDE}, default={ONE_SIDE})",
},
"tables": {
"groups": {},
"shortcuts": 'string(default="?")',
"preferredInput": f'string(default="{config.conf["braille"]["inputTable"]}|unicode-braille.utb")',
"preferredOutput": f'string(default="{config.conf["braille"]["translationTable"]}")',
"tabSpace": "boolean(default=False)",
f"tabSize_{curBD}": "integer(min=1, default=2, max=42)",
},
}

def loadPreferedTables():
Expand Down Expand Up @@ -319,8 +312,6 @@ def loadConf():
limitCellsRight = int(config.conf["brailleExtender"]["rightMarginCells_%s" % curBD])
if (backupDisplaySize-limitCellsRight <= backupDisplaySize and limitCellsRight > 0):
braille.handler.displaySize = backupDisplaySize-limitCellsRight
if not noUnicodeTable: loadPreferedTables()
if config.conf["brailleExtender"]["inputTableShortcuts"] not in tablesUFN: config.conf["brailleExtender"]["inputTableShortcuts"] = '?'
return True

def loadGestures():
Expand Down Expand Up @@ -373,20 +364,13 @@ def initGestures():
iniGestures["globalCommands.GlobalCommands"][g])).replace('br(' + curBD + '):', '')] = g
return gesturesFileExists, iniGestures

def isContractedTable(table):
if not table in tablesFN: return False
tablePos = tablesFN.index(table)
if brailleTables.listTables()[tablePos].contracted: return True
return False

def getKeyboardLayout():
if (config.conf["brailleExtender"]["keyboardLayout_%s" % curBD] is not None
and config.conf["brailleExtender"]["keyboardLayout_%s" % curBD] in iniProfile['keyboardLayouts'].keys()):
return iniProfile['keyboardLayouts'].keys().index(config.conf["brailleExtender"]["keyboardLayout_%s" % curBD])
return 0

def getCustomBrailleTables():
return [config.conf["brailleExtender"]["brailleTables"][k].split('|', 3) for k in config.conf["brailleExtender"]["brailleTables"]]

def getTabSize():
size = config.conf["brailleExtender"]["tabSize_%s" % curBD]
Expand Down
Loading
Loading