
    d)                     @   d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 	 ej                  Z
dadZdZdZdZdZdZdZ ej*                  d      Zd Zd	 Zd
 ZeeeeeeedfdZddZedk(  r eej:                  dd        yy# e$ r ej                  Z
Y jw xY w)a  
img2py.py  --  Convert an image to PNG format and embed it in a Python
               module with appropriate code so it can be loaded into
               a program at runtime.  The benefit is that since it is
               Python source code it can be delivered as a .pyc or
               'compiled' into the program using freeze, py2exe, etc.

Usage:

    img2py.py [options] image_file python_file

Options:

    -m <#rrggbb>   If the original image has a mask or transparency defined
                   it will be used by default.  You can use this option to
                   override the default or provide a new mask by specifying
                   a colour in the image to mark as transparent.

    -n <name>      Normally generic names (getBitmap, etc.) are used for the
                   image access functions.  If you use this option you can
                   specify a name that should be used to customize the access
                   functions, (getNameBitmap, etc.)

    -c             Maintain a catalog of names that can be used to reference
                   images.  Catalog can be accessed via catalog and
                   index attributes of the module.
                   If the -n <name> option is specified then <name>
                   is used for the catalog key and index value, otherwise
                   the filename without any path or extension is used
                   as the key.

    -a             This flag specifies that the python_file should be appended
                   to instead of overwritten.  This in combination with -n will
                   allow you to put multiple images in one Python source file.

    -i             Also output a function to return the image as a wxIcon.

    -f             Generate code compatible with the old function interface.
                   (This option is ON by default in 2.8, use -f to turn off.)

You can also import this module from your Python scripts, and use its img2py()
function. See its docstring for more info.
    N)img2imgFT z\s*index.append\('(.+)'\)\s*c                 0   |t         k(  r| j                         j                  |j                               r|r|}n`t        j                  j                  |t        j                  j                  t        j                  j                  |       d         |z         }t        |d      5 }t        | d      5 }|j                  |j                                d d d        d d d        yt        j                  | |||||      S # 1 sw Y   ,xY w# 1 sw Y   yxY w)Nr   wbrb)Tok)DEFAULT_MASKCLRupperendswithospathjoinbasenamesplitextopenwritereadr   convert)	fileNamemaskClr	outputDir
outputNameoutTypeoutExtnewnamef_outf_ins	            1/usr/lib/python3/dist-packages/wx/tools/img2py.pyr   r   n   s    /!hnn&6&?&?&O Gggll9#%77#3#3BGG4D4DX4Nq4Q#RU[#[]G'4  	)Eh% )DIIK()	) ??8WiWfUU) )	) s$   (D5 D D D		DDc                     | D cg c]  }|j                         r|nd }}|d   j                         s|d   dk7  r|j                  dd       dj                  |      }|S c c}w )N_r   r   )isalnumisalphainsertr   )imgNameletterlettersvarNames       r   )_replace_non_alphanumeric_with_underscorer(   }   se    AHIv)vs2IGI1:GAJ#$5q#gggGN Js   A"c                    | j                  d       |sZ| j                  dt        j                  d   z         | j                  d       |r"| j                  d       | j                  d       t        |      }| j                  |d|d       |rZ||v rt	        d	|z         t	        d
       |j                  |       | j                  d|z         | j                  d|d|d       |rb| j                  d|d|d       | j                  d|d|d       | j                  d|d|d       |r| j                  d|d|d       | j                  d       y )NzH#----------------------------------------------------------------------
z"# This file was generated by %s
#
r   z2from wx.lib.embeddedimage import PyEmbeddedImage

catalog = {}
index = []

z = PyEmbeddedImage(

zWarning: %s already in catalog.z1         Only the last entry will be accessible.
zindex.append('%s')
z	catalog['z'] = getzData = z	.GetData
zImage = z
.GetImage
z	Bitmap = z.GetBitmap
zIcon = z	.GetIcon
)r   sysargvr(   printappend)	outr$   datar1   iconcatalogfunctionCompatible	old_indexr'   s	            r   _write_imager8      s   II#$		8388A;FG		HIII&'II&'7@GIIw=>i3g=>FG!		(723		GW=>		AB		'7CD		GWEFIIGWEFIIdO    c
                 D   |	dk7  r|	}t        j                         st        j                  d      at	        j
                  d      5 }
|
j                  }ddd       	 t        | |dt         j                  d      \  }}|sBt        |       	 t        j                  j                  |      rt        j                  |       yyg }t        |d      5 }
t        |
j!                               }ddd       rC|dd }|dd }t"        j$                  d	kD  rd
|z  }nd|z  }|s|dz  }|j'                  |       |rCdj)                  |      }t        j                  j                  |      rt        j                  |       	 g }|r|r|dk7  rt        j                  j+                  |      \  }}d}t        |d      5 }|D ]D  }|dk(  rd}t,        j/                  |      }|s#|j'                  |j1                         d          F 	 ddd       |rHt        |d      5 }|j3                  d       |j3                  d       |j3                  d       ddd       |sRt        j                  j+                  |       \  }}t        j                  j5                  |      d   }t        d|z         |dk(  r#t"        j6                  }t9        ||||||||       n-|rdnd}t        ||      5 }t9        ||||||||       ddd       |rd|z  }nd}|rd|z  }nd}t        d| |d||       y# 1 sw Y   xY w# 1 sw Y   MxY w# t        j                  j                        rt        j                  |       w w xY w# 1 sw Y   {xY w# 1 sw Y   >xY w# 1 sw Y   xY w)a  
    Converts an image file to a data structure written in a Python file
    --image_file: string; the path of the source image file
    --python_file: string; the path of the destination python file
    --other arguments: they are equivalent to the command-line arguments
    r:   r   F)deleteNz.pngr   H   3z    %sz    "%s")r,   -Trr*   az<
# ***************** Catalog starts here *******************z

catalog = {}
r+   zW
Warning: -n not specified. Using filename (%s) for name of image and/or catalog entry.wz using "%s"r   z with mask %sz	Embedded z into )wxGetAppAppapptempfileNamedTemporaryFilenamer   BITMAP_TYPE_PNGr0   r   r   existsremover   	b64encoder   r.   versionr1   r   splitindexPatternmatchgroupsr   r   stdoutr8   )
image_filepython_filer1   
compressedr   r$   r4   r5   r6   functionCompatibilefidtfnamer   msglinesr3   partoutputr7   pyPathpyFileappend_catalogsourcePylinelineMatcherr2   imgPathimgFilemoden_msgm_msgs                                  r   img2pyrj      sd   $ b 0 99;ffQi 
	$	$E	2 c*gtVR=O=OQWXC#J" 77>>&!IIf " &$ 	)3SXXZ(D	)9D9D{{S !D#d*#LL   yy77>>&!IIfI6kS0 {3+s# 	Bx  B++%*N"."4"4T":K"!((););)=a)@AB	B k3' ,3		YZ		./		*+,
 77==4''""7+A.hkrrscjjS'4w@RT]^s#+t$ 	cgtVT7DVXab	c '')	z5+u
MNS 	) 	) 77>>&!IIf "	B 	B, ,	c 	csg   L(.M M L5*AM 7M 8%M<$M<4N	#N(L25L?:M 7M9<N	NNc                 "   | st         j                  dd  } | rd| v rt        t               y t        }t
        }t        }t        }t        }t        }t        }	 t        j                  | d      \  }}	|D ]=  \  }
}|
dk(  rd}|
dk(  r|}|
dk(  r|}|
dk(  rd}&|
d	k(  rd}.|
d
k(  rd}6|
dk(  s<d}? t        |	      dk7  rt        t               y |	\  }}t        |||||||||	       y # t        j                  $ r t        t               Y y w xY w)N   z-hz
auicfFn:m:z-aTz-nz-mz-iz-cz-fz-FF   )r.   r/   r0   __doc__DEFAULT_APPENDDEFAULT_COMPRESSEDr	   DEFAULT_IMGNAMEDEFAULT_ICONDEFAULT_CATALOGDEFAULT_COMPATIBLEgetoptGetoptErrorlenrj   )argsr1   rW   r   r$   r4   r5   
compatibleoptsfileArgsoptvalrU   rV   s                 r   mainr~     s+   xx|DDLgF#JGGDG#Jt\:h
  S$;FD[GD[GD[DD[GD[JD[J  8}g&J
:{:ww
L3  gs   C) )"DD__main__rl   )N)rn   base64ru   r   rer.   rH   rD   wx.toolsr   rN   AttributeErrorencodestringrG   ro   rp   r	   rq   rr   rs   rt   compilerQ   r   r(   r8   rj   r~   __name__r/    r9   r   <module>r      s   J*X   	 	 
  	 $  I    rzz9:V6 !("""0!cOJ,L^ z!" o  $##I$s   B	 	BB