3
7ßL]Î	  ã               @   sT   d Z ddlZddlZddlmZ ddlZddlmZ ddl	m
Z
 G dd„ deƒZdS )z$ Enthought pyface package component
é    N)Ú	cStringIO)ÚResourceFactory)Ú	Undefinedc               @   s"   e Zd ZdZdd„ Zddd„ZdS )ÚPyfaceResourceFactoryz2 The implementation of a shared resource manager. c             C   s   t j|t jƒS )z; Creates an image from the data in the specified filename. )ÚwxÚImageÚBITMAP_TYPE_ANY)ÚselfÚfilename© r   úA/tmp/pip-install-5sebvq2j/pyface/pyface/ui/wx/resource_manager.pyÚimage_from_file*   s    z%PyfaceResourceFactory.image_from_fileNc          	   C   sŠ   yt jt|ƒƒS    |tkr"dS Y nX d}|dkr@tjƒ \}}t|dƒ}|j|ƒ |jƒ  t j	|t j
ƒ}|dk	r†tj|ƒ tj|ƒ |S )z+ Creates an image from the specified data. NÚwb)r   ZImageFromStreamÚStringIOr   ÚtempfileÚmkstempÚopenÚwriteÚcloser   r   ÚosÚunlink)r	   Údatar
   ÚhandleÚtfÚimager   r   r   Úimage_from_data1   s     




z%PyfaceResourceFactory.image_from_data)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   #   s   r   )r   r   r   Z	six.movesr   r   r   Zpyface.resource.apir   Z
traits.apir   r   r   r   r   r   Ú<module>   s   