Beispiel #1
0
 def _caretMovementScriptHelper(self,
                                gesture,
                                unit,
                                direction=None,
                                posConstant=textInfos.POSITION_SELECTION,
                                posUnit=None,
                                posUnitEnd=False,
                                extraDetail=False,
                                handleSymbols=False):
     oldInfo = self.makeTextInfo(posConstant)
     info = oldInfo.copy()
     info.collapse(end=not self._lastSelectionMovedStart)
     if not self._lastSelectionMovedStart and not oldInfo.isCollapsed:
         info.move(textInfos.UNIT_CHARACTER, -1)
     if posUnit is not None:
         info.expand(posUnit)
         info.collapse(end=posUnitEnd)
         if posUnitEnd:
             info.move(textInfos.UNIT_CHARACTER, -1)
     if direction is not None:
         info.expand(unit)
         info.collapse(end=posUnitEnd)
         info.move(unit, direction)
     self.selection = info
     info.expand(unit)
     if not willSayAllResume(gesture):
         speech.speakTextInfo(info,
                              unit=unit,
                              reason=controlTypes.REASON_CARET)
     if not oldInfo.isCollapsed:
         speech.speakSelectionChange(oldInfo, self.selection)
Beispiel #2
0
	def _caretMovementScriptHelper(self,gesture,unit,direction=None,posConstant=textInfos.POSITION_SELECTION,posUnit=None,posUnitEnd=False,extraDetail=False,handleSymbols=False):
		oldInfo=self.makeTextInfo(posConstant)
		info=oldInfo.copy()
		info.collapse(end=self.isTextSelectionAnchoredAtStart)
		if self.isTextSelectionAnchoredAtStart and not oldInfo.isCollapsed:
			info.move(textInfos.UNIT_CHARACTER,-1)
		if posUnit is not None:
			# expand and collapse to ensure that we are aligned with the end of the intended unit
			info.expand(posUnit)
			try:
				info.collapse(end=posUnitEnd)
			except RuntimeError:
				# MS Word has a "virtual linefeed" at the end of the document which can cause RuntimeError to be raised.
				# In this case it can be ignored.
				# See #7009
				pass
			if posUnitEnd:
				info.move(textInfos.UNIT_CHARACTER,-1)
		if direction is not None:
			info.expand(unit)
			info.collapse(end=posUnitEnd)
			if info.move(unit,direction)==0 and isinstance(self,DocumentWithPageTurns):
				try:
					self.turnPage(previous=direction<0)
				except RuntimeError:
					pass
				else:
					info=self.makeTextInfo(textInfos.POSITION_FIRST if direction>0 else textInfos.POSITION_LAST)
		self.selection=info
		info.expand(unit)
		if not willSayAllResume(gesture): speech.speakTextInfo(info,unit=unit,reason=controlTypes.REASON_CARET)
		if not oldInfo.isCollapsed:
			speech.speakSelectionChange(oldInfo,self.selection)
Beispiel #3
0
	def _caretMovementScriptHelper(self,gesture,unit,direction=None,posConstant=textInfos.POSITION_SELECTION,posUnit=None,posUnitEnd=False,extraDetail=False,handleSymbols=False):
		oldInfo=self.makeTextInfo(posConstant)
		info=oldInfo.copy()
		info.collapse(end=self.isTextSelectionAnchoredAtStart)
		if self.isTextSelectionAnchoredAtStart and not oldInfo.isCollapsed:
			info.move(textInfos.UNIT_CHARACTER,-1)
		if posUnit is not None:
			# expand and collapse to ensure that we are aligned with the end of the intended unit
			info.expand(posUnit)
			try:
				info.collapse(end=posUnitEnd)
			except RuntimeError:
				# MS Word has a "virtual linefeed" at the end of the document which can cause RuntimeError to be raised.
				# In this case it can be ignored.
				# See #7009
				pass
			if posUnitEnd:
				info.move(textInfos.UNIT_CHARACTER,-1)
		if direction is not None:
			info.expand(unit)
			info.collapse(end=posUnitEnd)
			if info.move(unit,direction)==0 and isinstance(self,DocumentWithPageTurns):
				try:
					self.turnPage(previous=direction<0)
				except RuntimeError:
					pass
				else:
					info=self.makeTextInfo(textInfos.POSITION_FIRST if direction>0 else textInfos.POSITION_LAST)
		self.selection=info
		info.expand(unit)
		if not willSayAllResume(gesture): speech.speakTextInfo(info,unit=unit,reason=controlTypes.REASON_CARET)
		if not oldInfo.isCollapsed:
			speech.speakSelectionChange(oldInfo,self.selection)
Beispiel #4
0
	def _caretMovementScriptHelper(self,gesture,unit,direction=None,posConstant=textInfos.POSITION_SELECTION,posUnit=None,posUnitEnd=False,extraDetail=False,handleSymbols=False):
		oldInfo=self.makeTextInfo(posConstant)
		info=oldInfo.copy()
		info.collapse(end=not self._lastSelectionMovedStart)
		if not self._lastSelectionMovedStart and not oldInfo.isCollapsed:
			info.move(textInfos.UNIT_CHARACTER,-1)
		if posUnit is not None:
			info.expand(posUnit)
			info.collapse(end=posUnitEnd)
			if posUnitEnd:
				info.move(textInfos.UNIT_CHARACTER,-1)
		if direction is not None:
			info.expand(unit)
			info.collapse(end=posUnitEnd)
			if info.move(unit,direction)==0 and isinstance(self,DocumentWithPageTurns):
				try:
					self.turnPage(previous=direction<0)
				except RuntimeError:
					pass
				else:
					info=self.makeTextInfo(textInfos.POSITION_FIRST if direction>0 else textInfos.POSITION_LAST)
		self.selection=info
		info.expand(unit)
		if not willSayAllResume(gesture): speech.speakTextInfo(info,unit=unit,reason=controlTypes.REASON_CARET)
		if not oldInfo.isCollapsed:
			speech.speakSelectionChange(oldInfo,self.selection)
Beispiel #5
0
 def _selectionMovementScriptHelper(self,
                                    unit=None,
                                    direction=None,
                                    toPosition=None):
     oldInfo = self.makeTextInfo(textInfos.POSITION_SELECTION)
     if toPosition:
         newInfo = self.makeTextInfo(toPosition)
         if newInfo.compareEndPoints(oldInfo, "startToStart") > 0:
             newInfo.setEndPoint(oldInfo, "startToStart")
         if newInfo.compareEndPoints(oldInfo, "endToEnd") < 0:
             newInfo.setEndPoint(oldInfo, "endToEnd")
     elif unit:
         newInfo = oldInfo.copy()
     if unit:
         if self._lastSelectionMovedStart:
             newInfo.move(unit, direction, endPoint="start")
         else:
             newInfo.move(unit, direction, endPoint="end")
     self.selection = newInfo
     if newInfo.compareEndPoints(oldInfo, "startToStart") != 0:
         self._lastSelectionMovedStart = True
     else:
         self._lastSelectionMovedStart = False
     if newInfo.compareEndPoints(oldInfo, "endToEnd") != 0:
         self._lastSelectionMovedStart = False
     speech.speakSelectionChange(oldInfo, newInfo)
Beispiel #6
0
	def _caretMovementScriptHelper(self,gesture,unit,direction=None,posConstant=textInfos.POSITION_SELECTION,posUnit=None,posUnitEnd=False,extraDetail=False,handleSymbols=False):
		oldInfo=self.makeTextInfo(posConstant)
		info=oldInfo.copy()
		info.collapse(end=not self._lastSelectionMovedStart)
		if not self._lastSelectionMovedStart and not oldInfo.isCollapsed:
			info.move(textInfos.UNIT_CHARACTER,-1)
		if posUnit is not None:
			info.expand(posUnit)
			info.collapse(end=posUnitEnd)
			if posUnitEnd:
				info.move(textInfos.UNIT_CHARACTER,-1)
		if direction is not None:
			info.expand(unit)
			info.collapse(end=posUnitEnd)
			if info.move(unit,direction)==0 and isinstance(self,DocumentWithPageTurns):
				try:
					self.turnPage(previous=direction<0)
				except RuntimeError:
					pass
				else:
					info=self.makeTextInfo(textInfos.POSITION_FIRST if direction>0 else textInfos.POSITION_LAST)
		self.selection=info
		info.expand(unit)
		if not willSayAllResume(gesture): speech.speakTextInfo(info,unit=unit,reason=controlTypes.REASON_CARET)
		if not oldInfo.isCollapsed:
			speech.speakSelectionChange(oldInfo,self.selection)
Beispiel #7
0
	def _selectionMovementScriptHelper(self,unit=None,direction=None,toPosition=None):
		oldInfo=self.makeTextInfo(textInfos.POSITION_SELECTION)
		# toPosition and unit might both be provided.
		# In this case, we move to the position before moving by the unit.
		if toPosition:
			newInfo=self.makeTextInfo(toPosition)
			if oldInfo.isCollapsed:
				self._lastSelectionMovedStart = newInfo.compareEndPoints(oldInfo, "startToStart") < 0
		elif unit:
			# position was not provided, so start from the old selection.
			newInfo = oldInfo.copy()
		if unit:
			if oldInfo.isCollapsed:
				# Starting a new selection, so set the selection direction
				# based on the direction of this movement.
				self._lastSelectionMovedStart = direction < 0
			# Find the requested unit starting from the active end of the selection.
			# We can't just move the desired endpoint because this might cause
			# the end to move before the start in some cases
			# and some implementations don't support this.
			# For example, you might shift+rightArrow to select a character in the middle of a word
			# and then press shift+control+leftArrow to move to the previous word.
			newInfo.collapse(end=not self._lastSelectionMovedStart)
			newInfo.move(unit, direction, endPoint="start" if direction < 0 else "end")
			# Collapse this so we don't have to worry about which endpoint we used here.
			newInfo.collapse(end=direction > 0)
		if self._lastSelectionMovedStart:
			if newInfo.compareEndPoints(oldInfo, "startToEnd") > 0:
				# We were selecting backwards, but now we're selecting forwards.
				# For example:
				# 1. Caret at 1
				# 2. Shift+leftArrow: selection (0, 1)
				# 3. Shift+control+rightArrow: next word at 3, so selection (1, 3)
				newInfo.setEndPoint(oldInfo, "startToEnd")
			else:
				# We're selecting backwards.
				# For example:
				# 1. Caret at 1; selection (1, 1)
				# 2. Shift+leftArrow: selection (0, 1)
				newInfo.setEndPoint(oldInfo, "endToEnd")
		else:
			if newInfo.compareEndPoints(oldInfo, "startToStart") < 0:
				# We were selecting forwards, but now we're selecting backwards.
				# For example:
				# 1. Caret at 1
				# 2. Shift+rightArrow: selection (1, 2)
				# 3. Shift+control+leftArrow: previous word at 0, so selection (0, 1)
				newInfo.setEndPoint(oldInfo, "endToStart")
			else:
				# We're selecting forwards.
				# For example:
				# 1. Caret at 1; selection (1, 1)
				# 2. Shift+rightArrow: selection (1, 2)
				newInfo.setEndPoint(oldInfo, "startToStart")
		self.selection = newInfo
		speech.speakSelectionChange(oldInfo,newInfo)
	def script_caret_changeSelection(self,gesture):
		try:
			oldInfo=self.makeTextInfo(textInfos.POSITION_SELECTION)
		except:
			gesture.send()
			return
		gesture.send()
		if isScriptWaiting() or eventHandler.isPendingEvents("gainFocus"):
			return
		api.processPendingEvents(processEventQueue=False)
		try:
			newInfo=self.makeTextInfo(textInfos.POSITION_SELECTION)
		except:
			return
		speech.speakSelectionChange(oldInfo,newInfo)
Beispiel #9
0
	def detectPossibleSelectionChange(self):
		"""Detects if the selection has been changed, and if so it speaks the change.
		"""
		try:
			newInfo=self.makeTextInfo(textInfos.POSITION_SELECTION)
		except:
			# Just leave the old selection, which is usually better than nothing.
			return
		oldInfo=getattr(self,'_lastSelectionPos',None)
		self._lastSelectionPos=newInfo.copy()
		if not oldInfo:
			# There's nothing we can do, but at least the last selection will be right next time.
			return
		hasContentChanged=getattr(self,'hasContentChangedSinceLastSelection',False)
		self.hasContentChangedSinceLastSelection=False
		speech.speakSelectionChange(oldInfo,newInfo,generalize=hasContentChanged)
Beispiel #10
0
	def script_caret_changeSelection(self,gesture):
		try:
			oldInfo=self.makeTextInfo(textInfos.POSITION_SELECTION)
		except:
			gesture.send()
			return
		gesture.send()
		if isScriptWaiting() or eventHandler.isPendingEvents("gainFocus"):
			return
		api.processPendingEvents(processEventQueue=False)
		try:
			newInfo=self.makeTextInfo(textInfos.POSITION_SELECTION)
		except:
			return
		speech.speakSelectionChange(oldInfo,newInfo)
		braille.handler.handleCaretMove(self)
Beispiel #11
0
	def detectPossibleSelectionChange(self):
		"""Detects if the selection has been changed, and if so it speaks the change.
		"""
		try:
			newInfo=self.makeTextInfo(textInfos.POSITION_SELECTION)
		except:
			# Just leave the old selection, which is usually better than nothing.
			return
		oldInfo=getattr(self,'_lastSelectionPos',None)
		self._lastSelectionPos=newInfo.copy()
		if not oldInfo:
			# There's nothing we can do, but at least the last selection will be right next time.
			return
		hasContentChanged=getattr(self,'hasContentChangedSinceLastSelection',False)
		self.hasContentChangedSinceLastSelection=False
		speech.speakSelectionChange(oldInfo,newInfo,generalize=hasContentChanged)
	def _caretMovementScriptHelper(self,unit,direction=None,posConstant=textInfos.POSITION_SELECTION,posUnit=None,posUnitEnd=False,extraDetail=False,handleSymbols=False):
		oldInfo=self.makeTextInfo(posConstant)
		info=oldInfo.copy()
		info.collapse(end=not self._lastSelectionMovedStart)
		if not self._lastSelectionMovedStart and not oldInfo.isCollapsed:
			info.move(textInfos.UNIT_CHARACTER,-1)
		if posUnit is not None:
			info.expand(posUnit)
			info.collapse(end=posUnitEnd)
			if posUnitEnd:
				info.move(textInfos.UNIT_CHARACTER,-1)
		if direction is not None:
			info.expand(unit)
			info.collapse(end=posUnitEnd)
			info.move(unit,direction)
		self.selection=info
		info.expand(unit)
		speech.speakTextInfo(info,unit=unit,reason=speech.REASON_CARET)
		if not oldInfo.isCollapsed:
			speech.speakSelectionChange(oldInfo,self.selection)
Beispiel #13
0
 def _selectionMovementScriptHelper(self, unit=None, direction=None, toPosition=None):
     oldInfo = self.makeTextInfo(textInfos.POSITION_SELECTION)
     if toPosition:
         newInfo = self.makeTextInfo(toPosition)
         if newInfo.compareEndPoints(oldInfo, "startToStart") > 0:
             newInfo.setEndPoint(oldInfo, "startToStart")
         if newInfo.compareEndPoints(oldInfo, "endToEnd") < 0:
             newInfo.setEndPoint(oldInfo, "endToEnd")
     elif unit:
         newInfo = oldInfo.copy()
     if unit:
         if self._lastSelectionMovedStart:
             newInfo.move(unit, direction, endPoint="start")
         else:
             newInfo.move(unit, direction, endPoint="end")
     self.selection = newInfo
     if newInfo.compareEndPoints(oldInfo, "startToStart") != 0:
         self._lastSelectionMovedStart = True
     else:
         self._lastSelectionMovedStart = False
     if newInfo.compareEndPoints(oldInfo, "endToEnd") != 0:
         self._lastSelectionMovedStart = False
     speech.speakSelectionChange(oldInfo, newInfo)
Beispiel #14
0
 def reportSelectionChange(self, oldTextInfo):
     newInfo = self.makeTextInfo(textInfos.POSITION_SELECTION)
     speech.speakSelectionChange(oldTextInfo, newInfo)
     braille.handler.handleCaretMove(self)
Beispiel #15
0
 def _selectionMovementScriptHelper(self,
                                    unit=None,
                                    direction=None,
                                    toPosition=None):
     oldInfo = self.makeTextInfo(textInfos.POSITION_SELECTION)
     # toPosition and unit might both be provided.
     # In this case, we move to the position before moving by the unit.
     if toPosition:
         newInfo = self.makeTextInfo(toPosition)
         if oldInfo.isCollapsed:
             self.isTextSelectionAnchoredAtStart = newInfo.compareEndPoints(
                 oldInfo, "startToStart") >= 0
     elif unit:
         # position was not provided, so start from the old selection.
         newInfo = oldInfo.copy()
     if unit:
         if oldInfo.isCollapsed:
             # Starting a new selection, so set the selection direction
             # based on the direction of this movement.
             self.isTextSelectionAnchoredAtStart = direction > 0
         # Find the requested unit starting from the active end of the selection.
         # We can't just move the desired endpoint because this might cause
         # the end to move before the start in some cases
         # and some implementations don't support this.
         # For example, you might shift+rightArrow to select a character in the middle of a word
         # and then press shift+control+leftArrow to move to the previous word.
         newInfo.collapse(end=self.isTextSelectionAnchoredAtStart)
         newInfo.move(unit,
                      direction,
                      endPoint="start" if direction < 0 else "end")
         # Collapse this so we don't have to worry about which endpoint we used here.
         newInfo.collapse(end=direction > 0)
     # If we're selecting all, we're moving both endpoints.
     # Otherwise, newInfo is the collapsed new active endpoint
     # and we need to set the anchor endpoint.
     movingSingleEndpoint = toPosition != textInfos.POSITION_ALL
     if movingSingleEndpoint and not self.isTextSelectionAnchoredAtStart:
         if newInfo.compareEndPoints(oldInfo, "startToEnd") > 0:
             # We were selecting backwards, but now we're selecting forwards.
             # For example:
             # 1. Caret at 1
             # 2. Shift+leftArrow: selection (0, 1)
             # 3. Shift+control+rightArrow: next word at 3, so selection (1, 3)
             newInfo.setEndPoint(oldInfo, "startToEnd")
             self.isTextSelectionAnchoredAtStart = True
         else:
             # We're selecting backwards.
             # For example:
             # 1. Caret at 1; selection (1, 1)
             # 2. Shift+leftArrow: selection (0, 1)
             newInfo.setEndPoint(oldInfo, "endToEnd")
     elif movingSingleEndpoint:
         if newInfo.compareEndPoints(oldInfo, "startToStart") < 0:
             # We were selecting forwards, but now we're selecting backwards.
             # For example:
             # 1. Caret at 1
             # 2. Shift+rightArrow: selection (1, 2)
             # 3. Shift+control+leftArrow: previous word at 0, so selection (0, 1)
             newInfo.setEndPoint(oldInfo, "endToStart")
             self.isTextSelectionAnchoredAtStart = False
         else:
             # We're selecting forwards.
             # For example:
             # 1. Caret at 1; selection (1, 1)
             # 2. Shift+rightArrow: selection (1, 2)
             newInfo.setEndPoint(oldInfo, "startToStart")
     self.selection = newInfo
     speech.speakSelectionChange(oldInfo, newInfo)
Beispiel #16
0
 def reportSelectionChange(self, oldTextInfo):
     api.processPendingEvents(processEventQueue=False)
     newInfo = self.makeTextInfo(textInfos.POSITION_SELECTION)
     self._updateSelectionAnchor(oldTextInfo, newInfo)
     speech.speakSelectionChange(oldTextInfo, newInfo)
     braille.handler.handleCaretMove(self)
Beispiel #17
0
 def reportSelectionChange(self, oldTextInfo):
     newInfo = self.makeTextInfo(textInfos.POSITION_SELECTION)
     speech.speakSelectionChange(oldTextInfo, newInfo)
     braille.handler.handleCaretMove(self)
Beispiel #18
0
	def reportSelectionChange(self, oldTextInfo):
		api.processPendingEvents(processEventQueue=False)
		newInfo=self.makeTextInfo(textInfos.POSITION_SELECTION)
		speech.speakSelectionChange(oldTextInfo,newInfo)
		braille.handler.handleCaretMove(self)