'Select line(s) after a mouse press/mouse press drag event'

def select_lines(self, linenumber_pressed, linenumber_released):

    find_block_by_line_number = self.document().findBlockByLineNumber
    move_n_blocks = (linenumber_released - linenumber_pressed)
    start_line = linenumber_pressed
    start_block = find_block_by_line_number((start_line - 1))
    cursor = self.textCursor()
    cursor.setPosition(start_block.position())
    if (move_n_blocks > 0):
        for n in range((abs(move_n_blocks) + 1)):
            cursor.movePosition(cursor.NextBlock, cursor.KeepAnchor)
    else:
        cursor.movePosition(cursor.NextBlock)
        for n in range((abs(move_n_blocks) + 1)):
            cursor.movePosition(cursor.PreviousBlock, cursor.KeepAnchor)
    if (linenumber_released == self.blockCount()):
        cursor.movePosition(cursor.EndOfBlock, cursor.KeepAnchor)
    else:
        cursor.movePosition(cursor.StartOfBlock, cursor.KeepAnchor)
    self.setTextCursor(cursor)
