コード例 #1
0
def readObjectsHelper_generator(obj):
	lastSentIndex=0
	lastReceivedIndex=0
	speechGen=generateObjectSubtreeSpeech(obj,itertools.count())
	objIndexMap={}
	keepReading=True
	while True:
		# lastReceivedIndex might be None if other speech was interspersed with this say all.
		# In this case, we want to send more text in case this was the last chunk spoken.
		if lastReceivedIndex is None or (lastSentIndex-lastReceivedIndex)<=1:
			if keepReading:
				try:
					o,lastSentIndex=speechGen.next()
				except StopIteration:
					keepReading=False
					continue
				objIndexMap[lastSentIndex]=o
		receivedIndex=speech.getLastSpeechIndex()
		if receivedIndex!=lastReceivedIndex and (lastReceivedIndex!=0 or receivedIndex!=None): 
			lastReceivedIndex=receivedIndex
			lastReceivedObj=objIndexMap.get(lastReceivedIndex)
			if lastReceivedObj is not None:
				api.setNavigatorObject(lastReceivedObj, isFocus=lastSayAllMode==CURSOR_CARET)
			#Clear old objects from the map
			for i in objIndexMap.keys():
				if i<=lastReceivedIndex:
					del objIndexMap[i]
		while speech.isPaused:
			yield
		yield
コード例 #2
0
ファイル: sayAllHandler.py プロジェクト: JRMeyer/nvda
def readObjectsHelper_generator(obj):
	lastSentIndex=0
	lastReceivedIndex=0
	speechGen=generateObjectSubtreeSpeech(obj,itertools.count())
	objIndexMap={}
	keepReading=True
	while True:
		# lastReceivedIndex might be None if other speech was interspersed with this say all.
		# In this case, we want to send more text in case this was the last chunk spoken.
		if lastReceivedIndex is None or (lastSentIndex-lastReceivedIndex)<=1:
			if keepReading:
				try:
					o,lastSentIndex=speechGen.next()
				except StopIteration:
					keepReading=False
					continue
				objIndexMap[lastSentIndex]=o
		receivedIndex=speech.getLastSpeechIndex()
		if receivedIndex!=lastReceivedIndex and (lastReceivedIndex!=0 or receivedIndex!=None): 
			lastReceivedIndex=receivedIndex
			lastReceivedObj=objIndexMap.get(lastReceivedIndex)
			if lastReceivedObj is not None:
				api.setNavigatorObject(lastReceivedObj)
			#Clear old objects from the map
			for i in objIndexMap.keys():
				if i<=lastReceivedIndex:
					del objIndexMap[i]
		while speech.isPaused:
			yield
		yield
コード例 #3
0
def readObjectsHelper_generator(obj):
	levelsIndexMap={}
	updateObj=obj
	keepReading=True
	keepUpdating=True
	indexCount=0
	lastSpokenIndex=0
	endIndex=0
	while keepUpdating:
		while speech.isPaused:
			yield
			continue
		if keepReading:
			speech.speakObject(obj,index=indexCount,reason=speech.REASON_SAYALL)
			up=[]
			down=[]
			obj=obj.getNextInFlow(up=up,down=down)
			if not obj:
				endIndex=indexCount
				keepReading=False
			indexCount+=1
			levelsIndexMap[indexCount]=(len(up),len(down))
		spokenIndex=speech.getLastSpeechIndex()
		if spokenIndex is None:
			spokenIndex=0
		for count in range(spokenIndex-lastSpokenIndex):
			upLen,downLen=levelsIndexMap.get(lastSpokenIndex+count+1,(0,0))
			if upLen==0 and downLen==0:
				tones.beep(880,50)
			if upLen>0:
				for count in range(upLen+1):
					tones.beep(880*(1.25**count),50)
					time.sleep(0.025)
			if downLen>0:
				for count in range(downLen+1):
					tones.beep(880/(1.25**count),50)
					time.sleep(0.025)
			updateObj=updateObj.nextInFlow
			api.setNavigatorObject(updateObj)
		if not keepReading and spokenIndex>=endIndex:
			keepUpdating=False
		lastSpokenIndex=spokenIndex
		yield
コード例 #4
0
def readTextHelper_generator(info,cursor):
	sendCount=0
	receiveCount=0
	cursorIndexMap={}
	reader=info.copy()
	if not reader.isCollapsed:
		reader.collapse()
	keepReading=True
	keepUpdating=True
	oldSpokenIndex=None
	while keepUpdating:
		if not reader.obj:
			# The object died, so we should too.
			return
		# receiveCount might be None if other speech was interspersed with this say all.
		# In this case, we want to send more text in case this was the last chunk spoken.
		if receiveCount is None or (sendCount-receiveCount)<=10:
			if keepReading:
				bookmark=reader.bookmark
				index=sendCount
				delta=reader.move(textInfos.UNIT_READINGCHUNK,1,endPoint="end")
				if delta<=0:
					keepReading=False
					continue
				speech.speakTextInfo(reader,unit=textInfos.UNIT_READINGCHUNK,reason=speech.REASON_SAYALL,index=index)
				sendCount+=1
				cursorIndexMap[index]=bookmark
				reader.collapse(end=True)
		spokenIndex=speech.getLastSpeechIndex()
		if spokenIndex!=oldSpokenIndex:
			oldSpokenIndex=spokenIndex
			receiveCount=spokenIndex
			bookmark=cursorIndexMap.get(spokenIndex,None)
			if bookmark is not None:
				updater=reader.obj.makeTextInfo(bookmark)
				if cursor==CURSOR_CARET:
					updater.updateCaret()
				if cursor!=CURSOR_CARET or config.conf["reviewCursor"]["followCaret"]:
					api.setReviewPosition(updater)
		while speech.isPaused:
			yield
		yield
コード例 #5
0
ファイル: sayAllHandler.py プロジェクト: JRMeyer/nvda
def readTextHelper_generator(cursor):
	if cursor==CURSOR_CARET:
		try:
			reader=api.getCaretObject().makeTextInfo(textInfos.POSITION_CARET)
		except (NotImplementedError, RuntimeError):
			return
	else:
		reader=api.getReviewPosition()

	lastSentIndex=0
	lastReceivedIndex=0
	cursorIndexMap={}
	keepReading=True
	speakTextInfoState=speech.SpeakTextInfoState(reader.obj)
	with SayAllProfileTrigger():
		while True:
			if not reader.obj:
				# The object died, so we should too.
				return
			# lastReceivedIndex might be None if other speech was interspersed with this say all.
			# In this case, we want to send more text in case this was the last chunk spoken.
			if lastReceivedIndex is None or (lastSentIndex-lastReceivedIndex)<=10:
				if keepReading:
					bookmark=reader.bookmark
					index=lastSentIndex+1
					delta=reader.move(textInfos.UNIT_READINGCHUNK,1,endPoint="end")
					if delta<=0:
						speech.speakWithoutPauses(None)
						keepReading=False
						continue
					speech.speakTextInfo(reader,unit=textInfos.UNIT_READINGCHUNK,reason=controlTypes.REASON_SAYALL,index=index,useCache=speakTextInfoState)
					lastSentIndex=index
					cursorIndexMap[index]=(bookmark,speakTextInfoState.copy())
					try:
						reader.collapse(end=True)
					except RuntimeError: #MS Word when range covers end of document
						# Word specific: without this exception to indicate that further collapsing is not posible, say-all could enter an infinite loop.
						speech.speakWithoutPauses(None)
						keepReading=False
			else:
				# We'll wait for speech to catch up a bit before sending more text.
				if speech.speakWithoutPauses.lastSentIndex is None or (lastSentIndex-speech.speakWithoutPauses.lastSentIndex)>=10:
					# There is a large chunk of pending speech
					# Force speakWithoutPauses to send text to the synth so we can move on.
					speech.speakWithoutPauses(None)
			receivedIndex=speech.getLastSpeechIndex()
			if receivedIndex!=lastReceivedIndex and (lastReceivedIndex!=0 or receivedIndex!=None): 
				lastReceivedIndex=receivedIndex
				bookmark,state=cursorIndexMap.get(receivedIndex,(None,None))
				if state:
					state.updateObj()
				if bookmark is not None:
					updater=reader.obj.makeTextInfo(bookmark)
					if cursor==CURSOR_CARET:
						updater.updateCaret()
					if cursor!=CURSOR_CARET or config.conf["reviewCursor"]["followCaret"]:
						api.setReviewPosition(updater)
			elif not keepReading and lastReceivedIndex==lastSentIndex:
				# All text has been sent to the synth.
				# Turn the page and start again if the object supports it.
				if isinstance(reader.obj,textInfos.DocumentWithPageTurns):
					try:
						reader.obj.turnPage()
					except RuntimeError:
						break
					else:
						reader=reader.obj.makeTextInfo(textInfos.POSITION_FIRST)
						keepReading=True
				else:
					break

			while speech.isPaused:
				yield
			yield

		# Wait until the synth has actually finished speaking.
		# Otherwise, if there is a triggered profile with a different synth,
		# we will switch too early and truncate speech (even up to several lines).
		# Send another index and wait for it.
		index=lastSentIndex+1
		speech.speak([speech.IndexCommand(index)])
		while speech.getLastSpeechIndex()<index:
			yield
			yield
		# Some synths say they've handled the index slightly sooner than they actually have,
		# so wait a bit longer.
		for i in xrange(30):
			yield
コード例 #6
0
def elten_command(ac):
	global eltenmod
	global eltenbraille
	global eltenbrailletext
	global eltenindex
	global eltenindexid
	global eltenqueue
	try:
		if(('ac' in ac)==False): return {}
		if(ac['ac']=="speak"):
			eltenindex=None
			eltenindexid=None
			text=""
			if('text' in ac): text=ac['text']
			if(speech.isBlank(text)==False): queueHandler.queueFunction(queueHandler.eventQueue,speech.speakText,text)
		if(ac['ac']=="speakindexed"):
			eltenindex=None
			eltenindexid=None
			texts=[]
			indexes=[]
			indid=None
			if('texts' in ac): texts=ac['texts']
			if('indexes' in ac): indexes=ac['indexes']
			if('indid' in ac): indid=ac['indid']
			v=[]
			for i in range(0, len(texts)):
				if is_python_3_or_above:
					if(speech.isBlank(texts[i])): continue
					if(i<len(indexes)): v.append(EltenIndexCallback(indexes[i], indid))
					if(i<len(indexes) and i>0 and texts[i-1]!="" and texts[i-1][-1]=="\n"): v.append(speech.EndUtteranceCommand())
				else:
					eltenindexid=indid
					if(i<len(indexes)): v.append(speech.IndexCommand(indexes[i]))
				v.append(texts[i])
			speech.cancelSpeech()
			speech.speak(v)
		if(ac['ac']=='stop'):
			speech.cancelSpeech()
			eltenindex=None
			eltenindexid=None
		if(ac['ac']=='sleepmode'):
			st=eltenmod.sleepMode
			if('st' in ac): st=ac['st']
			eltenmod.sleepMode=st
			return {'st': st}
		if(ac['ac']=='init'):
			pid=0
			if('pid' in ac): pid=ac['pid']
			eltenmod = appModuleHandler.getAppModuleFromProcessID(pid)
			def script_eltengesture(self, gesture):
				global eltenqueue
				eltenqueue['gestures']+=gesture.identifiers
			eltenmod.__class__.script_eltengesture = types.MethodType(script_eltengesture, eltenmod.__class__)
			eltenmod.bindGesture('kb(laptop):NVDA+A', 'eltengesture')
			eltenmod.bindGesture('kb(laptop):NVDA+L', 'eltengesture')
			eltenmod.bindGesture('kb(desktop):NVDA+downArrow', 'eltengesture')
			eltenmod.bindGesture('kb(desktop):NVDA+upArrow', 'eltengesture')
		if(ac['ac']=='braille'):
			text=""
			if('text' in ac): text=ac['text']
			if('type' in ac and 'index' in ac):
				if ac['type']==-1: text=eltenbrailletext[:ac['index']]+eltenbrailletext[ac['index']+1:]
				elif ac['type']==1: text=eltenbrailletext[:ac['index']]+text+eltenbrailletext[ac['index']:]
			eltenbrailletext=text+" "
			regions=[]
			for phrase in re.split("([.,:/\n?!])", eltenbrailletext):
				if phrase=="": continue
				if len(regions)>10000: continue;
				region=braille.TextRegion(phrase)
				if hasattr(region, 'parseUndefinedChars'): region.parseUndefinedChars=False
				region.update()
				regions.append(region)
			eltenbraille.regions=regions
			if('pos' in ac): 
				poses = eltenbraille.rawToBraillePos
				if(ac['pos']<len(text) and ac['pos']<len(poses)):
					reg, pos = eltenbraille.bufferPosToRegionPos(poses[ac['pos']])
					eltenbraille.scrollTo(reg, pos)
			if('cursor' in ac and ac['cursor'] is not None):
				poses = eltenbraille.rawToBraillePos
				reg, pos = eltenbraille.bufferPosToRegionPos(poses[ac['cursor']])
				reg.cursorPos=reg.brailleToRawPos[pos]
				reg.update()
			eltenbraille.update()
			braille.handler.update()
		if(ac['ac']=='braillepos' and 'pos' in ac and len(eltenbraille.regions)>0):
			poses = eltenbraille.rawToBraillePos
			if(ac['pos']<len(poses)):
				reg, pos = eltenbraille.bufferPosToRegionPos(poses[ac['pos']])
				eltenbraille.scrollTo(reg, pos)
				reg.update()
			if('cursor' in ac and ac['cursor'] is not None):
				reg, pos = eltenbraille.bufferPosToRegionPos(poses[ac['cursor']])
				reg.cursorPos=reg.brailleToRawPos[pos]
				reg.update()
			eltenbraille.update()
			braille.handler.update()
		if(ac['ac']=='getversion'):
			return {'version': 33}
		if(ac['ac']=='getnvdaversion'):
			return {'version': buildVersion.version}
		if(ac['ac']=='getindex'):
			if(is_python_3_or_above):
				return {'index': eltenindex, 'indid': eltenindexid}
			else:
				return {'index': speech.getLastSpeechIndex(), 'indid': eltenindexid}
	except Exception as Argument:
		log.exception("Elten: command thread")
		return {}
	return {}
コード例 #7
0
def readTextHelper_generator(cursor):
    if cursor == CURSOR_CARET:
        try:
            reader = api.getCaretObject().makeTextInfo(
                textInfos.POSITION_CARET)
        except (NotImplementedError, RuntimeError):
            return
    else:
        reader = api.getReviewPosition()

    lastSentIndex = 0
    lastReceivedIndex = 0
    cursorIndexMap = {}
    keepReading = True
    speakTextInfoState = speech.SpeakTextInfoState(reader.obj)

    start = time.time()

    with SayAllProfileTrigger():
        while True:
            if not reader.obj:
                # The object died, so we should too.
                return
            # lastReceivedIndex might be None if other speech was interspersed with this say all.
            # In this case, we want to send more text in case this was the last chunk spoken.
            if lastReceivedIndex is None or (lastSentIndex -
                                             lastReceivedIndex) <= 10:
                if keepReading:
                    bookmark = reader.bookmark
                    index = lastSentIndex + 1
                    delta = reader.move(textInfos.UNIT_READINGCHUNK,
                                        1,
                                        endPoint="end")
                    if delta <= 0:
                        speech.speakWithoutPauses(None)
                        keepReading = False
                        continue
                    speech.speakTextInfo(reader,
                                         unit=textInfos.UNIT_READINGCHUNK,
                                         reason=controlTypes.REASON_SAYALL,
                                         index=index,
                                         useCache=speakTextInfoState)
                    lastSentIndex = index
                    cursorIndexMap[index] = (bookmark,
                                             speakTextInfoState.copy())
                    try:
                        reader.collapse(end=True)
                    except RuntimeError:  #MS Word when range covers end of document
                        # Word specific: without this exception to indicate that further collapsing is not posible, say-all could enter an infinite loop.
                        speech.speakWithoutPauses(None)
                        keepReading = False
            else:
                # We'll wait for speech to catch up a bit before sending more text.
                if speech.speakWithoutPauses.lastSentIndex is None or (
                        lastSentIndex -
                        speech.speakWithoutPauses.lastSentIndex) >= 10:
                    # There is a large chunk of pending speech
                    # Force speakWithoutPauses to send text to the synth so we can move on.
                    speech.speakWithoutPauses(None)
            receivedIndex = speech.getLastSpeechIndex()
            if receivedIndex != lastReceivedIndex and (
                    lastReceivedIndex != 0 or receivedIndex != None):
                lastReceivedIndex = receivedIndex
                bookmark, state = cursorIndexMap.get(receivedIndex,
                                                     (None, None))
                if state:
                    state.updateObj()
                if bookmark is not None:
                    updater = reader.obj.makeTextInfo(bookmark)
                    if cursor == CURSOR_CARET:
                        updater.updateCaret()
                    if cursor != CURSOR_CARET or config.conf["reviewCursor"][
                            "followCaret"]:
                        api.setReviewPosition(updater,
                                              isCaret=cursor == CURSOR_CARET)
            elif not keepReading and lastReceivedIndex == lastSentIndex:
                # All text has been sent to the synth.
                # Turn the page and start again if the object supports it.
                if isinstance(reader.obj, textInfos.DocumentWithPageTurns):
                    try:
                        reader.obj.turnPage()
                    except RuntimeError:
                        break
                    else:
                        reader = reader.obj.makeTextInfo(
                            textInfos.POSITION_FIRST)
                        keepReading = True
                else:
                    break

            while speech.isPaused:
                yield
            yield

            now = time.time()

            if (now - start) > int(min) * 60 + int(sec):
                speech.cancelSpeech()
                break

        # Wait until the synth has actually finished speaking.
        # Otherwise, if there is a triggered profile with a different synth,
        # we will switch too early and truncate speech (even up to several lines).
        # Send another index and wait for it.
        index = lastSentIndex + 1
        speech.speak([speech.IndexCommand(index)])
        while speech.getLastSpeechIndex() < index:
            yield
            yield
        # Some synths say they've handled the index slightly sooner than they actually have,
        # so wait a bit longer.
        for i in xrange(30):
            yield
コード例 #8
0
def readTextHelper_generator(cursor):
	if cursor==CURSOR_CARET:
		try:
			reader=api.getCaretObject().makeTextInfo(textInfos.POSITION_CARET)
		except (NotImplementedError, RuntimeError):
			return
	else:
		reader=api.getReviewPosition()

	lastSentIndex=0
	lastReceivedIndex=0
	cursorIndexMap={}
	keepReading=True
	while True:
		if not reader.obj:
			# The object died, so we should too.
			return
		# lastReceivedIndex might be None if other speech was interspersed with this say all.
		# In this case, we want to send more text in case this was the last chunk spoken.
		if lastReceivedIndex is None or (lastSentIndex-lastReceivedIndex)<=10:
			if keepReading:
				bookmark=reader.bookmark
				index=lastSentIndex+1
				delta=reader.move(textInfos.UNIT_READINGCHUNK,1,endPoint="end")
				if delta<=0:
					speech.speakWithoutPauses(None)
					keepReading=False
					continue
				speech.speakTextInfo(reader,unit=textInfos.UNIT_READINGCHUNK,reason=controlTypes.REASON_SAYALL,index=index)
				lastSentIndex=index
				cursorIndexMap[index]=bookmark
				try:
					reader.collapse(end=True)
				except RuntimeError: #MS Word when range covers end of document
					speech.speakWithoutPauses(None)
					keepReading=False
		else:
			# We'll wait for speech to catch up a bit before sending more text.
			if speech.speakWithoutPauses.lastSentIndex is None or (lastSentIndex-speech.speakWithoutPauses.lastSentIndex)>=10:
				# There is a large chunk of pending speech
				# Force speakWithoutPauses to send text to the synth so we can move on.
				speech.speakWithoutPauses(None)
		receivedIndex=speech.getLastSpeechIndex()
		if receivedIndex!=lastReceivedIndex and (lastReceivedIndex!=0 or receivedIndex!=None): 
			lastReceivedIndex=receivedIndex
			bookmark=cursorIndexMap.get(receivedIndex,None)
			if bookmark is not None:
				updater=reader.obj.makeTextInfo(bookmark)
				if cursor==CURSOR_CARET:
					updater.updateCaret()
				if cursor!=CURSOR_CARET or config.conf["reviewCursor"]["followCaret"]:
					api.setReviewPosition(updater)
		elif not keepReading and lastReceivedIndex==lastSentIndex:
			# All text has been spoken.
			# Turn the page and start again if the object supports it.
			if isinstance(reader.obj,textInfos.DocumentWithPageTurns):
				try:
					reader.obj.turnPage()
				except RuntimeError:
					break
				else:
					reader=reader.obj.makeTextInfo(textInfos.POSITION_FIRST)
					keepReading=True
			else:
				break

		while speech.isPaused:
			yield
		yield