<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def toggle_comments(self):
 """ Toggles comments on the document selected lines. :return: Method success. :rtype: bool """


        if not self.__comment_marker:
            return True

        cursor = self.textCursor()
        if not cursor.hasSelection():
            cursor.movePosition(QTextCursor.StartOfBlock)
            line = foundations.strings.to_string(self.document().findBlockByNumber(cursor.blockNumber()).text())
            if line.startswith(self.__comment_marker):
                foundations.common.repeat(cursor.deleteChar, len(self.__comment_marker))
            else:
                cursor.insertText(self.__comment_marker)
        else:
            block = self.document().findBlock(cursor.selectionStart())
            while True:
                block_cursor = self.textCursor()
                block_cursor.setPosition(block.position())
                if foundations.strings.to_string(block.text()).startswith(self.__comment_marker):
                    foundations.common.repeat(block_cursor.deleteChar, len(self.__comment_marker))
                else:
                    block_cursor.insertText(self.__comment_marker)

                if block.contains(cursor.selectionEnd()):
                    break
                block = block.next()
        return True