Example #1
0
    async def __readAndPrintStream(self, sr: asyncio.StreamReader,
                                   text_cursor: QTextCursor):
        leftover_data = bytearray()
        while not sr.at_eof() or len(leftover_data) > 0:
            separator_encountered = False
            meaningful_data = None
            cr_found = False
            lf_found = False
            while not separator_encountered:
                leftover_data += await sr.read(64)
                separator_index = -1
                for index, b in enumerate(leftover_data):
                    if b == ord(b'\r'):
                        separator_index = index
                        cr_found = True
                        break
                    elif b == ord(b'\n'):
                        separator_index = index
                        lf_found = True
                        break
                if separator_index != -1:
                    separator_encountered = True
                    meaningful_data = leftover_data[0:separator_index]
                    leftover_data = leftover_data[separator_index + 1:]
                else:
                    leftover_data += leftover_data[separator_index + 1:]

            text = meaningful_data.decode(
            ) if meaningful_data is not None else ''

            text_cursor.beginEditBlock()

            if cr_found:
                text_cursor.movePosition(QTextCursor.StartOfLine)
                text_cursor.insertText(text)
                i = 1
                count = len(text)
                while i <= count:
                    text_cursor.deleteChar()
                    i += 1
            elif lf_found:
                text_cursor.insertText(text + '\n')
            else:
                text_cursor.insertText(text)

            text_cursor.endEditBlock()
            self.__ui.terminalLogWindow.ensureCursorVisible()
 def indent_line(self, line_no, indent_length):
     block = self._get_block(line_no)
     cursor = QTextCursor(block)
     cursor.joinPreviousEditBlock()
     cursor.movePosition(QTextCursor.StartOfBlock, QTextCursor.MoveAnchor)
     if indent_length < 0:
         for i in range(-indent_length):
             cursor.deleteChar()
     else:
         cursor.insertText(" " * indent_length)
     if indent_length:
         cursor.movePosition(QTextCursor.StartOfBlock, QTextCursor.MoveAnchor)
         line = unicode(cursor.block().text())
         if len(line) and line[0] == " ":
             cursor.movePosition(QTextCursor.NextWord, QTextCursor.MoveAnchor)
         self.editview.setTextCursor(cursor)
     cursor.endEditBlock()
Example #3
0
 def indent_line(self, line_no, indent_length):
     block = self._get_block(line_no)
     cursor = QTextCursor(block)
     cursor.joinPreviousEditBlock()
     cursor.movePosition(QTextCursor.StartOfBlock, QTextCursor.MoveAnchor)
     if indent_length < 0:
         for i in range(-indent_length):
             cursor.deleteChar()
     else:
         cursor.insertText(" " * indent_length)
     if indent_length:
         cursor.movePosition(QTextCursor.StartOfBlock,
                             QTextCursor.MoveAnchor)
         line = unicode(cursor.block().text())
         if len(line) and line[0] == " ":
             cursor.movePosition(QTextCursor.NextWord,
                                 QTextCursor.MoveAnchor)
         self.editview.setTextCursor(cursor)
     cursor.endEditBlock()
Example #4
0
the_book = mw.open_books[0]
the_doc = the_book.get_edit_model()

# edit data with some >ascii data
test_lines = ['Ōne','twő','thrĕep']
test_data = '\n'.join(test_lines)
the_doc.setPlainText(test_data)
#print('|'+the_doc.full_text()+'|')
#print(the_doc.blockCount())
assert the_doc.blockCount() == 3
assert the_doc.full_text() == test_data
assert the_doc._text is not None
# check that modified signal received
tc = QTextCursor(the_doc)
tc.setPosition(0)
tc.deleteChar()
assert the_doc._text is None
the_doc.undo(tc) # put text back to original

j = 0
for line in the_doc.all_lines():
    assert line == test_lines[j]
    j+= 1
for line in the_doc.z_to_a_lines(1,3):
    j -= 1
    assert line == test_lines[j]
assert j==0
# j now 0, following should detect error, yield nothing
for line in the_doc.a_to_z_lines(-1,2):
    j += 1
assert j==0