コード例 #1
0
ファイル: qrview.py プロジェクト: webushka/reduce
 def __positionPair(self,pos):
     cursor = QTextCursor(self.document())
     cursor.setPosition(pos)
     rootFrame = self.document().rootFrame()
     frames = rootFrame.childFrames()
     frame = cursor.currentFrame()
     if frame == rootFrame:
         # pos is outside any group
         return [pos,pos]
     p = frame.parentFrame()
     if p != rootFrame:
         # frame is an input or output frame containing pos
         return [frame.firstPosition(),frame.lastPosition()]
     # frame is a group frame containing pos in a comment position
     localFrames = frame.childFrames()
     inputStart = localFrames[0].firstPosition()
     if pos < inputStart:
         return [frame.firstPosition(),inputStart-1]
     inputEnd = localFrames[0].lastPosition()
     outputStart = localFrames[1].firstPosition()
     if inputEnd < pos and pos < outputStart:
         return [inputEnd+1,outputStart-1]
     outputEnd = localFrames[1].lastPosition()
     if outputEnd < pos:
         return [outputEnd+1,frame.lastPosition()]
     traceLogger.critical("bad position %d (%d %d) (%d %d)" %
                          (pos,
                           ifr.firstPosition(), ifr.lastPosition(),
                           ofr.firstPosition(), ofr.lastPosition()))
     return [-1,-1]
コード例 #2
0
 def __positionPair(self, pos):
     cursor = QTextCursor(self.document())
     cursor.setPosition(pos)
     rootFrame = self.document().rootFrame()
     frames = rootFrame.childFrames()
     frame = cursor.currentFrame()
     if frame == rootFrame:
         # pos is outside any group
         return [pos, pos]
     p = frame.parentFrame()
     if p != rootFrame:
         # frame is an input or output frame containing pos
         return [frame.firstPosition(), frame.lastPosition()]
     # frame is a group frame containing pos in a comment position
     localFrames = frame.childFrames()
     inputStart = localFrames[0].firstPosition()
     if pos < inputStart:
         return [frame.firstPosition(), inputStart - 1]
     inputEnd = localFrames[0].lastPosition()
     outputStart = localFrames[1].firstPosition()
     if inputEnd < pos and pos < outputStart:
         return [inputEnd + 1, outputStart - 1]
     outputEnd = localFrames[1].lastPosition()
     if outputEnd < pos:
         return [outputEnd + 1, frame.lastPosition()]
     traceLogger.critical("bad position %d (%d %d) (%d %d)" %
                          (pos, ifr.firstPosition(), ifr.lastPosition(),
                           ofr.firstPosition(), ofr.lastPosition()))
     return [-1, -1]
コード例 #3
0
 def insertRow(self, row):
     self.insertingFrames = True
     document = self.document()
     rootFrame = document.rootFrame()
     rows = rootFrame.childFrames()
     if row > len(rows):
         traceLogger.critical("invalid row %d > %d" % (row, len(rows)))
         row = len(rows)
     if row == len(rows):
         cursor = QTextCursor(document)
         cursor.movePosition(QTextCursor.End)
     elif rows:
         cursor = QTextCursor(rows[row].firstCursorPosition())
         cursor.movePosition(QTextCursor.PreviousBlock)
     cursor.insertFrame(QtReduceRowFormat())
     cursor.insertFrame(QtReduceInput().frameFormat)
     position = cursor.position()
     cursor.clearSelection()
     cursor.setBlockFormat(QtReduceInput().blockFormat)
     cursor.setBlockCharFormat(QtReduceInput().charFormat)
     cursor.movePosition(QTextCursor.NextBlock)
     cursor.insertFrame(QtReduceNoResult().frameFormat)
     cursor.setBlockFormat(QtReduceNoResult().blockFormat)
     cursor.setBlockCharFormat(QtReduceNoResult().charFormat)
     cursor.insertText(QtReduceFrameView.NotEvaluated)
     cursor.setPosition(position)
     self.insertingFrames = False
コード例 #4
0
ファイル: qrview.py プロジェクト: webushka/reduce
 def insertRow(self,row):
     self.insertingFrames = True
     document = self.document()
     rootFrame = document.rootFrame()
     rows = rootFrame.childFrames()
     if row > len(rows):
         traceLogger.critical("invalid row %d > %d" % (row,len(rows)))
         row = len(rows)
     if row == len(rows):
         cursor = QTextCursor(document)
         cursor.movePosition(QTextCursor.End)
     elif rows:
         cursor = QTextCursor(rows[row].firstCursorPosition())
         cursor.movePosition(QTextCursor.PreviousBlock)
     cursor.insertFrame(QtReduceRowFormat())
     cursor.insertFrame(QtReduceInput().frameFormat)
     position = cursor.position()
     cursor.clearSelection()
     cursor.setBlockFormat(QtReduceInput().blockFormat)
     cursor.setBlockCharFormat(QtReduceInput().charFormat)
     cursor.movePosition(QTextCursor.NextBlock)
     cursor.insertFrame(QtReduceNoResult().frameFormat)
     cursor.setBlockFormat(QtReduceNoResult().blockFormat)
     cursor.setBlockCharFormat(QtReduceNoResult().charFormat)
     cursor.insertText(QtReduceFrameView.NotEvaluated)
     cursor.setPosition(position)
     self.insertingFrames = False
コード例 #5
0
 def markSentence(self):
     """Mark sentence with marker if marker ir checked."""
     cursor = QTextCursor(self.sentence_mw.ui.textEditSentence.document())
     begin = self.sentence_mw.ui.textEditSentence.textCursor(
     ).selectionStart()
     end = self.sentence_mw.ui.textEditSentence.textCursor().selectionEnd()
     marker = self.preferences['marker']
     cursor.setPosition(begin, QTextCursor.MoveAnchor)
     cursor.insertText(marker[0])
     cursor.setPosition(end + 1, QTextCursor.MoveAnchor)
     cursor.insertText(marker[1])
コード例 #6
0
 def currentField(self, row):
     rows = self.document().rootFrame().childFrames()
     if row >= len(rows):
         traceLogger.critical("invalid row %d > %d" % (row, len(rows) - 1))
         row = len(rows)
     inputFrame = rows[row].childFrames()[0]
     cursor = QTextCursor(inputFrame)
     cursor.setPosition(inputFrame.lastPosition(), QTextCursor.KeepAnchor)
     command = cursor.selectedText()
     command = command.replace(u'\u2028', u'\n')
     command = command.replace(u'\u2029', u'\n')
     if command != '' and not command[-1] in [';', '$']:
         command += ';'
     return command
コード例 #7
0
ファイル: qrview.py プロジェクト: webushka/reduce
 def currentField(self,row):
     rows = self.document().rootFrame().childFrames()
     if row >= len(rows):
         traceLogger.critical("invalid row %d > %d" % (row,len(rows)-1))
         row = len(rows)
     inputFrame = rows[row].childFrames()[0]
     cursor = QTextCursor(inputFrame)
     cursor.setPosition(inputFrame.lastPosition(),QTextCursor.KeepAnchor)
     command = cursor.selectedText()
     command = command.replace(u'\u2028',u'\n')
     command = command.replace(u'\u2029',u'\n')
     if command != '' and not command[-1] in [';','$']:
         command += ';'
     return command
コード例 #8
0
ファイル: console.py プロジェクト: harry159821/cinemol
 def cursor_is_in_editing_region(self, cursor):
     # Want to be to the right of the prompt...
     if cursor.positionInBlock() < len(self.prompt):
         return False
     # ... and in the final line.
     if cursor.blockNumber() != self.te.blockCount() - 1:
         return False
     if cursor.anchor() != cursor.position():
         # Anchor might be outside of editing region
         anchorCursor = QTextCursor(cursor)
         anchorCursor.setPosition(cursor.anchor())
         if anchorCursor.positionInBlock() < len(self.prompt):
             return False
         if anchorCursor.blockNumber() != self.te.blockCount() - 1:
             return False
     return True
コード例 #9
0
ファイル: code_edit.py プロジェクト: hofoen/pcef-core
def cursorForPosition(codeEdit, line, column, selectEndOfLine=False,
                      selection=None, selectWordUnderCursor=False):
    """
    Return a QTextCursor set to line and column with the specified selection
    :param line:
    :param column:
    """
    tc = QTextCursor(codeEdit.document())
    tc.movePosition(QTextCursor.Start, QTextCursor.MoveAnchor)
    tc.movePosition(QTextCursor.Down, QTextCursor.MoveAnchor, line - 1)
    tc.setPosition(tc.position() + column - 1)
    if selectEndOfLine is True:
        tc.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor)
    elif isinstance(selection, int):
        tc.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor, selection)
    elif selectWordUnderCursor is True:
        tc.select(QTextCursor.WordUnderCursor)
    codeEdit.setTextCursor(tc)
    return tc
コード例 #10
0
ファイル: code_edit.py プロジェクト: hofoen/pcef-core
    def __init__(self, cursorOrBlockOrDoc, startPos=None, endPos=None,
                 draw_order=0, tooltip=None):
        """
        Creates a text decoration

        :param cursorOrBlockOrDoc: Selection
        :type cursorOrBlockOrDoc: QTextCursor or QTextBlock or QTextDocument

        :param startPos: Selection start pos

        :param endPos: Selection end pos

        .. note:: Use the cursor selection if startPos and endPos are none.
        """
        self.draw_order = draw_order
        self.tooltip = tooltip
        QTextEdit.ExtraSelection.__init__(self)
        cursor = QTextCursor(cursorOrBlockOrDoc)
        if startPos is not None:
            cursor.setPosition(startPos)
        if endPos is not None:
            cursor.setPosition(endPos, QTextCursor.KeepAnchor)
        self.cursor = cursor
コード例 #11
0
 def goToLine(self, line):
     block = self.editor.document().findBlockByLNumber(line)
     cursor = QTextCursor(self.editor.document())
     cursor.setPosition(block.position())
     self.editor.setTextCursor(cursor)