diff --git a/source/NVDAObjects/IAccessible/MSHTML.py b/source/NVDAObjects/IAccessible/MSHTML.py index b98c745fdfa..634a2d7bf46 100644 --- a/source/NVDAObjects/IAccessible/MSHTML.py +++ b/source/NVDAObjects/IAccessible/MSHTML.py @@ -156,7 +156,7 @@ def getZoomFactorsFromHTMLDocument(HTMLDocument): except (COMError,NameError,AttributeError,TypeError): log.debugWarning("unable to fetch DPI factors") return (1,1) - return (devX/logX,devY/logY) + return (devX // logX, devY // logY) def IAccessibleFromHTMLNode(HTMLNode): try: @@ -483,7 +483,7 @@ def kwargsFromSuper(cls,kwargs,relation=None): # #3494: MSHTML's internal coordinates are always at a hardcoded DPI (usually 96) no matter the system DPI or zoom level. xFactor,yFactor=getZoomFactorsFromHTMLDocument(HTMLNode.document) try: - HTMLNode=HTMLNode.document.elementFromPoint(p.x/xFactor,p.y/yFactor) + HTMLNode=HTMLNode.document.elementFromPoint(p.x // xFactor, p.y // yFactor) except: HTMLNode=None if not HTMLNode: diff --git a/source/NVDAObjects/behaviors.py b/source/NVDAObjects/behaviors.py index 457ec73c65a..64471d93477 100755 --- a/source/NVDAObjects/behaviors.py +++ b/source/NVDAObjects/behaviors.py @@ -51,8 +51,8 @@ def event_valueChange(self): left,top,width,height=self.location except: left=top=width=height=0 - x=left+(width/2) - y=top+(height/2) + x = left + (width // 2) + y = top+ (height // 2) lastBeepProgressValue=self.progressValueCache.get("beep,%d,%d"%(x,y),None) if pbConf["progressBarOutputMode"] in ("beep","both") and (lastBeepProgressValue is None or abs(percentage-lastBeepProgressValue)>=pbConf["beepPercentageInterval"]): tones.beep(pbConf["beepMinHZ"]*2**(percentage/25.0),40) diff --git a/source/NVDAObjects/window/edit.py b/source/NVDAObjects/window/edit.py index 7de6a696d9a..00529bda049 100644 --- a/source/NVDAObjects/window/edit.py +++ b/source/NVDAObjects/window/edit.py @@ -257,7 +257,8 @@ def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True): formatField["font-name"]=charFormat.szFaceName if formatConfig["reportFontSize"]: if charFormat is None: charFormat=self._getCharFormat(offset) - formatField["font-size"]="%spt"%(charFormat.yHeight/20) + # Font size is supposed to be an integral value + formatField["font-size"]="%spt"%(charFormat.yHeight//20) if formatConfig["reportFontAttributes"]: if charFormat is None: charFormat=self._getCharFormat(offset) formatField["bold"]=bool(charFormat.dwEffects&CFE_BOLD) diff --git a/source/api.py b/source/api.py index 3c6a68f9581..821095a2736 100644 --- a/source/api.py +++ b/source/api.py @@ -257,11 +257,8 @@ def createStateList(states): def moveMouseToNVDAObject(obj): """Moves the mouse to the given NVDA object's position""" location=obj.location - if location and (len(location)==4): - (left,top,width,height)=location - x=(left+left+width)/2 - y=(top+top+height)/2 - winUser.setCursorPos(x,y) + if location: + winUser.setCursorPos(*location.center) def processPendingEvents(processEventQueue=True): # Import late to avoid circular import. diff --git a/source/appModules/devenv.py b/source/appModules/devenv.py index c752b066c87..c647a256850 100644 --- a/source/appModules/devenv.py +++ b/source/appModules/devenv.py @@ -179,13 +179,12 @@ def _createEditPoint(self): def _getOffsetFromPoint(self,x,y): yMinUnit, yMaxUnit, yVisible, yFirstVisible = self._textView.GetScrollInfo(SB_VERT) hMinUnit, hMaxUnit, hVisible, hFirstVisible = self._textView.GetScrollInfo(SB_HORZ) - # These should probably be cached as they are fairly unlikely to change, but ... lineHeight = self._textView.GetLineHeight() - charWidth = self._window.Width / hVisible + charWidth = self._window.Width // hVisible - offsetLine = (y - self._window.Top) / lineHeight + yFirstVisible - offsetChar = (x - self._window.Left) / charWidth + hFirstVisible + offsetLine = (y - self._window.Top) // lineHeight + yFirstVisible + offsetChar = (x - self._window.Left) // charWidth + hFirstVisible return self._textView.GetNearestPosition(offsetLine, offsetChar)[0] def __init__(self, obj, position): diff --git a/source/appModules/nlnotes.py b/source/appModules/nlnotes.py index 3c71adfc2b8..3a8f87b387f 100644 --- a/source/appModules/nlnotes.py +++ b/source/appModules/nlnotes.py @@ -15,8 +15,7 @@ class IrisTedit(IAccessible): def _get_name(self): - left,top,width,height=self.location - label=api.getDesktopObject().objectFromPoint(left+(width/2),top+(height/2)) + label=api.getDesktopObject().objectFromPoint(*self.location.center) if label: return label.name diff --git a/source/displayModel.py b/source/displayModel.py index 854ee9480d7..65e18fa2240 100644 --- a/source/displayModel.py +++ b/source/displayModel.py @@ -414,10 +414,10 @@ def _getClosestOffsetFromPoint(self,x,y): #Enumerate the character rectangles a=enumerate(self._storyFieldsAndRects[1]) #Convert calculate center points for all the rectangles - b=((charOffset,(charLeft+(charRight-charLeft)/2,charTop+(charBottom-charTop)/2)) for charOffset,(charLeft,charTop,charRight,charBottom) in a) - #Calculate distances from all center points to the given x and y - #But place the distance before the character offset, to make sorting by distance easier - c=((math.sqrt(abs(x-cx)**2+abs(y-cy)**2),charOffset) for charOffset,(cx,cy) in b) + b = ((charOffset, rect.center) for charOffset, rect in a) + # Calculate distances from all center points to the given x and y + # But place the distance before the character offset, to make sorting by distance easier + c = ((math.sqrt(abs(x - center.x) ** 2 + abs(y - center.y) ** 2), charOffset) for charOffset, center in b) #produce a static list of distances and character offsets, sorted by distance d=sorted(c) #Return the lowest offset with the shortest distance @@ -446,9 +446,7 @@ def _getOffsetsFromNVDAObject(self,obj): if not l: log.debugWarning("object has no location") raise LookupError - x=l[0]+(l[2]/2) - y=l[1]+(l[3]/2) - offset=self._getClosestOffsetFromPoint(x,y) + offset=self._getClosestOffsetFromPoint(*l.center) return offset,offset def _getLineOffsets(self,offset): @@ -569,9 +567,9 @@ def _setCaretOffset(self,offset): rects=self._storyFieldsAndRects[1] if offset>=len(rects): raise RuntimeError("offset %d out of range") - left,top,right,bottom=rects[offset] - x=left #+(right-left)/2 - y=top+(bottom-top)/2 + rect = rects[offset] + x = rect.x + y= rect.center.y x,y=windowUtils.logicalToPhysicalPoint(self.obj.windowHandle,x,y) oldX,oldY=winUser.getCursorPos() winUser.setCursorPos(x,y) diff --git a/source/touchHandler.py b/source/touchHandler.py index ecc5a962dfe..2928c81d3b3 100644 --- a/source/touchHandler.py +++ b/source/touchHandler.py @@ -290,9 +290,8 @@ def notifyInteraction(self, obj): @param obj: The NVDAObject with which the user is interacting. @type obj: L{NVDAObjects.NVDAObject} """ - l, t, w, h = obj.location oledll.oleacc.AccNotifyTouchInteraction(gui.mainFrame.Handle, obj.windowHandle, - POINT(l + (w / 2), t + (h / 2))) + obj.location.center.toPOINT()) handler=None diff --git a/source/touchTracker.py b/source/touchTracker.py index eccfbed7079..c0428b214e6 100644 --- a/source/touchTracker.py +++ b/source/touchTracker.py @@ -200,8 +200,8 @@ def makePreheldTrackerFromSingleTouchTrackers(self,trackers): numFingers=len(childTrackers) if numFingers==0: return if numFingers==1: return childTrackers[0] - avgX=sum(t.x for t in childTrackers)/numFingers - avgY=sum(t.y for t in childTrackers)/numFingers + avgX: int = sum(t.x for t in childTrackers) // numFingers + avgY: int = sum(t.y for t in childTrackers) // numFingers tracker=MultiTouchTracker(action_hold,avgX,avgY,childTrackers[0].startTime,time.time(),numFingers) tracker.childTrackers=childTrackers return tracker @@ -257,8 +257,8 @@ def makeMergedTrackerIfPossible(self,oldTracker,newTracker): childTrackers.extend(oldTracker.childTrackers) if oldTracker.numFingers>1 else childTrackers.append(oldTracker) childTrackers.extend(newTracker.childTrackers) if newTracker.numFingers>1 else childTrackers.append(newTracker) numFingers=oldTracker.numFingers+newTracker.numFingers - avgX=sum(t.x for t in childTrackers)/numFingers - avgY=sum(t.y for t in childTrackers)/numFingers + avgX: int =sum(t.x for t in childTrackers) // numFingers + avgY: int = sum(t.y for t in childTrackers) // numFingers mergedTracker=MultiTouchTracker(newTracker.action,avgX,avgY,oldTracker.startTime,newTracker.endTime,numFingers,newTracker.actionCount,pluralTimeout=newTracker.pluralTimeout) mergedTracker.childTrackers=childTrackers elif self.numUnknownTrackers==0 and newTracker.pluralTimeout is not None and newTracker.startTime>=oldTracker.endTime and newTracker.startTime