def UIAHeadingQuicknavIterator(itemType, document, position, direction="next"): if position: curPosition = position else: curPosition = document.makeTextInfo( textInfos.POSITION_LAST if direction == "previous" else textInfos.POSITION_FIRST) stop = False firstLoop = True while not stop: tempInfo = curPosition.copy() tempInfo.expand(textInfos.UNIT_CHARACTER) styleIDValue = getUIATextAttributeValueFromRange( tempInfo._rangeObj, UIAHandler.UIA_StyleIdAttributeId, ignoreMixedValues=True) # #9842: styleIDValue can sometimes be a pointer to IUnknown. # In Python 3, comparing an int with a pointer raises a TypeError. if isinstance( styleIDValue, int ) and UIAHandler.StyleId_Heading1 <= styleIDValue <= UIAHandler.StyleId_Heading9: foundLevel = (styleIDValue - UIAHandler.StyleId_Heading1) + 1 wantedLevel = int(itemType[7:]) if len(itemType) > 7 else None if not wantedLevel or wantedLevel == foundLevel: if not firstLoop or not position: tempInfo.expand(textInfos.UNIT_PARAGRAPH) yield HeadingUIATextInfoQuickNavItem(itemType, document, tempInfo, level=foundLevel) stop = (curPosition.move(textInfos.UNIT_PARAGRAPH, 1 if direction == "next" else -1) == 0) firstLoop = False
def level(self): if not hasattr(self, '_level'): styleVal = getUIATextAttributeValueFromRange( self.textInfo._rangeObj, UIAHandler.UIA_StyleIdAttributeId) if UIAHandler.StyleId_Heading1 <= styleVal <= UIAHandler.StyleId_Heading6: self._level = styleVal - (UIAHandler.StyleId_Heading1 - 1) else: self._level = None return self._level
def UIAParagraphQuicknavIterator(document, position, direction="next"): if position: curPosition = position else: curPosition = document.makeTextInfo( textInfos.POSITION_LAST if direction == "previous" else textInfos.POSITION_FIRST) stop = False firstLoop = True while not stop: tempInfo = curPosition.copy() tempInfo.expand(textInfos.UNIT_CHARACTER) styleIDValue = getUIATextAttributeValueFromRange( tempInfo._rangeObj, UIAHandler.UIA_StyleIdAttributeId) if styleIDValue == UIAHandler.StyleId_Normal: if not firstLoop or not position: tempInfo.expand(textInfos.UNIT_PARAGRAPH) yield browseMode.TextInfoQuickNavItem("paragraph", document, tempInfo) stop = (curPosition.move(textInfos.UNIT_PARAGRAPH, 1 if direction == "next" else -1) == 0) firstLoop = False