当前位置: 首页>>代码示例>>Python>>正文


Python ElementTree.Element方法代码示例

本文整理汇总了Python中xml.etree.ElementTree.Element方法的典型用法代码示例。如果您正苦于以下问题:Python ElementTree.Element方法的具体用法?Python ElementTree.Element怎么用?Python ElementTree.Element使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xml.etree.ElementTree的用法示例。


在下文中一共展示了ElementTree.Element方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _init

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def _init(self, etree, control, parent=None):
        self.etree = etree                          # Element tree to parse
        self.control = control                      # Control class (for callback connect)
        self.parent = parent                        # Parent widget
        self.id = None                              # ID of this widget (if specified)
        self.data = utils.Bunch()                   # Metadata to append to object
        self.actions = []                           # List of actions
        self.manifest = utils.Bunch()               # Dict of element ids
        self.bgimage = None                         # Background image
        self.bgpos = (0,0)                          # Background position 'x,y' or 'center,top' etc..
        self.bgsize = 'fit'                         # Background size 'x,y' or 'fit'
        self.bgfade = 0                             # Fade bgimage when changed (0 to disable)
        self.bgopacity = 1.0                        # Current bgopacity (used during transition)
        self.click_enabled = False                  # Set True when click event enabled
        self.dblclick_enabled = False               # Set True when dblclick event enabled
        self.installEventFilter(self)               # Capture events for interactions
        self._init_attributes()                     # Process all attributes (and actions)
        self.children = self._append_children()     # Build all Chiuldren
        if parent is not None:
            parent.layout().addWidget(self) 
开发者ID:pkkid,项目名称:pkmeter,代码行数:22,代码来源:pkmixins.py

示例2: new_site

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def new_site(name, rgba=RED, pos=(0, 0, 0), size=(0.005,), **kwargs):
    """
    Creates a site element with attributes specified by @**kwargs.

    Args:
        name (str): site name.
        rgba: color and transparency. Defaults to solid red.
        pos: 3d position of the site.
        size ([float]): site size (sites are spherical by default).
    """
    kwargs["rgba"] = array_to_string(rgba)
    kwargs["pos"] = array_to_string(pos)
    kwargs["size"] = array_to_string(size)
    kwargs["name"] = name
    element = ET.Element("site", attrib=kwargs)
    return element 
开发者ID:StanfordVL,项目名称:robosuite,代码行数:18,代码来源:mjcf_utils.py

示例3: new_geom

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def new_geom(geom_type, size, pos=(0, 0, 0), rgba=RED, group=0, **kwargs):
    """
    Creates a geom element with attributes specified by @**kwargs.

    Args:
        geom_type (str): type of the geom.
            see all types here: http://mujoco.org/book/modeling.html#geom
        size: geom size parameters.
        pos: 3d position of the geom frame.
        rgba: color and transparency. Defaults to solid red.
        group: the integrer group that the geom belongs to. useful for
            separating visual and physical elements.
    """
    kwargs["type"] = str(geom_type)
    kwargs["size"] = array_to_string(size)
    kwargs["rgba"] = array_to_string(rgba)
    kwargs["group"] = str(group)
    kwargs["pos"] = array_to_string(pos)
    element = ET.Element("geom", attrib=kwargs)
    return element 
开发者ID:StanfordVL,项目名称:robosuite,代码行数:22,代码来源:mjcf_utils.py

示例4: get_collision

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def get_collision(self, name=None, site=False):
        """
        Returns a ET.Element
        It is a <body/> subtree that defines all collision related fields
        of this object.

        Return is a copy

        Args:
            name (None, optional): Assign name to body
            site (False, optional): Add a site (with name @name
                 when applicable) to the returned body

        Returns:
            ET.Element: body

        Raises:
            NotImplementedError: Description
        """
        raise NotImplementedError 
开发者ID:StanfordVL,项目名称:robosuite,代码行数:22,代码来源:objects.py

示例5: get_visual

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def get_visual(self, name=None, site=False):
        """
        Returns a ET.Element
        It is a <body/> subtree that defines all visualization related fields
        of this object.

        Return is a copy

        Args:
            name (None, optional): Assign name to body
            site (False, optional): Add a site (with name @name
                 when applicable) to the returned body

        Returns:
            ET.Element: body

        Raises:
            NotImplementedError: Description
        """
        raise NotImplementedError 
开发者ID:StanfordVL,项目名称:robosuite,代码行数:22,代码来源:objects.py

示例6: _get_visual

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def _get_visual(self, name=None, site=False, ob_type="box"):
        main_body = ET.Element("body")
        if name is not None:
            main_body.set("name", name)
        template = self.get_visual_attrib_template()
        template["type"] = ob_type
        template["rgba"] = array_to_string(self.rgba)
        template["size"] = array_to_string(self.size)
        main_body.append(ET.Element("geom", attrib=template))
        if site:
            # add a site as well
            template = self.get_site_attrib_template()
            if name is not None:
                template["name"] = name
            main_body.append(ET.Element("site", attrib=template))
        return main_body 
开发者ID:StanfordVL,项目名称:robosuite,代码行数:18,代码来源:objects.py

示例7: find_id_maybe

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def find_id_maybe(base, id):  # type: (_Element, str) -> Optional[Element]
    """
    Return the child element with the given id, or None.
    """
    assert id.replace('-', '').isalnum(), id
    matches = base.findall('.//*[@id="{}"]'.format(id))
    if 0 == len(matches):
        return None
    elif 1 == len(matches):
        [match] = matches
        return match
    else:
        raise ValueError(
            'Found {} matching elements with id {!r}'.format(len(matches), id),
            matches,
        ) 
开发者ID:PiDelport,项目名称:django-payfast,代码行数:18,代码来源:etree_helpers.py

示例8: from_xml

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def from_xml(data):
    '''
    Convert XML to ElementTree.Element

    Parameters
    ----------
    data : string
        The XML to parse

    Returns
    -------
    :class:`ElementTree.Element`

    '''
    try:
        return ET.fromstring(data)
    except:
        for i, line in enumerate(data.split('\n')):
            print(i+1, line)
        raise 
开发者ID:sassoftware,项目名称:python-esppy,代码行数:22,代码来源:xml.py

示例9: ensure_element

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def ensure_element(data):
    '''
    Ensure the given object is an ElementTree.Element

    Parameters
    ----------
    data : string or Element

    Returns
    -------
    :class:`ElementTree.Element`

    '''
    if isinstance(data, six.string_types):
        return from_xml(data)
    return data 
开发者ID:sassoftware,项目名称:python-esppy,代码行数:18,代码来源:xml.py

示例10: toJson

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def toJson(self):
        e = ElementTree.Element("schema")
        fields = []
        for field in self._fields:
            f = {}
            f["name"] = field["name"]
            f["espType"] = field["espType"]
            f["type"] = field["type"]
            f["isNumber"] = field["isNumber"]
            f["isDate"] = field["isDate"]
            f["isTime"] = field["isTime"]
            if field["isKey"]:
                f["isKey"] = "true"
            else:
                f["isKey"] = "false"
            fields.append(f)
        return(fields) 
开发者ID:sassoftware,项目名称:python-esppy,代码行数:19,代码来源:connections.py

示例11: _feature_to_element

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def _feature_to_element(self):
        e = xml.Element("input");
        e.attrib["count"] = str(self._count)
        e.attrib["score"] = str(self._score)
        e.attrib["label"] = str(self._label)
        e.attrib["coord-type"] = str(self._coordType)
        if self._coordType == "rect" or self._coordType == "yolo":
            e.attrib["x"] = str(self._x)
            e.attrib["y"] = str(self._y)
            e.attrib["width"] = str(self._width)
            e.attrib["height"] = str(self._height)
        elif self._coordType == "coco":
            e.attrib["x-min"] = str(self._xMin)
            e.attrib["y-min"] = str(self._yMin)
            e.attrib["x-max"] = str(self._xMax)
            e.attrib["y-max"] = str(self._yMax)
        return(e) 
开发者ID:sassoftware,项目名称:python-esppy,代码行数:19,代码来源:objectTracker.py

示例12: _chunk_parse

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def _chunk_parse(self, grammar=None, root_label='record', trace=0, **kwargs):
        """
        Returns an element tree structure corresponding to a toolbox data file
        parsed according to the chunk grammar.

        :type grammar: str
        :param grammar: Contains the chunking rules used to parse the
            database.  See ``chunk.RegExp`` for documentation.
        :type root_label: str
        :param root_label: The node value that should be used for the
            top node of the chunk structure.
        :type trace: int
        :param trace: The level of tracing that should be used when
            parsing a text.  ``0`` will generate no tracing output;
            ``1`` will generate normal tracing output; and ``2`` or
            higher will generate verbose tracing output.
        :type kwargs: dict
        :param kwargs: Keyword arguments passed to ``toolbox.StandardFormat.fields()``
        :rtype: ElementTree._ElementInterface
        """
        from nltk import chunk
        from nltk.tree import Tree

        cp = chunk.RegexpParser(grammar, root_label=root_label, trace=trace)
        db = self.parse(**kwargs)
        tb_etree = Element('toolbox_data')
        header = db.find('header')
        tb_etree.append(header)
        for record in db.findall('record'):
            parsed = cp.parse([(elem.text, elem.tag) for elem in record])
            tb_etree.append(self._tree2etree(parsed))
        return tb_etree 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:34,代码来源:toolbox.py

示例13: pp_browse_group_list

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def pp_browse_group_list(self, attr:ElementTree.Element):
        '''Parse and print BrowseGroupList (0x0005).

        XML example:
            <attribute id="0x0005">
                <sequence>
                    <uuid value="0x1002" />
                </sequence>
            </attribute>
        '''
        sequence = attr.find('./sequence')
        uuids = sequence.findall('./uuid')
        for uuid in uuids:
            uuid  = uuid.attrib['value']
            print('\t'+uuid+':', end=' ')
            
            if uuid == "0x1002":
                print('PublicBrowseRoot')
            else:
                print('Unknown') 
开发者ID:fO-000,项目名称:bluescan,代码行数:22,代码来源:service_record.py

示例14: pp_additional_protocol_descp_lists

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def pp_additional_protocol_descp_lists(self, attr:ElementTree.Element):
        '''Parse and print AdditionalProtocolDescriptorLists (0x000D).
        
        XML example:
    	    <attribute id="0x000d">
                <sequence>
                    <sequence>
                        <sequence>
                            <uuid value="0x0100" />
                            <uint16 value="0x001b" />
                        </sequence>

                        <sequence>
                            <uuid value="0x0017" />
                            <uint16 value="0x0103" />
                        </sequence>
                    </sequence>
                </sequence>
            </attribute>
        '''
        sequences = attr.find('./sequence').findall('./sequence')
        for sequence in sequences:
            pseudo_attr = ElementTree.Element('attribute')
            pseudo_attr.append(sequence)
            self.pp_protocol_descp_list(pseudo_attr) 
开发者ID:fO-000,项目名称:bluescan,代码行数:27,代码来源:service_record.py

示例15: __call__

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Element [as 别名]
def __call__(self, target):
        """
        Arguments:
            target (annotation) : the target annotation to be made usable
                will be an ET.Element
        Returns:
            a list containing lists of bounding boxes  [bbox coords, class name]
        """
        res = np.empty((0, 5))
        for obj in target.iter('object'):
            difficult = int(obj.find('difficult').text) == 1
            if not self.keep_difficult and difficult:
                continue
            name = obj.find('name').text.lower().strip()
            bbox = obj.find('bndbox')

            pts = ['xmin', 'ymin', 'xmax', 'ymax']
            bndbox = []
            for i, pt in enumerate(pts):
                cur_pt = int(bbox.find(pt).text)
                bndbox.append(cur_pt)
            label_idx = self.class_to_ind[name]
            bndbox.append(label_idx)
            res = np.vstack((res, bndbox))  # [xmin, ymin, xmax, ymax, label_ind]
        return res 
开发者ID:zllrunning,项目名称:hand-detection.PyTorch,代码行数:27,代码来源:wider_voc.py


注:本文中的xml.etree.ElementTree.Element方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。