'Selects entire lines between start and end line numbers.
This functions apply the selection and returns the text cursor that
contains the selection.
Optionally it is possible to prevent the selection from being applied
on the code editor widget by setting ``apply_selection`` to False.
:param start: Start line number (0 based)
:param end: End line number (0 based). Use -1 to select up to the
end of the document
:param apply_selection: True to apply the selection before returning
the QTextCursor.
:returns: A QTextCursor that holds the requested selection'

def select_lines(self, start=0, end=(-1), apply_selection=True):

    editor = self._editor
    if (end == (-1)):
        end = (self.line_count() - 1)
    if (start < 0):
        start = 0
    text_cursor = self._move_cursor_to(start)
    if (end > start):
        text_cursor.movePosition(text_cursor.Down, text_cursor.KeepAnchor, (end - start))
        text_cursor.movePosition(text_cursor.EndOfLine, text_cursor.KeepAnchor)
    elif (end < start):
        text_cursor.movePosition(text_cursor.EndOfLine, text_cursor.MoveAnchor)
        text_cursor.movePosition(text_cursor.Up, text_cursor.KeepAnchor, (start - end))
        text_cursor.movePosition(text_cursor.StartOfLine, text_cursor.KeepAnchor)
    else:
        text_cursor.movePosition(text_cursor.EndOfLine, text_cursor.KeepAnchor)
    if apply_selection:
        editor.setTextCursor(text_cursor)
    return text_cursor
