# Path: pyglet_gui/theme/templates.py
# class TextureTemplate(Template):
#     def __init__(self, texture, width=None, height=None):
#         Template.__init__(self)
# 
#         self.texture = texture
#         self.width = width or texture.width
#         self.height = height or texture.height
# 
#     def generate(self, color, batch, group):
#         return TextureGraphicElement(self.texture, color, batch, group)
# 
# class FrameTextureTemplate(TextureTemplate):
#     def __init__(self, texture, frame, padding, width=None, height=None):
#         TextureTemplate.__init__(self, texture, width=width, height=height)
# 
#         self._inner_texture = texture.get_region(*frame).get_texture()
#         x, y, width, height = frame
#         self._margins = (x, texture.width - width - x,    # left, right
#                          texture.height - height - y, y)  # top, bottom
#         self._padding = padding
# 
#     def generate(self, color, batch, group):
#         return FrameTextureGraphicElement(
#             self.texture, self._inner_texture,
#             self._margins, self._padding, color, batch, group)


from abc import abstractmethod
from .templates import TextureTemplate, FrameTextureTemplate
import pyglet.resource
        """
        Same as _get_texture, but limits the texture for a region
        x, y, width, height.
        """
        texture = self._get_texture(filename)
        retval = texture.get_region(x, y, width, height).get_texture()
        return retval

    def parse_element(self, element):
        if isinstance(element, dict):
            # if it has a region, we create a texture from that region.
            # else, we use a full texture.
            if 'region' in element:
                texture = self._get_texture_region(element['source'], *element['region'])
            else:
                texture = self._get_texture(element['source'])

            # if it has frame, it is a FrameTexture
            # else, it is a simple texture.
            if 'frame' in element:
                return FrameTextureTemplate(
                    texture,
                    element['frame'],
                    element.get('padding', [0, 0, 0, 0])  # if padding, else 0.
                )
            else:
                return TextureTemplate(texture)
        # if it is of the form {'image': 'test.png'}
        else:
            texture = self._get_texture(element)

# Path: pyglet_gui/theme/templates.py
# class TextureTemplate(Template):
#     def __init__(self, texture, width=None, height=None):
#         Template.__init__(self)
# 
#         self.texture = texture
#         self.width = width or texture.width
#         self.height = height or texture.height
# 
#     def generate(self, color, batch, group):
#         return TextureGraphicElement(self.texture, color, batch, group)
# 
# class FrameTextureTemplate(TextureTemplate):
#     def __init__(self, texture, frame, padding, width=None, height=None):
#         TextureTemplate.__init__(self, texture, width=width, height=height)
# 
#         self._inner_texture = texture.get_region(*frame).get_texture()
#         x, y, width, height = frame
#         self._margins = (x, texture.width - width - x,    # left, right
#                          texture.height - height - y, y)  # top, bottom
#         self._padding = padding
# 
#     def generate(self, color, batch, group):
#         return FrameTextureGraphicElement(
#             self.texture, self._inner_texture,
#             self._margins, self._padding, color, batch, group)


# Path: pyglet_gui/theme/parsers.py
from abc import abstractmethod
from .templates import TextureTemplate, FrameTextureTemplate
import pyglet.resource

        """
        Same as _get_texture, but limits the texture for a region
        x, y, width, height.
        """
        texture = self._get_texture(filename)
        retval = texture.get_region(x, y, width, height).get_texture()
        return retval

    def parse_element(self, element):
        if isinstance(element, dict):
            # if it has a region, we create a texture from that region.
            # else, we use a full texture.
            if 'region' in element:
                texture = self._get_texture_region(element['source'], *element['region'])
            else:
                texture = self._get_texture(element['source'])

            # if it has frame, it is a FrameTexture
            # else, it is a simple texture.
            if 'frame' in element:
                return FrameTextureTemplate(
                    texture,
                    element['frame'],
                    element.get('padding', [0, 0, 0, 0])  # if padding, else 0.
                )
            else:
                return TextureTemplate(texture)
        # if it is of the form {'image': 'test.png'}
        else:
            texture = self._get_texture(element)

            return TextureTemplate(texture)