# encoding: utf-8
"""
Objects related to shapes, visual objects that appear on the drawing layer of
a document.
"""
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
from .enum.shape import WD_INLINE_SHAPE
from .oxml.ns import nsmap
from .shared import Parented
class InlineShapes(Parented):
"""
Sequence of |InlineShape| instances, supporting len(), iteration, and
indexed access.
"""
def __init__(self, body_elm, parent):
super(InlineShapes, self).__init__(parent)
self._body = body_elm
def __getitem__(self, idx):
"""
Provide indexed access, e.g. 'inline_shapes[idx]'
"""
try:
inline = self._inline_lst[idx]
except IndexError:
msg = "inline shape index [%d] out of range" % idx
raise IndexError(msg)
return InlineShape(inline)
def __iter__(self):
return (InlineShape(inline) for inline in self._inline_lst)
def __len__(self):
return len(self._inline_lst)
@property
def _inline_lst(self):
body = self._body
xpath = '//w:p/w:r/w:drawing/wp:inline'
return body.xpath(xpath)
class InlineShape(object):
"""
Proxy for an ``