Пример #1
0
    def setComment(self, *args):
        """
        Add/Set comment for the block or parameter.

        There are two modes of operation. The first (`setComment(text)`) sets the comment of the
        block itself to the supplied *text*. The second (`setComment(param, text)` sets the comment
        of the supplied *param* with the value of *text*.
        """
        if len(args) == 1:
            param = None
            text = args[0]
        elif len(args) == 2:
            param, text = args

        comment = self.__hitparamcomments.get(param, self.__hitblockcomment)
        if comment is not None:
            comment.setText('# {}'.format(text))

        elif (comment is None) and (param is None):
            self.parent.__hitnode.insertChild(
                self.__hitoffset, hit.NewComment('# {}'.format(text)))
            self.__reinitComments()

        elif (comment is None) and (param is not None):
            for child in self.__hitnode.children(hit.NodeType.Field):
                if child.path() == param:
                    child.addChild(hit.NewComment('# {}'.format(text), True))
                    self.__reinitComments()
                    break
Пример #2
0
    def setComment(self, *args):
        """
        Add/Set comment for the block or parameter.

        Usage:
            setComment("comment")
            setComment("param", "comment")
        """
        if len(args) == 1:
            param = None
            text = args[0]
        elif len(args) == 2:
            param, text = args

        comment = self.__hitparamcomments.get(param, self.__hitblockcomment)
        if comment is not None:
            comment.setText('# {}'.format(text))

        elif (comment is None) and (param is None):
            self.parent.__hitnode.insertChild(self.__hitoffset, hit.NewComment('# {}'.format(text)))
            self.__reinitComments()

        elif (comment is None) and (param is not None):
            for child in self.__hitnode.children(hit.NodeType.Field):
                if child.path() == param:
                    child.addChild(hit.NewComment('# {}'.format(text), True))
                    self.__reinitComments()
                    break
Пример #3
0
def commentNode(hit_parent, comments, is_inline):
    c_list = comments
    if isinstance(comments, str):
        c_list = [comments]
    for c in c_list:
        lines = c.split("\n")
        for line in lines:
            if line:
                line = "# %s" % line
            else:
                line = "#"
            hit_comment = hit.NewComment(line, is_inline)
            hit_parent.addChild(hit_comment)