Ejemplo n.º 1
0
    def insertAtCursor( self, textDict ):
        """
        Inserts the given text at the cursor position without
        replacing anything.
        Returns a boolean telling whether insertion succeeded.
        """

        # LONGTERM TODO:
        # find a better way to do this? It's currently not really inserting
        # at cursor, it's replacing text selection with text selection + new
        # text.  This means that, for instance, if I do an insert when
        # the cursor is at the beginning of the selection, my new text
        # will actually appear at the end of the selection.
        #
        # If there were a programmatic way to deselect the selection without
        # changing the text or moving the cursor, we could do that, then
        # issue paste... but I don't know of a way to do this.

        # Try to do a copy:
        ClipboardBackend.prepareForClipboardToChange()
        self.simulateCopyKeystroke()
        changed = ClipboardBackend.waitForClipboardToChange( STANDARD_WAIT_TIME )

        if not changed:
            # There was no selection to copy; just paste the text:
            return self._pasteText( textDict )
        else:
            # There was an existing selection: Concatenate it with
            # the new text:
            currentText = self._getClipboardText()
            newText = _concatenate( currentText, textDict )
            return self._pasteText( newText )
Ejemplo n.º 2
0
    def replaceSelection( self, textDict ):
        """
        Replace the selected text with the given text by first
        cutting and discarding the selected text, then pasting in
        the new text.
        Returns a boolean telling whether replacement succeeded.
        """
        ClipboardBackend.prepareForClipboardToChange()
        self.simulateCutKeystroke()
        ClipboardBackend.waitForClipboardToChange( STANDARD_WAIT_TIME )

        return self._pasteText( textDict )
Ejemplo n.º 3
0
    def getSelection( self ):
        """
        Returns a textDict ( with, potentially, "text" and "html" keys )
        containing the text that is selected in the application.
        Attempts to do so without clobbering the clipboard.
        """

        ContextUtils.clearClipboard()

        ClipboardBackend.prepareForClipboardToChange()
        self.simulateCopyKeystroke()
        ClipboardBackend.waitForClipboardToChange( STANDARD_WAIT_TIME )

        result = self._getClipboardText()
        return result
Ejemplo n.º 4
0
    def getSelectedFiles(self):
        """
        Returns a list of the names of the files that are selected.
        Each element of the list is an absolute path.  If no files are
        selected, it returns None (not an empty list).
        """

        ClipboardBackend.prepareForClipboardToChange()
        ContextUtils.typeCommandKey("C")
        success = ClipboardBackend.waitForClipboardToChange(
            FILE_COPY_WAIT_TIME)

        if not success:
            return None

        return self.__getHdropFiles()
Ejemplo n.º 5
0
    def getSelectedFiles( self ):
        """
        Returns a list of the names of the files that are selected.
        Each element of the list is an absolute path.  If no files are
        selected, it returns None (not an empty list).
        """

        ClipboardBackend.prepareForClipboardToChange()
        ContextUtils.typeCommandKey( "C" )
        success = ClipboardBackend.waitForClipboardToChange(
            FILE_COPY_WAIT_TIME
            )

        if not success:
            return None

        return self.__getHdropFiles()