def label(self):
     author = self.collectionItem.author
     date = self.collectionItem.date
     text = self.collectionItem.range.text
     if text is None:
         text = ""
     msg = NVDAString(_unicode("comment: {text} by {author} on {date}"))
     return msg.format(author=author, text=text, date=date)
Exemplo n.º 2
0
	def __init__(self, document):
		self.document = document
		# Translators: The title of the browse mode Elements List dialog.
		super(ElementsListDialog, self).__init__(gui.mainFrame, wx.ID_ANY, NVDAString("Elements List"))
		mainSizer = wx.BoxSizer(wx.VERTICAL)
		contentsSizer = wx.BoxSizer(wx.VERTICAL)
		childSizer=wx.BoxSizer(wx.VERTICAL)
		# Translators: The label of a list of items to select the type of element
		# in the browse mode Elements List dialog.
		childLabel=wx.StaticText(self,wx.NewId(),label= NVDAString("&Type:") , style =wx.ALIGN_CENTRE )
		childSizer.Add(childLabel, )
		self.childListBox =wx.ListBox(self,wx.ID_ANY,name= "TypeName" ,choices=tuple(et[1] for et in self.ELEMENT_TYPES),  style = wx.LB_SINGLE ,size= (596,130))
		if self.childListBox.GetCount():
			self.childListBox.SetSelection(self.lastSelectedElementType)
		self.childListBox.Bind(wx.EVT_LISTBOX, self.onElementTypeChange)
		self.childListBox.Bind(wx.EVT_SET_FOCUS, self.onChildBoxFocus)
		childSizer.Add(self.childListBox)
		contentsSizer.Add(childSizer, flag=wx.EXPAND)
		contentsSizer.AddSpacer(gui.guiHelper.SPACE_BETWEEN_VERTICAL_DIALOG_ITEMS)

		self.tree = wx.TreeCtrl(self, size=wx.Size(500, 600), style=wx.TR_HAS_BUTTONS | wx.TR_HIDE_ROOT | wx.TR_LINES_AT_ROOT | wx.TR_SINGLE | wx.TR_EDIT_LABELS)
		self.tree.Bind(wx.EVT_SET_FOCUS, self.onTreeSetFocus)
		self.tree.Bind(wx.EVT_CHAR, self.onTreeChar)
		self.treeRoot = self.tree.AddRoot("root")
		contentsSizer.Add(self.tree,flag=wx.EXPAND)
		contentsSizer.AddSpacer(gui.guiHelper.SPACE_BETWEEN_VERTICAL_DIALOG_ITEMS)

		# Translators: The label of an editable text field to filter the elements
		# in the browse mode Elements List dialog.
		filterText = NVDAString("Filter b&y:")
		labeledCtrl = gui.guiHelper.LabeledControlHelper(self, filterText, wx.TextCtrl)
		self.filterEdit = labeledCtrl.control
		self.filterEdit.Bind(wx.EVT_TEXT, self.onFilterEditTextChange)
		contentsSizer.Add(labeledCtrl.sizer)
		contentsSizer.AddSpacer(gui.guiHelper.SPACE_BETWEEN_VERTICAL_DIALOG_ITEMS)
		
		bHelper = gui.guiHelper.ButtonHelper(wx.HORIZONTAL)
		# Translators: The label of a button to activate an element
		# in the browse mode Elements List dialog.
		self.activateButton = bHelper.addButton(self, label= NVDAString("&Activate"))
		self.activateButton.Bind(wx.EVT_BUTTON, lambda evt: self.onAction(True))
		
		# Translators: The label of a button to move to an element
		# in the browse mode Elements List dialog.
		self.moveButton = bHelper.addButton(self, label= NVDAString("&Move to"))
		self.moveButton.Bind(wx.EVT_BUTTON, lambda evt: self.onAction(False))
		bHelper.addButton(self, id=wx.ID_CANCEL)

		contentsSizer.Add(bHelper.sizer, flag=wx.ALIGN_RIGHT)
		mainSizer.Add(contentsSizer, border=gui.guiHelper.BORDER_FOR_DIALOGS, flag=wx.ALL)
		mainSizer.Fit(self)
		self.SetSizer(mainSizer)

		self.tree.SetFocus()
		self.initElementType(self.ELEMENT_TYPES[self.lastSelectedElementType][0])
		self.CentreOnScreen()
Exemplo n.º 3
0
 def doGui(self):
     mainSizer = wx.BoxSizer(wx.VERTICAL)
     sHelper = guiHelper.BoxSizerHelper(self, orientation=wx.VERTICAL)
     # the text control
     tcLabel = sHelper.addItem(
         wx.StaticText(self, label=self.informationLabel))
     self.tc = sHelper.addItem(
         wx.TextCtrl(self,
                     id=wx.ID_ANY,
                     style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH,
                     size=(1000, 600)))
     self.tc.AppendText(self.information)
     self.tc.SetInsertionPoint(0)
     # the buttons
     bHelper = sHelper.addDialogDismissButtons(
         guiHelper.ButtonHelper(wx.HORIZONTAL))
     # Translators: label of copy to clipboard button
     copyToClipboardButton = bHelper.addButton(
         self, id=wx.ID_ANY, label=_("Co&py to Clipboard"))
     closeButton = bHelper.addButton(self,
                                     id=wx.ID_CLOSE,
                                     label=NVDAString("&Close"))
     mainSizer.Add(sHelper.sizer,
                   border=guiHelper.BORDER_FOR_DIALOGS,
                   flag=wx.ALL)
     mainSizer.Fit(self)
     self.SetSizer(mainSizer)
     # events
     copyToClipboardButton.Bind(wx.EVT_BUTTON, self.onCopyToClipboardButton)
     closeButton.Bind(wx.EVT_BUTTON, lambda evt: self.Destroy())
     self.tc.SetFocus()
     self.SetEscapeId(wx.ID_CLOSE)
Exemplo n.º 4
0
 def script_reportCurrentComment(self, gesture):
     caretInfo = self.makeTextInfo(textInfos.POSITION_CARET)
     caretInfo.expand(textInfos.UNIT_CHARACTER)
     val = caretInfo._rangeObj.getAttributeValue(
         UIAHandler.UIA_AnnotationObjectsAttributeId)
     if not val:
         return
     try:
         UIAElementArray = val.QueryInterface(
             UIAHandler.IUIAutomationElementArray)
     except COMError:
         return
     for index in range(UIAElementArray.length):
         UIAElement = UIAElementArray.getElement(index)
         UIAElement = UIAElement.buildUpdatedCache(
             UIAHandler.handler.baseCacheRequest)
         obj = UIA(UIAElement=UIAElement)
         if not obj.parent or obj.parent.name != NVDAString('Comment'):
             continue
         comment = obj.makeTextInfo(textInfos.POSITION_ALL).text
         dateObj = obj.previous
         date = dateObj.name
         authorObj = dateObj.previous
         author = authorObj.name
         # Translators: The message reported for a comment in Microsoft Word
         ui.message(
             _("{comment} by {author} on {date}").format(comment=comment,
                                                         date=date,
                                                         author=author))
         return
 def _quickNavScript(self, gesture, itemType, direction, errorMessage,
                     readUnit):
     if itemType == "notLinkBlock":
         iterFactory = self._iterNotLinkBlock
     else:
         iterFactory = lambda direction, info: self._iterNodesByType(  # noqa:E731
             itemType, direction, info)
     info = self.selection
     try:
         item = next(iterFactory(direction, info))
     except NotImplementedError:
         # Translators: a message when a particular quick nav command
         # is not supported in the current document.
         ui.message(NVDAString("Not supported in this document"))
         return
     except StopIteration:
         if not _addonConfigManager.toggleLoopInNavigationModeOption(False):
             ui.message(errorMessage)
             return
         # return to the top or bottom of page and continue search
         if direction == "previous":
             info = api.getReviewPosition().obj.makeTextInfo(
                 textInfos.POSITION_LAST)
             self._set_selection(info, reason="quickNav")
             # Translators: message to the user which indicates the return
             # to the bottom of the page.
             msg = _("Return to bottom of page")
         else:
             info = None
             # Translators: message to user which indicates the return
             # to the top of the page.
             msg = _("Return to top of page")
         try:
             item = next(iterFactory(direction, info))
         except:  # noqa:E722
             ui.message(errorMessage)
             return
         ui.message(msg)
         winsound.PlaySound("default", 1)
     # #8831: Report before moving because moving might change the focus, which
     # might mutate the document, potentially invalidating info if it is
     # offset-based.
     if not gesture or not willSayAllResume(gesture):
         item.report(readUnit=readUnit)
     item.moveTo()
Exemplo n.º 6
0
    def onVoiceInformationButton(self, evt):
        def boolToText(val):
            return _("yes") if val else _("no")

        def punctuationLevelToText(level):
            return characterProcessing.SPEECH_SYMBOL_LEVEL_LABELS[int(level)]

        NVDASpeechSettingsInfos = [
            ("Automatic language switching (when supported)", boolToText),
            ("Automatic dialect switching (when supported)", boolToText),
            ("Punctuation/symbol level", punctuationLevelToText),
            ("Trust voice's language when processing characters and symbols",
             boolToText),  # noqa:E501
            ("Include Unicode Consortium data (including emoji) when processing characters and symbols",
             boolToText),  # noqa:E501
        ]
        NVDASpeechManySettingsInfos = [
            ("Capital pitch change percentage", None),
            ("Say &cap before capitals", boolToText),
            ("&Beep for capitals", boolToText),
            ("Use &spelling functionality if supported", boolToText),
        ]
        autoReadingSynth = _addonConfigManager.getAutoReadingSynthSettings()
        if autoReadingSynth is None:
            # Translators: message to user to report no automatic reading voice.
            speech.speakMessage(_("No voice recorded for automatic reading"))
            return
        autoReadingSynthName = autoReadingSynth.get("synthName")
        textList = []
        textList.append(_("Synthetizer: %s") % autoReadingSynthName)
        synthSpeechSettings = autoReadingSynth[SCT_Speech]
        synthDisplayInfos = autoReadingSynth["SynthDisplayInfos"]
        textList.append(
            _("Output device: %s") % synthSpeechSettings["outputDevice"])
        for i in synthDisplayInfos:
            item = synthDisplayInfos[i]
            textList.append("%s: %s" % (item[0], item[1]))

        for setting in NVDASpeechSettings:
            val = synthSpeechSettings[setting]
            index = NVDASpeechSettings.index(setting)
            (name, f) = NVDASpeechSettingsInfos[index]
            if f is not None:
                val = f(val)
            name = NVDAString(name).replace("&", "")
            textList.append("%s: %s" % (name, val))
        for setting in NVDASpeechManySettings:
            val = synthSpeechSettings[SCT_Many][setting]
            if setting in synthSpeechSettings:
                val = synthSpeechSettings[setting]
            else:
                val = synthSpeechSettings[SCT_Many][setting]
            index = NVDASpeechManySettings.index(setting)
            (name, f) = NVDASpeechManySettingsInfos[index]
            if f is not None:
                val = f(val)
            name = NVDAString(name).replace("&", "")
            textList.append("%s: %s" % (name, val))

        # Translators: this is the title of informationdialog box


# to show voice profile informations.
        dialogTitle = _("Voice settings for automatic reading")
        infos = "\r\n".join(textList)
        InformationDialog.run(None, dialogTitle, infos)
Exemplo n.º 7
0
class UIAWordDocument(ww_wordDocumentBase.WordDocument,
                      NVDAObjects.UIA.wordDocument.WordDocument):
    treeInterceptorClass = UIAWordBrowseModeDocument
    shouldCreateTreeInterceptor = False
    announceEntireNewLine = True
    TextInfo = UIAWordDocumentTextInfo
    # Microsoft Word duplicates the full title of the document on this control, which is redundant as it appears in the title of the app itself.
    name = u""

    def initOverlayClass(self):
        printDebug("UIAWordDocument InitOverlayClass")
        # textInfo.UNIT_SENTENCE does not exist for UIA,
        # so unbind next and previous sentence script
        self.removeGestureBinding("kb:alt+upArrow")
        self.removeGestureBinding("kb:alt+downArrow")

    # part of code from WordDocument class of IAccessible.winword file
    def populateHeaderCellTrackerFromHeaderRows(self, headerCellTracker,
                                                table):
        rows = table.rows
        numHeaderRows = 0
        for rowIndex in range(rows.count):
            try:
                row = rows.item(rowIndex + 1)
            except COMError:
                break
            try:
                headingFormat = row.headingFormat
            except (COMError, AttributeError, NameError):
                headingFormat = 0
            if headingFormat == -1:  # is a header row
                numHeaderRows += 1
            else:
                break
        if numHeaderRows > 0:
            headerCellTracker.addHeaderCellInfo(rowNumber=1,
                                                columnNumber=1,
                                                rowSpan=numHeaderRows,
                                                isColumnHeader=True,
                                                isRowHeader=False)

    def populateHeaderCellTrackerFromBookmarks(self, headerCellTracker,
                                               bookmarks):
        for x in bookmarks:
            name = x.name
            lowerName = name.lower()
            isColumnHeader = isRowHeader = False
            if lowerName.startswith('title'):
                isColumnHeader = isRowHeader = True
            elif lowerName.startswith('columntitle'):
                isColumnHeader = True
            elif lowerName.startswith('rowtitle'):
                isRowHeader = True
            else:
                continue
            try:
                headerCell = x.range.cells.item(1)
            except COMError:
                continue
            headerCellTracker.addHeaderCellInfo(
                rowNumber=headerCell.rowIndex,
                columnNumber=headerCell.columnIndex,
                name=name,
                isColumnHeader=isColumnHeader,
                isRowHeader=isRowHeader)

    _curHeaderCellTrackerTable = None
    _curHeaderCellTracker = None

    def getHeaderCellTrackerForTable(self, table):
        tableRange = table.range
        # Sometimes there is a valid reference in _curHeaderCellTrackerTable,
        # but we get a COMError when accessing the range (#6827)
        try:
            tableRangesEqual = tableRange.isEqual(
                self._curHeaderCellTrackerTable.range)
        except (COMError, AttributeError):
            tableRangesEqual = False
        if not tableRangesEqual:
            self._curHeaderCellTracker = HeaderCellTracker()
            self.populateHeaderCellTrackerFromBookmarks(
                self._curHeaderCellTracker, tableRange.bookmarks)
            self.populateHeaderCellTrackerFromHeaderRows(
                self._curHeaderCellTracker, table)
            self._curHeaderCellTrackerTable = table
        return self._curHeaderCellTracker

    def setAsHeaderCell(self, cell, isColumnHeader=False, isRowHeader=False):
        rowNumber = cell.rowIndex
        columnNumber = cell.columnIndex
        headerCellTracker = self.getHeaderCellTrackerForTable(
            cell.range.tables[1])
        oldInfo = headerCellTracker.getHeaderCellInfoAt(
            rowNumber, columnNumber)
        if oldInfo:
            if isColumnHeader and not oldInfo.isColumnHeader:
                oldInfo.isColumnHeader = True
            elif isRowHeader and not oldInfo.isRowHeader:
                oldInfo.isRowHeader = True
            else:
                return False
            isColumnHeader = oldInfo.isColumnHeader
            isRowHeader = oldInfo.isRowHeader
        if isColumnHeader and isRowHeader:
            name = "Title_"
        elif isRowHeader:
            name = "RowTitle_"
        elif isColumnHeader:
            name = "ColumnTitle_"
        else:
            raise ValueError(
                "One or both of isColumnHeader or isRowHeader must be True")
        name += uuid.uuid4().hex
        if oldInfo:
            self.WinwordDocumentObject.bookmarks[oldInfo.name].delete()
            oldInfo.name = name
        else:
            headerCellTracker.addHeaderCellInfo(rowNumber=rowNumber,
                                                columnNumber=columnNumber,
                                                name=name,
                                                isColumnHeader=isColumnHeader,
                                                isRowHeader=isRowHeader)
        self.WinwordDocumentObject.bookmarks.add(name, cell.range)
        return True

    def forgetHeaderCell(self, cell, isColumnHeader=False, isRowHeader=False):
        rowNumber = cell.rowIndex
        columnNumber = cell.columnIndex
        if not isColumnHeader and not isRowHeader:
            return False
        headerCellTracker = self.getHeaderCellTrackerForTable(
            cell.range.tables[1])
        info = headerCellTracker.getHeaderCellInfoAt(rowNumber, columnNumber)
        if not info or not hasattr(info, 'name'):
            return False
        if isColumnHeader and info.isColumnHeader:
            info.isColumnHeader = False
        elif isRowHeader and info.isRowHeader:
            info.isRowHeader = False
        else:
            return False
        headerCellTracker.removeHeaderCellInfo(info)
        self.WinwordDocumentObject.bookmarks(info.name).delete()
        if info.isColumnHeader or info.isRowHeader:
            self.setAsHeaderCell(cell,
                                 isColumnHeader=info.isColumnHeader,
                                 isRowHeader=info.isRowHeader)
        return True

    def fetchAssociatedHeaderCellText(self, cell, columnHeader=False):
        table = cell.range.tables[1]
        rowNumber = cell.rowIndex
        columnNumber = cell.columnIndex
        headerCellTracker = self.getHeaderCellTrackerForTable(table)
        for info in headerCellTracker.iterPossibleHeaderCellInfosFor(
                rowNumber, columnNumber, columnHeader=columnHeader):
            textList = []
            if columnHeader:
                for headerRowNumber in range(info.rowNumber,
                                             info.rowNumber + info.rowSpan):
                    tempColumnNumber = columnNumber
                    while tempColumnNumber >= 1:
                        try:
                            headerCell = table.cell(headerRowNumber,
                                                    tempColumnNumber)
                        except COMError:
                            tempColumnNumber -= 1
                            continue
                        break
                    textList.append(headerCell.range.text)
            else:
                for headerColumnNumber in range(
                        info.columnNumber, info.columnNumber + info.colSpan):
                    tempRowNumber = rowNumber
                    while tempRowNumber >= 1:
                        try:
                            headerCell = table.cell(tempRowNumber,
                                                    headerColumnNumber)
                        except COMError:
                            tempRowNumber -= 1
                            continue
                        break
                    textList.append(headerCell.range.text)
            text = " ".join(textList)
            if text:
                return text

    #  end  of code from WordDocument class of IAccessible.winword file
    # to fix bug of NVDA script: "Comment" must be in Word language.
    # we suppose that NVDA and Word are in same language.
    def script_reportCurrentComment(self, gesture):
        caretInfo = self.makeTextInfo(textInfos.POSITION_CARET)
        caretInfo.expand(textInfos.UNIT_CHARACTER)
        val = caretInfo._rangeObj.getAttributeValue(
            UIAHandler.UIA_AnnotationObjectsAttributeId)
        if not val:
            return
        try:
            UIAElementArray = val.QueryInterface(
                UIAHandler.IUIAutomationElementArray)
        except COMError:
            return
        for index in range(UIAElementArray.length):
            UIAElement = UIAElementArray.getElement(index)
            UIAElement = UIAElement.buildUpdatedCache(
                UIAHandler.handler.baseCacheRequest)
            obj = UIA(UIAElement=UIAElement)
            if not obj.parent or obj.parent.name != NVDAString('Comment'):
                continue
            comment = obj.makeTextInfo(textInfos.POSITION_ALL).text
            dateObj = obj.previous
            date = dateObj.name
            authorObj = dateObj.previous
            author = authorObj.name
            # Translators: The message reported for a comment in Microsoft Word
            ui.message(
                _("{comment} by {author} on {date}").format(comment=comment,
                                                            date=date,
                                                            author=author))
            return

    # Translators: a description for a script
    script_reportCurrentComment.__doc__ = NVDAString(
        "Reports the text of the comment where the System caret is located.")