1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
U
X±d¿#ã@sdZddlZddlZddlmZddlmZddl    m
Z
m Z ddl m Z e e¡ZdZdZdZGd    d
„d
ƒZGd d „d eƒZGd d„deƒZGdd„deƒZGdd„deƒZGdd„dƒZddd„Zdd„ZedkrddlZejdZejdd…ZeeeƒdS)ap
The code in this module supports the --icon parameter on Windows.
(For --icon support under Mac OS, see building/osx.py.)
 
The only entry point, called from api.py, is CopyIcons(), below. All the elaborate structure of classes that follows
is used to support the operation of CopyIcons_FromIco(). None of these classes and globals are referenced outside
this module.
éN)Úconfig)Ú
pywintypesÚwin32api)Únormalize_icon_typeéééc@s<eZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd S)Ú    StructurecCsTt |j¡}|_tt |jd|¡ƒ|_i}|_t|j    ƒD]\}}|||<q>dS)Nó)
ÚstructÚcalcsizeÚ_format_Ú _sizeInBytesÚlistÚunpackÚ_fields_Ú    _indexes_Ú    enumerateÚ_names_)ÚselfÚsizeZindexesÚiÚnm©rúSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\PyInstaller/utils/win32/icon.pyÚ__init__$s
 
zStructure.__init__cCsDt d|¡|jD]"}| d¡st d|t||ƒ¡qt d¡dS)Nz
DUMP of %sÚ_z    %20s = %sÚ)ÚloggerÚinforÚ
startswithÚgetattr)rÚnamerrrÚdump+s
 
 
zStructure.dumpc
Cs\||jkr|j|}|j|Sz |j|WStk
rV}zt|ƒ|‚W5d}~XYnXdS©N)rrrÚ__dict__ÚKeyErrorÚAttributeError)rr"ÚindexÚerrrÚ __getattr__2s
 
 
 zStructure.__getattr__cCs.||jkr |j|}||j|<n
||j|<dSr$)rrrr%)rr"Úvaluer(rrrÚ __setattr__;s
 
 zStructure.__setattr__cCstj|jf|jžŽSr$)r Úpackr r©rrrrÚtostringBszStructure.tostringcCs$| |j¡}tt |j|¡ƒ|_dSr$)Úreadrrr rr r)rÚfileÚdatarrrÚfromfileEs zStructure.fromfileN)    Ú__name__Ú
__module__Ú __qualname__rr#r*r,r/r3rrrrr    #s     r    c@seZdZdZdZdS)Ú ICONDIRHEADER©Z
idReservedZidTypeÚidCountÚhhhN©r4r5r6rr rrrrr7Jsr7c@seZdZdZdZdS)Ú ICONDIRENTRY)ÚbWidthÚbHeightÚ bColorCountÚ    bReservedÚwPlanesÚ    wBitCountÚ dwBytesInResÚ dwImageOffsetZbbbbhhiiNr;rrrrr<Osr<c@seZdZdZdZdS)Ú
GRPICONDIRr8r:Nr;rrrrrETsrEc@seZdZdZdZdS)ÚGRPICONDIRENTRY)r=r>r?r@rArBrCÚnIDZbbbbhhihNr;rrrrrFYsrFc@s&eZdZdd„Zdd„Zd    dd„ZdS)
ÚIconFilec    CsÎ||_zt|jdƒ}Wn&tk
r<td|j›dƒ‚YnX|‚g|_g|_tƒ}|_| |¡t    |j
ƒD] }t ƒ}| |¡|j  |¡qp|jD]&}|  |jd¡|j  | |j¡¡q˜W5QRXdS)NÚrbzUnable to open icon file ú!r)ÚpathÚopenÚOSErrorÚ
SystemExitÚentriesÚimagesr7Úheaderr3Úranger9r<ÚappendÚseekrDr0rC)rrKr1rQrÚentryr)rrrr`s" 
 
 
zIconFile.__init__cCs
|j ¡Sr$)rQr/r.rrrÚ grp_icon_dirvszIconFile.grp_icon_dirécCsZd}|jD]J}tƒ}|jdd…D]}t||t||ƒƒq"||_|d}|| ¡}q
|S)NóéÿÿÿÿrW)rOrFrÚsetattrr!rGr/)rÚidr2rUr)ÚnrrrÚgrp_icondir_entriesys
zIconFile.grp_icondir_entriesN)rW)r4r5r6rrVr]rrrrrH_srHrWc    Cs¶tt|ƒ}t d|¡t |d¡}d}t|ƒD]v\}}| ¡}|| |¡}t     |t
||¡t d|t |ƒ¡|j D].}t     |t ||¡t d|t |ƒ¡|d}qtq.t |d¡dS)zà
    Use the Win API UpdateResource facility to apply the icon resource(s) to the .exe file.
 
    :param str dstpath: absolute path of the .exe file being built.
    :param str srcpath: list of 1 or more .ico file paths
    úCopying icons from %srrWz/Writing RT_GROUP_ICON %d resource with %d bytesz)Writing RT_ICON %d resource with %d bytesN)ÚmaprHrrrÚBeginUpdateResourcerrVr]ÚUpdateResourceÚ RT_GROUP_ICONÚlenrPÚRT_ICONÚEndUpdateResource)    ÚdstpathÚsrcpathr[ZiconsÚhdstZiconidrÚfr2rrrÚCopyIcons_FromIco…s
 
 rjc
CsØt|tƒr|g}dd„}tt||ƒƒ}t|ƒdkrhg}|D]"}| t|dddtjdƒ¡q:t    ||ƒS|d\}}t|ddtjdƒ}t
j   |¡d}|  ¡d    kr°t    ||gƒS|d
k    rÈt d ||¡n t d |¡zt |dt¡}Wn<tjk
r"}ztd  ||j|j¡ƒ‚W5d
}~XYnXt |d¡}    |d
krLt |t¡d}
n"|dkrht |t¡|}
n| }
t |t|
¡} t |    t|
| ¡t |t¡D]$} t |t| ¡} t |    t| | ¡q˜t |¡t  |    d¡d
S)aÇ
    Called from building/api.py to handle icons. If the input was by --icon on the command line, srcpath is a single
    string. However, it is possible to modify the spec file adding icon=['foo.ico','bar.ico'] to the EXE() statement.
    In that case, srcpath is a list of strings.
 
    The string format is either path-to-.ico or path-to-.exe,n for n an integer resource index in the .exe. In either
    case, the path can be relative or absolute.
    cSsBz | d¡\}}| ¡t|ƒfWStk
r<|dfYSXdS)zv
        Convert "pathname" to tuple ("pathname", None)
        Convert "pathname,n" to tuple ("pathname", n)
        ú,N)ÚsplitÚstripÚintÚ
ValueError)Úsrgr(rrrÚsplitter¯s
zCopyIcons.<locals>.splitterrWr)ÚicorrZworkpath)Zexerrz.icoNzCopying icon from %s, %dr^z2Unable to load icon file {}
    {} (Error code {}))!Ú
isinstanceÚstrrr_rcrSrrZCONFrjÚosrKÚsplitextÚlowerrrrZ LoadLibraryExÚLOAD_LIBRARY_AS_DATAFILErÚerrorrNÚformatÚstrerrorÚwinerrorr`ZEnumResourceNamesrbZ LoadResourcerardÚ FreeLibraryre) rfrgrqZsrcsrpr(ZsrcextZhsrcZW32ErhZgrpnamer2ZiconnamerrrÚ    CopyIcons¡sH
 
   
    ÿ 
 
 
r~Ú__main__)rW) Ú__doc__Úos.pathrur ZPyInstaller.logÚlogÚloggingZ PyInstallerrZPyInstaller.compatrrZPyInstaller.building.iconrÚ    getLoggerr4rrdrbrxr    r7r<rErFrHrjr~ÚsysÚargvrfrgrrrrÚ<module> s.       
'&
R