1- #brailleDisplayDrivers/brltty.py
2- #A part of NonVisual Desktop Access (NVDA)
3- #This file is covered by the GNU General Public License.
4- #See the file COPYING for more details.
5- #Copyright (C) 2008-2019 NV Access Limited, Babbage B.V>
1+ # A part of NonVisual Desktop Access (NVDA)
2+ # This file is covered by the GNU General Public License.
3+ # See the file COPYING for more details.
4+ # Copyright (C) 2008-2023 NV Access Limited, Babbage B.V, Bram Duvigneau
65
6+ import os
77import time
88import wx
99import braille
2121
2222KEY_CHECK_INTERVAL = 50
2323
24+ # BRLAPI named pipes for local connections are numbered and all start with a common name.
25+ # This name is set on compile time and should be the same for all BRLTTY releases,
26+ # however, if a user compiles their own version this may differ
27+ BRLAPI_NAMED_PIPE_PREFIX = "BrlAPI"
28+
2429class BrailleDisplayDriver (braille .BrailleDisplayDriver ):
2530 """brltty braille display driver.
2631 """
2732 name = "brltty"
2833 description = "brltty"
34+ isThreadSafe = True
35+
36+ @classmethod
37+ def _get_brlapi_pipes (cls ) -> List [str ]:
38+ """Get the BrlAPI named pipes
39+
40+ Every BRLTTY instance with the BrlAPI enabled will have it's own named pipe to accept API connections.
41+ The brlapi.Connection constructor takes either a `host:port` argument or just `:port`.
42+ If only a port is given, this corresponds to the number at the end of the named pipe.
43+ """
44+ return [pipe .name for pipe in os .scandir ("//./pipe/" ) if pipe .name .startswith (BRLAPI_NAMED_PIPE_PREFIX )]
2945
3046 @classmethod
3147 def check (cls ):
32- return bool (brlapi )
48+ if not bool (brlapi ):
49+ return False
50+ # Since this driver only supports local connections for now,
51+ # we can mark it as unavailable if there are no BrlAPI named pipes present
52+ return bool (cls .brlapi_pipes )
3353
3454 def __init__ (self ):
35- super (BrailleDisplayDriver , self ).__init__ ()
55+ super ().__init__ ()
3656 self ._con = brlapi .Connection ()
3757 self ._con .enterTtyModeWithPath ()
3858 self ._keyCheckTimer = wx .PyTimer (self ._handleKeyPresses )
@@ -42,7 +62,7 @@ def __init__(self):
4262 self ._con .ignoreKeys (brlapi .rangeType_type , (brlapi .KEY_TYPE_SYM ,))
4363
4464 def terminate (self ):
45- super (BrailleDisplayDriver , self ).terminate ()
65+ super ().terminate ()
4666 # Exceptions might be raised if initialisation failed. Just ignore them.
4767 try :
4868 self ._keyCheckTimer .Stop ()
@@ -100,6 +120,13 @@ def _onKeyPress(self, key):
100120 "braille_previousLine" : ("br(brltty):lnup" ,),
101121 "braille_nextLine" : ("br(brltty):lndn" ,),
102122 "braille_routeTo" : ("br(brltty):route" ,),
123+ "toggleInputHelp" : ("brl(brltty):learn" ),
124+ "showGui" : ("brl(brltty):prefmenu" ,),
125+ "revertConfiguration" : ("brl(brltty):prefload" ,),
126+ "saveConfiguration" : ("brl(brltty):prefsave" ,),
127+ "dateTime" : ("brl(brltty):time" ,),
128+ "review_currentLine" : ("brl(brltty):say_line" ,),
129+ "review_sayAll" : ("brl(brltty):say_below" ,),
103130 }
104131 })
105132
@@ -108,7 +135,7 @@ class InputGesture(braille.BrailleDisplayGesture):
108135 source = BrailleDisplayDriver .name
109136
110137 def __init__ (self , model , command , argument ):
111- super (InputGesture , self ).__init__ ()
138+ super ().__init__ ()
112139 self .model = model
113140 self .id = BRLAPI_CMD_KEYS [command ]
114141 if command == brlapi .KEY_CMD_ROUTE :
0 commit comments