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

Implements another method for right margin on cells #67

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions addon/globalPlugins/brailleExtender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,7 @@ def terminate(self):
braille.TextInfoRegion._addTextWithFields = self.backup__addTextWithFields
braille.TextInfoRegion.update = self.backup__update
braille.TextInfoRegion._getTypeformFromFormatField = self.backup__getTypeformFromFormatField
braille.handler.display.display = patches.origFunc["display"]
self.removeMenu()
rolelabels.discardRoleLabels()
if addoncfg.noUnicodeTable:
Expand Down
32 changes: 21 additions & 11 deletions addon/globalPlugins/brailleExtender/addoncfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
RC_EMULATE_ARROWS_SILENT: _("alternative, emulate left and right arrow keys silently")
}
curBD = braille.handler.display.name
backupDisplaySize = braille.handler.displaySize

backupDisplaySize = 0
iniGestures = {}
iniProfile = {}
profileFileExists = gesturesFileExists = False
Expand Down Expand Up @@ -251,8 +250,9 @@ def loadPreferedTables():


def loadConf():
global curBD, gesturesFileExists, profileFileExists, iniProfile
global curBD, gesturesFileExists, profileFileExists, iniProfile, backupDisplaySize
curBD = braille.handler.display.name
backupDisplaySize = 0
try: brlextConf = config.conf["brailleExtender"].copy()
except configobj.validate.VdtValueError:
config.conf["brailleExtender"]["updateChannel"] = "dev"
Expand All @@ -261,10 +261,6 @@ def loadConf():
config.conf["brailleExtender"]["profile_%s" % curBD] = "default"
if "tabSize_%s" % curBD not in brlextConf.keys():
config.conf["brailleExtender"]["tabSize_%s" % curBD] = 2
if "leftMarginCells__%s" % curBD not in brlextConf.keys():
config.conf["brailleExtender"]["leftMarginCells_%s" % curBD] = 0
if "rightMarginCells_%s" % curBD not in brlextConf.keys():
config.conf["brailleExtender"]["rightMarginCells_%s" % curBD] = 0
if "autoScrollDelay_%s" % curBD not in brlextConf.keys():
config.conf["brailleExtender"]["autoScrollDelay_%s" % curBD] = 3000
if "keyboardLayout_%s" % curBD not in brlextConf.keys():
Expand All @@ -281,14 +277,28 @@ def loadConf():
else:
if curBD != "noBraille": log.warn("%s inaccessible" % confGen)
else: log.debug("No braille display present")

limitCellsRight = int(config.conf["brailleExtender"]["rightMarginCells_%s" % curBD])
if (backupDisplaySize-limitCellsRight <= backupDisplaySize and limitCellsRight > 0):
braille.handler.displaySize = backupDisplaySize-limitCellsRight
setRightMarginCells()
if not noUnicodeTable: loadPreferedTables()
if config.conf["brailleExtender"]["inputTableShortcuts"] not in tablesUFN: config.conf["brailleExtender"]["inputTableShortcuts"] = '?'
return True

def setRightMarginCells():
rightMarginCells = getRightMarginCells()
if rightMarginCells:
global backupDisplaySize
if not backupDisplaySize:
backupDisplaySize = braille.handler.displaySize
displaySize = backupDisplaySize-rightMarginCells
if displaySize:
try:
braille.handler.displaySize = displaySize
except AttributeError: # NVDA >= 2023.1
pass # TODO

def getRightMarginCells():
key = f"rightMarginCells_{curBD}"
return int(config.conf["brailleExtender"][key]) if key in config.conf["brailleExtender"]else 0

def loadGestures():
if gesturesFileExists:
if os.path.exists(os.path.join(profilesDir, "_BrowseMode", config.conf["braille"]["inputTable"] + ".ini")): GLng = config.conf["braille"]["inputTable"]
Expand Down
12 changes: 10 additions & 2 deletions addon/globalPlugins/brailleExtender/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
origFunc = {
"script_braille_routeTo": globalCommands.GlobalCommands.script_braille_routeTo,
"update": braille.Region.update,
"_createTablesString": louis._createTablesString
"_createTablesString": louis._createTablesString,
"display": braille.handler.display.display
}

def sayCurrentLine():
Expand Down Expand Up @@ -550,6 +551,11 @@ def _createTablesString(tablesList):
"""Creates a tables string for liblouis calls"""
return b",".join([x.encode(sys.getfilesystemencoding()) if isinstance(x, str) else bytes(x) for x in tablesList])

# braille.handler.display.display
def display(cells):
nb = addoncfg.backupDisplaySize - braille.handler.displaySize
if nb: cells += [0] * nb
origFunc["display"](cells)

def _displayWithCursor(self):
if not self._cells:
Expand All @@ -576,7 +582,6 @@ def getTetherWithRoleTerminal(self):
return braille.handler.TETHER_REVIEW
return origGetTether(self)


# applying patches
braille.Region.update = update
braille.TextInfoRegion.previousLine = previousLine
Expand All @@ -594,6 +599,9 @@ def getTetherWithRoleTerminal(self):
# This variable tells if braille region should parse undefined characters
braille.Region.parseUndefinedChars = True

if addoncfg.getRightMarginCells():
braille.handler.display.display = display

braille.BrailleHandler.AutoScroll = autoscroll.AutoScroll
braille.BrailleHandler._auto_scroll = None
braille.BrailleHandler.get_auto_scroll_delay = autoscroll.get_auto_scroll_delay
Expand Down
10 changes: 8 additions & 2 deletions addon/globalPlugins/brailleExtender/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,19 @@ def makeSettings(self, settingsSizer):
itemToSelect = list(addoncfg.outputMessage.keys()).index(config.conf["brailleExtender"]["modifierKeysFeedback"])
else:
itemToSelect = list(addoncfg.outputMessage.keys()).index(addoncfg.CHOICE_braille)
self.modifierKeysFeedback.SetSelection(itemToSelect)

# Translators: label of a dialog.
self.beepsModifiers = sHelper.addItem(wx.CheckBox(self, label=_("Play &beeps for modifier keys")))
self.beepsModifiers.SetValue(config.conf["brailleExtender"]["beepsModifiers"])

label = _("Braille display margins (beta, requires NVDA restart)")
marginsGroup = gui.guiHelper.BoxSizerHelper(self, sizer=wx.StaticBoxSizer(wx.StaticBox(self, label=label), wx.VERTICAL))
sHelper.addItem(marginsGroup)

# Translators: label of a dialog.
self.modifierKeysFeedback.SetSelection(itemToSelect)
self.rightMarginCells = sHelper.addLabeledControl(_("&Right margin on cells for the active braille display"), gui.nvdaControls.SelectOnFocusSpinCtrl, min=0, max=100, initial=int(config.conf["brailleExtender"]["rightMarginCells_%s" % addoncfg.curBD]))
label = _("&Right")
self.rightMarginCells = marginsGroup.addLabeledControl(label, gui.nvdaControls.SelectOnFocusSpinCtrl, min=0, max=100, initial=addoncfg.getRightMarginCells())
if addoncfg.gesturesFileExists:
lb = [k for k in instanceGP.getKeyboardLayouts()]
# Translators: label of a dialog.
Expand Down