2023-08-22 02:04:00 +01:00
|
|
|
from .cdll import libc
|
2023-08-22 16:11:00 +01:00
|
|
|
from .errors import NVDAVMCAPIError
|
2023-08-22 02:04:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
class CBindings:
|
|
|
|
bind_test_if_running = libc.nvdaController_testIfRunning
|
|
|
|
bind_speak_text = libc.nvdaController_speakText
|
|
|
|
bind_cancel_speech = libc.nvdaController_cancelSpeech
|
|
|
|
bind_braille_message = libc.nvdaController_brailleMessage
|
|
|
|
|
2023-08-22 16:11:00 +01:00
|
|
|
def call(self, fn, *args, ok=(0,), ok_exp=None):
|
2023-08-22 02:04:00 +01:00
|
|
|
retval = fn(*args)
|
2023-08-22 16:11:00 +01:00
|
|
|
if ok_exp is None:
|
|
|
|
if retval not in ok:
|
|
|
|
raise NVDAVMCAPIError(fn.__name__, retval)
|
|
|
|
elif not ok_exp(retval) and retval not in ok:
|
|
|
|
raise NVDAVMCAPIError(fn.__name__, retval)
|
2023-08-22 02:04:00 +01:00
|
|
|
return retval
|
|
|
|
|
|
|
|
|
|
|
|
class Nvda(CBindings):
|
|
|
|
@property
|
|
|
|
def is_running(self):
|
2023-08-22 16:11:00 +01:00
|
|
|
return self.call(self.bind_test_if_running, ok_exp=lambda x: x >= 0) == 0
|
2023-08-22 02:04:00 +01:00
|
|
|
|
|
|
|
def speak(self, text):
|
|
|
|
self.call(self.bind_speak_text, text)
|
|
|
|
|
|
|
|
def cancel_speech(self):
|
|
|
|
self.call(self.bind_cancel_speech)
|
|
|
|
|
|
|
|
def braille_message(self, text):
|
|
|
|
self.call(self.bind_braille_message, text)
|