def getCollectionInRange(self, theRange):
        printDebug("Collection getCollectionInRange: %s" % theRange)
        collection = []
        for item in self._propertyName:
            (property, elementClass) = item
            col = getattr(theRange, property)
            try:
                col = getattr(theRange, property)
            except:
                # no collection for the range
                printDebug("No collection for the range")
                continue

            #try:
            if True:
                count = col.count
                startTime = time.time()
                for i in range(1, count + 1):
                    startTime = self.sayPercentage(i, count, startTime)
                    # stopped by user?
                    if self.parent and self.parent.canceled:
                        return []
                    collection.append((col[i], elementClass))
            #except:
            else:
                speech.speakMessage(
                    _("Sorry, There are too  many elements to be treated "))
                speech.speakMessage(_("Select smaller part of document"))
                time.sleep(3.0)
                return None

        return collection
 def event_foreground(self, obj, nextHandler):
     printDebug("word: event_foreground")
     if obj.windowClassName == "OpusApp":
         self.opusApp = obj
     if obj.windowClassName in ["_WwG"]:
         maximizeWindow(obj.windowHandle)
     nextHandler()
Exemplo n.º 3
0
 def onActivate(self, evt):
     printDebug("collectInformation active: %s" % evt.GetActive())
     if evt.GetActive():
         self.isActive = True
     else:
         self.isActive = False
     evt.Skip()
    def getElementsInCollection(self):
        printDebug("Collection getElementsInCollection")
        objectsInCollection = self.getCollection()
        if objectsInCollection == None:
            return None

        elements = []
        startTime = time.time()
        count = len(objectsInCollection)
        for item in objectsInCollection:
            startTime = self.sayPercentage(objectsInCollection.index(item),
                                           count, startTime)
            if self.parent and self.parent.canceled:
                return []
            (obj, elementClass) = item
            element = elementClass(self, obj)
            try:
                element = elementClass(self, obj)
                elements.append(element)

            except:
                printDebug(
                    "getElementsInCollection:  except on element = elementClass"
                )
                speech.speakMessage(
                    _("Sorry, There are too  many elements to be treated "))
                time.sleep(2.0)
                return None

        return elements
 def script_makeChoice(
     self,
     gesture,
 ):
     printDebug("_makeChoice")
     stopScriptTimer()
     wx.CallAfter(ww_choice.ChoiceDialog.run, self)
 def script_insertComment(self, gesture):
     printDebug("insert comment")
     stopScriptTimer()
     winwordApplication = self._get_WinwordApplicationObject()
     if winwordApplication:
         wx.CallAfter(ww_comments.insertComment, winwordApplication)
     else:
         log.warning(" No winword application")
 def goTo(self):
     printDebug("ReportDialog goTo")
     index = self.entriesList.GetFocusedItem()
     self.collection[index].goTo()
     wx.CallAfter(self.parent.Close)
     self.Close()
     speech.cancelSpeech()
     oldSpeechMode = speech.speechMode
     speech.speechMode = speech.speechMode_off
     core.callLater(500, self.collectionObject.speakContext, oldSpeechMode)
 def reportElements(self):
     printDebug("Collection reportElement")
     col = self.collection
     if len(col) == 0:
         speech.speakMessage(self.noElementMessage)
         return
     if len(col) > 1:
         speech.speakMessage(
             _("{count} {element}").format(count=len(col),
                                           element=self._name[0]))
     for element in col:
         element.reportText()
 def __init__(self, parent, collectionObject):
     printDebug("ReportDialog init: collectionObject = %s" %
                collectionObject)
     self.parent = parent
     super(ReportDialog, self).__init__(parent,
                                        title=collectionObject.title)
     self.timer = None
     self.collectionObject = collectionObject
     self.wordApp = collectionObject.wordApp
     self.collection = collectionObject.collection[:]
     self.initializeGUI()
     self.doGUI()
	def sayText (self, wordDocument, columnHeader= None):
		printDebug ("cell setText: columnHeader= %s"%columnHeader)
		headerText = ""
		reportTableHeadersFlag = config.conf['documentFormatting']["reportTableHeaders"]
		if reportTableHeadersFlag:
			if columnHeader is not None:
				headerText=wordDocument.fetchAssociatedHeaderCellText(self.obj,columnHeader)
			else:
				columnHeaderText=wordDocument.fetchAssociatedHeaderCellText(self.obj,columnHeader = True)
				rowHeaderText=wordDocument.fetchAssociatedHeaderCellText(self.obj,columnHeader = False)
				headerText = "%s, %s"%(rowHeaderText, columnHeaderText)
			ui.message(headerText)
		text = self.obj.Range.Text
		text = text[:-2]
		if text != "":
			ui.message(text)
		else:
			ui.message(_("empty"))
	def _getCellInCollection(self, cells, position, index):
		printDebug ("_getCellInCollection: position= %s"%position)
		try:
			if position == "previous":
				cell = cells[index-1 if index>0 else None]
			elif position == "next":
				cell = cells[index+1 if index+1 <len(cells) else None]
			elif position == "first":
				cell = cells[0]
			elif position == "last":
				cell = cells[-1]
			elif position == "current":
				cell = cells[index]
			else:
				# error
				cell = None
		except:
			cell = None
		return cell
    def __init__(self, parent, obj):
        printDebug("Collection init: rangeType = %s" % self.rangeType)
        Collection._instance = self
        self.wordApp = obj._get_WinwordApplicationObject()
        self.doc = self.wordApp.ActiveDocument
        self.selection = self.wordApp.Selection

        noElementMessages = {
            "focus":
            _("%s at cursor's position"),
            "selection":
            _("%s in the selection"),
            "document":
            _("%s in the document"),
            "page":
            _("%s in the page"),
            "startToFocus":
            _("%s between  start of document and cursor's position"),
            "focusToEnd":
            _("%s between cursor's position and end of document")
        }

        (singular, plural) = self._name
        titles = {
            "focus":
            _("%s at cursor's position") % singular,
            "selection":
            _("%s in the selection") % plural,
            "document":
            _("%s in the document") % plural,
            "page":
            _("%s in the page") % plural,
            "startToFocus":
            _("%s  between document's start  and cursor's position") % plural,
            "focusToEnd":
            _("%s between cursor's position and document's end") % plural
        }

        self.noElementMessage = noElementMessages[
            self.rangeType] % self.noElement
        self.title = titles[self.rangeType]
        self.parent = parent
        self.collection = self.getElementsInCollection()
	def sayElement(self, elementType, position, currentCell, reportAllCells = False):
		printDebug ("sayElement: %s, %s, reportAllCells = %s"%(elementType, position, reportAllCells))
		if elementType == "row":
			self.sayRow(self._rowPositions[position], currentCell)
		elif elementType == "column":
			self.sayColumn(self._columnPositions[position], currentCell)
		elif elementType == "cell":
			if reportAllCells:
				if position in self._rowPositions:
					pos = self._rowPositions[position]
					self.sayColumn(pos, currentCell)
				elif position in self._columnPositions:
					pos = self._columnPositions[position]
					self.sayRow(pos, currentCell)
			else:
				self.sayCell(position, currentCell)
		else:
			# error
			log.error("SayElement invalid parameters %s" %type)
    def _reportTableElement(self,
                            elementType="cell",
                            position="current",
                            reportAllCells=None):
        printDebug("reportTableElement: elementType = %s,position= %s" %
                   (elementType, position))
        stopScriptTimer()
        if not self.inTable(True):
            return

        self.doc = self.WinwordDocumentObject
        (start, end) = (self.WinwordSelectionObject.Start,
                        self.WinwordSelectionObject.End)
        r = self.doc.range(start, start)
        cell = ww_tables.Cell(self, r.Cells[0])
        table = ww_tables.Table(self, r.Tables[0])
        table.sayElement(
            elementType, position, cell, self.appModule.reportAllCellsFlag
            if reportAllCells is None else reportAllCells)
    def script_reportCurrentEndNoteOrFootNote(self, gesture):
        stopScriptTimer()
        info = self.makeTextInfo(textInfos.POSITION_CARET)
        info.expand(textInfos.UNIT_CHARACTER)
        fields = info.getTextWithFields(formatConfig={'reportComments': True})
        for field in reversed(fields):
            if not (isinstance(field, textInfos.FieldCommand)
                    and isinstance(field.field, textInfos.ControlField)):
                continue
            role = field.field.get('role')
            start = self.WinwordDocumentObject.content.start
            end = self.WinwordDocumentObject.content.end
            range = self.WinwordDocumentObject.range(start, end)
            if role == controlTypes.ROLE_FOOTNOTE:
                val = field.field.get('value')
                try:
                    col = range.footNotes
                    text = col[int(val)].range.text
                    if text == None or len(text) == 0:
                        # Translators: message to the user to say  empty .
                        text = _("empty")
                    ui.message(text)
                    return
                except:
                    break
            if role == controlTypes.ROLE_ENDNOTE:
                val = field.field.get('value')
                try:
                    text = range.EndNotes[int(val)].range.text
                    if text == None or len(text) == 0:
                        # Translators: message to the user to say  empty .
                        text = _("empty")
                    ui.message(text)
                    return
                except:
                    printDebug("endnotes")
                    break

                return
        # Translators: a message when there is no endnoe or footnote to report in Microsoft Word.
        ui.message(_("no endnote or footnote"))
    def _updateGestureBinding(self):
        printDebug("updateGestureBinding: %s" % self.appModule.layerMode)
        self._gestureMap.clear()
        self._gestureMap.update(self.postOverlayClassInitGestureMap)
        for script in self._commonGestures:
            gests = self._commonGestures[script]
            if gests is None: continue
            for gest in gests:
                self.bindGesture(gest, script)
        if self.appModule.layerMode:
            gestures = self._layerGestures
            oldGestures = self._baseGestures
            scriptCategory = _scriptCategory + _(" (Table layer mode)")
        else:
            gestures = self._baseGestures
            oldGestures = self._layerGestures
            scriptCategory = _scriptCategory

        for script in gestures:
            gests = gestures.get(script)
            if gests is not None:
                for gest in gests:
                    self.bindGesture(gest, script)

        # remove gest and doc of previous binding
        for script in oldGestures:
            scr = "scrip_%s" % script
            scriptFunc = getattr(self, "script_%s" % script)
            scriptFunc.__func__.__doc__ = None

        # set doc of new scripts
        for script in gestures:
            docScriptName = script.replace("layer_", "")
            scr = "scrip_%s" % script
            doc = "_%s" % docScriptName
            scriptFunc = getattr(self, "script_%s" % script)
            docFunc = getattr(self, doc)
            scriptFunc.__func__.__doc__ = docFunc.__doc__
            scriptFunc.__func__.category = scriptCategory
    def getCollection(self):
        printDebug("Collection getCollection")
        pleaseWait = True
        if self.rangeType == "selection":
            # elements in a selection
            r = self.doc.range(self.selection.Start, self.selection.End)

        elif self.rangeType == "focus":
            if hasattr(self, "reference"):
                r = self.doc.range(self.reference, self.reference + 1)
            else:
                r = self.doc.range(self.selection.Start,
                                   self.selection.Start + 1)

            pleaseWait = False

        elif self.rangeType == "document":
            start = self.doc.Content.Start
            end = self.doc.Content.End
            r = self.doc.range(start, end)
        elif self.rangeType == "startToFocus":
            start = self.doc.Content.Start
            end = self.selection.Start
            r = self.doc.range(start, end)
        elif self.rangeType == "page":
            r = self.doc.Bookmarks("\page").Range

        elif self.rangeType == "focusToEnd":
            start = self.selection.Start
            end = self.doc.Content.End
            r = self.doc.range(start, end)

        if pleaseWait:
            speech.speakMessage(_("Please wait."))
            time.sleep(1.0)

        collection = self.getCollectionInRange(r)
        return collection
 def event_gainFocus(self, obj, nextHandler):
     printDebug("Word: event_gainFocus: %s, %s" %
                (obj.role, obj.windowClassName))
     if not hasattr(self, "WinwordWindowObject"):
         try:
             self.WinwordWindowObject = obj.WinwordWindowObject
             self.WinwordVersion = obj.WinwordVersion
         except:
             pass
     if not self.hasFocus:
         nextHandler()
         return
     if obj.windowClassName == "OpusApp":
         # to suppress double announce of document window title
         return
     #for spelling and grammar ending check window
     if obj.role == controlTypes.ROLE_BUTTON and obj.name.lower() == "ok":
         foreground = api.getForegroundObject()
         if foreground.windowClassName == "#32770" and foreground.name == "Microsoft Word":
             lastChild = foreground.getChild(foreground.childCount - 1)
             if lastChild.windowClassName == "MSOUNISTAT":
                 speech.speakMessage(foreground.description)
     nextHandler()
	def moveToCell(self, position, curCell ):
		(rowIndex, columnIndex) = (curCell.rowIndex, curCell.columnIndex)
		printDebug ("moveToCell: position = %s, rowIndex: %s, columnIndex= %s"%(position, rowIndex, columnIndex))
		if  position in self._rowPositions:
			cells = self._getCellsOfRow(rowIndex)
			newCell = self._getCellInCollection(cells, self._rowPositions[position], self._getCellIndexInCollection(curCell, cells))
			if newCell is None or newCell.columnIndex  == columnIndex:
				ui.message(_("Row's limit"))
				newCell = None
		elif position in self._columnPositions:
			cells = self._getCellsOfColumn(columnIndex)
			newCell = self._getCellInCollection(cells, self._columnPositions[position], self._getCellIndexInCollection(curCell, cells))
			if newCell is None or newCell.rowIndex  == rowIndex:
				ui.message(_("Column's limit"))
				newCell = None
		else:
			# error
			log.warning("moveToCell error: %s, %s"%(type, whichOne))
			return None
		if newCell == None:
			return None
		newCell.goTo()
		return newCell
	def sayCell(self,  position= "current", currentCell = None,columnHeader = None ):
		printDebug ("sayCell: position= %s,   columnHeader = %s, row= %s, column=%s"%(position, columnHeader, currentCell.rowIndex, currentCell.columnIndex))
		newCell = None
		row = None
		if position == "current":
			currentCell.sayText(self.parent, columnHeader)
			return
		
		if position in self._rowPositions:
			cells = self._getCellsOfRow(currentCell.rowIndex)
			row = True
			pos = self._rowPositions[position]
		elif  position in self._columnPositions:
			cells = self._getCellsOfColumn(currentCell.columnIndex)
			row = False
			pos = self._columnPositions[position]
		else:
			#error
			log.error ("error, sayCell invalid parameter %s" %whichOne)
			return
		
		if newCell is None:
			index = self._getCellIndexInCollection(currentCell, cells)
			newCell = self._getCellInCollection(cells, pos, index)
			if newCell is None:
				if row is None:
					pass
				elif row:
					ui.message(_("Row's limit"))
				else:
					ui.message(_("Column's limit"))
				return
			if row is True:
				ui.message(_("column %s") %newCell.columnIndex)
			elif row is False:
				ui.message(_("row %s") %newCell.rowIndex)
			newCell.sayText(self.parent, columnHeader = row if columnHeader is None else columnHeader)
 def goTo(self):
     printDebug("Collection goTo")
     r = self.doc.range(self.start, self.start)
     r.select()
     r.collapse()
 def __init__(self, parent, obj):
     printDebug("CollectionElement init")
     self.parent = parent
     self.doc = parent.doc
     self.obj = obj
Exemplo n.º 23
0
 def onActivate(self, evt):
     printDebug("makeChoice active: %s" % evt.GetActive())
     evt.Skip()
 def initOverlayClass(self):
     printDebug("MainWordDocumentEx InitOverlayClass")
     self.postOverlayClassInitGestureMap = self._gestureMap.copy()
     if self.appModule.layerMode is None:
         self.appModule.layerMode = False
     self._updateGestureBinding()
 def event_focusEntered(self):
     printDebug("MainWordDocumentEx: event_focusEntered")
     super(MainWordDocumentEx, self).event_focusEntered()
 def event_appModule_loseFocus(self):
     printDebug("Word: event_appModuleLoseFocus")
     self.hasFocus = False
 def event_appModule_gainFocus(self):
     printDebug("Word: event_appModuleGainFocus")
     self.hasFocus = True
 def __init__(self, *args, **kwargs):
     printDebug("word appmodule init")
     super(AppModule, self).__init__(*args, **kwargs)
     # configuration load
     self.hasFocus = False
    def _moveToTableElement(self, position="current", reportRow=None):
        printDebug("_moveToTableElement: position= %s, reportRow= %s" %
                   (position, reportRow))
        stopScriptTimer()
        if not self.inTable(True):
            return

        self.doc = self.WinwordDocumentObject
        (start, end) = (self.WinwordSelectionObject.Start,
                        self.WinwordSelectionObject.End)
        r = self.doc.range(start, start)
        cell = ww_tables.Cell(self, r.Cells[0])
        table = ww_tables.Table(self, r.Tables[0])
        cell = table.moveToCell(position, cell)
        if cell is None:
            return
        moveInRow = table.getMoveInRow(position)
        if position == "firstInRow":
            # Translators: a message to say moving to start of row.
            ui.message(
                _("Start of row {0}").format(cell.rowIndex
                                             ) if cell != None else "")
            # Translators: a message to report column number.
            msg = _(" column {0}").format(cell.columnIndex)
        elif position == "lastInRow":
            # Translators: message to say moving to end of row.
            ui.message(
                _("End of row {0}").format(cell.rowIndex
                                           ) if cell != None else "")
            # Translators: message to report row number.
            msg = _(" column {0}").format(cell.columnIndex)
        elif position == "firstInColumn":
            # Translators: message to say moving to start of column.
            ui.message(
                _("Start of column {0}").format(cell.columnIndex
                                                ) if cell != None else "")
            # Translators: message to report row number.
            msg = _(" row {0}").format(cell.rowIndex)
        elif position == "lastInColumn":
            # Translators: message to say moving to end of column
            ui.message(
                _("End of column {0}").format(cell.columnIndex
                                              ) if cell != None else "")
            # Translators: message to report row number.
            msg = _(" row {0}").format(cell.rowIndex)
        else:
            msg = None
            if moveInRow is True:
                # Translators: message to report column number.
                msg = _("column %s") % cell.columnIndex
            elif moveInRow is False:
                # Translators: message to report row number.
                msg = _("row %s") % cell.rowIndex
        info = self.makeTextInfo(textInfos.POSITION_CARET)
        info.updateCaret()
        if moveInRow is not None and (self.appModule.reportAllCellsFlag
                                      or reportRow is not None):
            elementType = "column" if moveInRow else "row"
            table.sayElement(elementType, "current", cell)
            return
        if msg is not None:
            ui.message(msg)
        cell.sayText(self, moveInRow)
 def event_gainFocus(self):
     printDebug("MainWordDocumentEx: event_gainFocus")
     super(MainWordDocumentEx, self).event_gainFocus()
     globalVars.lastWinwordObject = self
     if self.appModule.layerMode:
         speech.speakMessage(_("Table layer mode on"))