Пример #1
0
 def cleanComtypes(self): #TODO: Make this SAPI specific?
     try:
         gen = os.path.join(util.backendsDirectory(),'comtypes','gen')
         import stat, shutil
         os.chmod(gen,stat.S_IWRITE)
         shutil.rmtree(gen,ignore_errors=True)
         if not os.path.exists(gen): os.makedirs(gen)
     except:
         util.ERROR('SAPI: Failed to empty comtypes gen dir')
Пример #2
0
def lookupGenericComError(com_error):
    try:
        errno = '0x%08X' % (com_error.hresult & 0xffffffff)
        with open(os.path.join(util.backendsDirectory(),'comerrors.txt'),'r') as f:
            lines = f.read().splitlines()
        for l1,l2,l3 in zip(lines[0::3],lines[1::3],lines[2::3]):
            if errno in l2:
                return l1,l3
    except:
        pass
    return None
Пример #3
0
def getDLLPath():
    p = os.path.join(util.profileDirectory(),'nvdaControllerClient32.dll')
    if os.path.exists(p): return p
    p = os.path.join(util.backendsDirectory(),'nvda','nvdaControllerClient32.dll')
    if os.path.exists(p): return p
    try:
        import xbmc
        if xbmc.getCondVisibility('System.HasAddon(script.module.nvdacontrollerclient)'):
            if util.DEBUG: util.LOG('Found script.module.nvdacontrollerclient module for NVDA')
            import xbmcaddon
            nvdaCCAddon = xbmcaddon.Addon('script.module.nvdacontrollerclient')
            p = os.path.join(nvdaCCAddon.getAddonInfo('path').decode('utf-8'),'nvda','nvdaControllerClient32.dll')
            if os.path.exists(p): return p
    except (ImportError,AttributeError):
        return None
    return None
Пример #4
0
def getDLLPath():
    p = os.path.join(util.profileDirectory(),'nvdaControllerClient32.dll')
    if os.path.exists(p): return p
    p = os.path.join(util.backendsDirectory(),'nvda','nvdaControllerClient32.dll')
    if os.path.exists(p): return p
    try:
        import xbmc
        if xbmc.getCondVisibility('System.HasAddon(script.module.nvdacontrollerclient)'):
            if util.DEBUG: util.LOG('Found script.module.nvdacontrollerclient module for NVDA')
            import xbmcaddon
            nvdaCCAddon = xbmcaddon.Addon('script.module.nvdacontrollerclient')
            p = os.path.join(nvdaCCAddon.getAddonInfo('path').decode('utf-8'),'nvda','nvdaControllerClient32.dll')
            if os.path.exists(p): return p
    except (ImportError,AttributeError):
        return None
    return None
Пример #5
0
 def logSAPIError(self,com_error,extra=''):
     try:
         errno = str(com_error.hresult)
         with open(os.path.join(util.backendsDirectory(),'sapi_comerrors.txt'),'r') as f:
             lines = f.read().splitlines()
         for l1,l2 in zip(lines[0::2],lines[1::2]):
             bits = l1.split()
             if errno in bits:
                 util.LOG('SAPI specific COM error ({0})[{1}]: {2}'.format(errno,bits[0],l2 or '?'))
                 break
         else:
             error = lookupGenericComError(com_error)
             if error:
                 util.LOG('SAPI generic COM error ({0})[{1}]: {2}'.format(errno,error[0],error[1] or '?'))
             else:
                 util.LOG('Failed to lookup SAPI/COM error: {0}'.format(com_error))
     except:
         util.ERROR('Error looking up SAPI error: {0}'.format(com_error))
     util.LOG('Line: {1} In: {0}{2}'.format(sys.exc_info()[2].tb_frame.f_code.co_name, sys.exc_info()[2].tb_lineno, extra and ' ({0})'.format(extra) or ''))
     if util.DEBUG: util.ERROR('Debug:')
Пример #6
0
# -*- coding: utf-8 -*-
import os, ctypes
from lib import util
from base import TTSBackendBase

DLL_PATH = os.path.join(util.backendsDirectory(),'nvda','nvdaControllerClient32.dll')

try:
	from ctypes import windll
except ImportError:
	windll =None

class NVDATTSBackend(TTSBackendBase):
	provider = 'nvda'
	displayName = 'NVDA'

	@staticmethod
	def available():
		if not windll:
			return False
		try:
			dll = ctypes.windll.LoadLibrary(DLL_PATH)
			res = dll.nvdaController_testIfRunning() == 0
			ctypes.windll.kernel32.FreeLibrary(dll._handle)
			del dll
			return res
		except:
			return False

	def __init__(self):
		try: