
     hi]                         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 d dlm	Z	 d dl
mZ d dlmZ d dlmZmZmZ d dlmZmZ d dlmZ  ej.                  e      Z G d	 d
e      Zy)    N)log)SplashWriter)splash_templates)Target)_check_guts_eq_check_guts_tocmisc)is_aix	is_darwin)	bindependc                       e Zd ZdZd Zdefdefdefdefdefdefd	efd
efdefdefdefdefdefdefdefdefdefdefdeffZd Zd Z	e
d        Zd Ze
d        Zy)Splasha  
    Bundles the required resources for the splash screen into a file, which will be included in the CArchive.

    A Splash has two outputs, one is itself and one is stored in splash.binaries. Both need to be passed to other
    build targets in order to enable the splash screen.
    c                 d    ddl m} ddlm} t	        j
                          t        rt        d      |j                  st        d      t        j                  d        j                  |       t        j                  j                  |      s#t        j                  j                  |d   |      }t        j                  j!                  |      }t        j                  j#                  |      st%        d|z        | _        |j)                  d	d
       _        |j)                  dd       _        |j)                  dd       _        |j)                  dd       _        |j)                  dd       _        |j)                  dd       _        |j)                  dd       _        |j)                  dd       _        |j)                  dd       _        |j)                  dd       _        |j)                  dd       _        t        j                  jA                   jB                        d   } j,                  
|dz    _         j.                  
|dz    _        |jD                   _#         jI                   jF                  |       _%        t        jM                  d jJ                          jO                          _(        |jR                   _*        |jV                   _,         jT                  J  jX                  J t        jM                  d jT                         t        jM                  d  jX                         t[        t        j                  j]                   jT                        t        j                  j]                   jX                        t        j                  j                  |j^                  d!      t        j                  j                  |j`                  d"      t        j                  j                  |j`                  d#      t        j                  j                  |j`                  d$      t        j                  j                  |j`                  d%d&      t        j                  j                  |j`                  d%d'      t        j                  j                  |j`                  d%d(      t        j                  j                  |j`                  d%d)      g
       _1        |jd                  d*k\  rm jb                  jg                  t        j                  j                  |j`                  d+      t        j                  j                  |j`                  d,      g       t        j                  d-       |jh                  } j*                  r" jb                  jg                  d. |D                jT                   jX                  fD 	cg c]$  }	t        j                  j]                  |	      |	d/f& }
}	tk        jl                  |
       _7         jb                  jg                  d0  jn                  D                jJ                  s$ jn                  jq                   fd1|D               t[        d2 ||z    jn                  z   D              fd3}t[        ts        | jb                               _1        t        jM                  d4 jb                         tt        rt        j                  jA                   jT                        \  }}|d5k(  r+|jv                  \  }} xjT                  d6| d7| d8z  c_*        t        j                  jA                   jX                        \  }}|d5k(  r+|jd                  \  }} xjX                  d9| d7| d8z  c_,         jy                          yc c}	w ):a  
        :param str image_file:
            A path-like object to the image to be used. Only the PNG file format is supported.

            .. note:: If a different file format is supplied and PIL (Pillow) is installed, the file will be converted
                automatically.

            .. note:: *Windows*: The color ``'magenta'`` / ``'#ff00ff'`` must not be used in the image or text, as it is
                used by splash screen to indicate transparent areas. Use a similar color (e.g., ``'#ff00fe'``) instead.

            .. note:: If PIL (Pillow) is installed and the image is bigger than max_img_size, the image will be resized
                to fit into the specified area.
        :param list binaries:
            The TOC list of binaries the Analysis build target found. This TOC includes all extension modules and their
            binary dependencies. This is required to determine whether the user's program uses `tkinter`.
        :param list datas:
            The TOC list of data the Analysis build target found. This TOC includes all data-file dependencies of the
            modules. This is required to check if all splash screen requirements can be bundled.

        :keyword text_pos:
            An optional two-integer tuple that represents the origin of the text on the splash screen image. The
            origin of the text is its lower left corner. A unit in the respective coordinate system is a pixel of the
            image, its origin lies in the top left corner of the image. This parameter also acts like a switch for
            the text feature. If omitted, no text will be displayed on the splash screen. This text will be used to
            show textual progress in onefile mode.
        :type text_pos: Tuple[int, int]
        :keyword text_size:
            The desired size of the font. If the size argument is a positive number, it is interpreted as a size in
            points. If size is a negative number, its absolute value is interpreted as a size in pixels. Default: ``12``
        :type text_size: int
        :keyword text_font:
            An optional name of a font for the text. This font must be installed on the user system, otherwise the
            system default font is used. If this parameter is omitted, the default font is also used.
        :keyword text_color:
            An optional color for the text. HTML color codes (``'#40e0d0'``) and color names (``'turquoise'``) are
            supported. Default: ``'black'``
            (Windows: the color ``'magenta'`` / ``'#ff00ff'`` is used to indicate transparency, and should not be used)
        :type text_color: str
        :keyword text_default:
            The default text which will be displayed before the extraction starts. Default: ``"Initializing"``
        :type text_default: str
        :keyword full_tk:
            By default Splash bundles only the necessary files for the splash screen (some tk components). This
            options enables adding full tk and making it a requirement, meaning all tk files will be unpacked before
            the splash screen can be started. This is useful during development of the splash screen script.
            Default: ``False``
        :type full_tk: bool
        :keyword minify_script:
            The splash screen is created by executing an Tcl/Tk script. This option enables minimizing the script,
            meaning removing all non essential parts from the script. Default: ``True``
        :keyword name:
            An optional alternative filename for the .res file. If not specified, a name is generated.
        :type name: str
        :keyword script_name:
            An optional alternative filename for the Tcl script, that will be generated. If not specified, a name is
            generated.
        :type script_name: str
        :keyword max_img_size:
            Maximum size of the splash screen image as a tuple. If the supplied image exceeds this limit, it will be
            resized to fit the maximum width (to keep the original aspect ratio). This option can be disabled by
            setting it to None. Default: ``(760, 480)``
        :type max_img_size: Tuple[int, int]
        :keyword always_on_top:
            Force the splashscreen to be always on top of other windows. If disabled, other windows (e.g., from other
            applications) can cover the splash screen by user bringing them to front. This might be useful for
            frozen applications with long startup times. Default: ``True``
        :type always_on_top: bool
        r   )CONF
tcltk_infoz/ERROR: Splash screen is not supported on macOS.zERROR: Your platform does not support the splash screen feature, since tkinter is not installed. Please install tkinter and try again.z>Verifying Tcl/Tk compatibility with splash screen requirementsspecpathzImage file '%s' not foundfull_tkFnameNscript_nameminify_scriptTmax_img_size)i  i  text_pos	text_size   	text_fontTkDefaultFont
text_colorblacktext_defaultInitializingalways_on_topz.resz_script.tclzProgram uses tkinter: %rzUsing Tcl shared library: %rzUsing Tk shared library: %rzinit.tcllicense.termsztext.tclztk.tclttkzttk.tclz	fonts.tclzcursors.tclz	utils.tcl)	   r   zscaling.tcltclIndexz/Collect Tcl/Tk data files for the splash screenc              3   &   K   | ]	  }|d      ywr   N .0entrys     GC:\des-py\Monitor\venv\Lib\site-packages\PyInstaller/building/splash.py	<genexpr>z"Splash.__init__.<locals>.<genexpr>   s     +ME!H+M   BINARYc              3   &   K   | ]	  }|d      ywr(   r)   r*   s     r-   r.   z"Splash.__init__.<locals>.<genexpr>   s     'LUa'Lr/   c              3   F   K   | ]  }|d    j                   v s|  ywr(   )splash_requirements)r+   r,   selfs     r-   r.   z"Splash.__init__.<locals>.<genexpr>   s"      g5%(dNfNfBf gs   !!c              3   &   K   | ]	  }|d      ywr(   r)   r*   s     r-   r.   z"Splash.__init__.<locals>.<genexpr>   s     W5eAhWr/   c                     | vr:t         j                  j                  |       dk(  ryt        j	                  d|        yy)Nr#   FzThe local Tcl/Tk installation is missing the file %s. The behavior of the splash screen is therefore undefined and may be unsupported.T)ospathbasenameloggerwarning)filenamecollected_filess    r-   _filter_requirementz,Splash.__init__.<locals>._filter_requirement   sD    . 77##H-@ BCK     zSplash Requirements: %sz.az(libtcl.so..)z
(libtk.so.)=PyInstaller.configr   PyInstaller.utils.hooks.tcl_tkr   r   __init__r   
SystemExit	availabler:   info_check_tcl_tk_compatibilityr7   r8   isabsjoinnormpathexists
ValueError
image_filegetr   r   r   r   r   r   r   r   r   r    r"   splitexttocfilenametkinter_extension_file_tkinter_file_uses_tkinteruses_tkinterdebuggenerate_scriptscripttcl_shared_librarytcl_libtk_shared_librarytk_libsetr9   TCL_ROOTNAMETK_ROOTNAMEr3   
tk_versionupdate
data_filesr   binary_dependency_analysisbinariesextendfilterr
   tcl_version__postinit__)r4   rN   rd   dataskwargsr   r   root
tcltk_treesrc_name
tcltk_libsr>   _ext	tcl_major	tcl_minortk_majortk_minorr=   s   `                 @r-   rD   zSplash.__init__#   s   J 	,= NOO ##8  	TU((4 ww}}Z(d:&6
CJWW%%j1
ww~~j)8:EFF %zz)U3JJvt,	!::mT:#ZZ>"JJ~zB 

:t4K4KA **\7;"JJ~~F $ZZ> ww 0 01!499vDI##m3D (>> !..t/A/A8L/1B1BC**,!44 22||'''{{&&&3T\\B2DKK@#& GGT\\*GGT[[) GGLL00*=GGLL//AGGLL//<GGLL//:GGLL//	BGGLL//DGGLL//FGGLL//D)(
 $ .   F*$$++Z33]CZ33Z@- 
 	EF**
<<$$+++M*+MM Y]XdXdfjfqfqWrs8rww''18XFs
s!<<ZH 	  '''Ldmm'LL   MM   gJ gg WX5E5UWW	  $'v.A4C[C['\#] .0H0HI WW%%dll3FAsd{'1'='=$	9+i[)A FFWW%%dkk2FAsd{%/%:%:"(H:QxjBBc ts   )^-rN   r   r   r   r   r   r   r    r"   r   r   r   rU   rX   rZ   r\   r3   rd   rS   c                     t        j                  | ||      ryt        j                  | j                        |kD  r,t
        j                  d| j                  | j                         yy)NTz#Building %s because file %s changedF)r   _check_gutsr	   mtimerN   r:   rG   tocbasename)r4   data
last_builds      r-   rv   zSplash._check_guts$  sR    dD*5 ::doo&3KK=t?O?OQUQ`Q`ar?   c           
           t         j                  d j                         	 ddlm ddlm}  fd}t         j                  d      }|j                  d      dk(  r|j                  d	       t        j                  d
|j                  d            d   t        j                  d
|j                  d            d   f}| j                  kD  r | j                  |      }nt        j                   j#                   j                        }n͉rj                   j                  d      }|j$                   j                  kD  r |||j$                        }nGt'        j(                         }|j+                  |d       |j-                          |j/                         }t         j                  d j                         nt1        d j                  d      |j-                          t3         j                   j4                  t        j                   j7                   j8                        t        j                   j7                   j:                        |j<                  |j>                  | j@                         y # t
        $ r d Y bw xY w)NzBuilding Splash %sr   )Imager   c                    
r&|\  }}j                   d   |z  }|dk  rt        ||z        }j                   d   }j                   d   |z  }|dk  rt        ||z        }j                   d   }t        | 
j                        r| }n
j	                  |       }|j                  ||f      }t        j                         }|j                  |d       |j                          |j                          |j                         }	t        j                  dj                  |||       |	S t        d|d   |d   j                   d   j                   d   fz        )Nr      PNGformatz/Resized image %s from dimensions %r to (%d, %d)zThe splash image dimensions (w: %d, h: %d) exceed max_img_size (w: %d, h:%d), but the image cannot be resized due to missing PIL.Image! Either install the Pillow package, adjust the max_img_size, or use an image of compatible dimensions.)r   int
isinstancer|   openresizeioBytesIOsaveclosegetvaluer:   rG   rN   rM   )_image
_orig_size_w_h_ratio_w_ratio_h_img_img_resized_image_stream_image_dataPILImager4   s             r-   _resize_imagez&Splash.assemble.<locals>._resize_image<  sc   #B,,Q/"4a<R(]+B**1-B,,Q/"4a<R(]+B**1-B fhnn5!D#==0D#{{B84 !#

!!-!>

""$+446Mt`jlnprs"" N  ]JqM43D3DQ3GIZIZ[\I]^_ r?   rb   s   PNG

   z!I   r)moder   r   z Converted image %s to PNG formatz
The image z needs to be converted to a PNG file, but PIL.Image is not available! Either install the Pillow package, or use a PNG image for you splash screen.)!r:   rG   r   PILr|   ImportErrorrC   r   r   rN   readseekstructunpackr   r7   r8   abspathsizer   r   r   r   r   rM   r   r3   r9   rZ   r\   r^   r_   rX   )	r4   r   r   rN   img_sizeimageimg
image_datar   s	   `       @r-   assemblezSplash.assemble/  s   ($))4	-
 	>$	N $//40
 ??1!55OOBdJOOA,>?BFMMRVXbXgXghiXjDklmDnoH$+++%doox@8--c-:Cxx$+++%c3884ZZ\
E2		"++-KK:DOOLOSa 
 	II$$GGT\\*GGT[[)##""KK		
_  	H	s   I> >JJc                    | j                   }| j                  }t        r| j                  rt	        d      |dk  s|dk  rt        j                  dg||  ||k7  rt        j                  dg||  | j                  st	        d      | j                  | j                  d}| j                  s|dz  }t	        |      y )Nz[ERROR: The splash screen feature does not support macOS system framework version of Tcl/Tk.)r      zThe installed Tcl/Tk (%d.%d / %d.%d) version might not work with the splash screen feature of the bootloader, which was tested against Tcl/Tk 8.6zqThe installed version of Tcl (%d.%d) and Tk (%d.%d) do not match. PyInstaller is tested against matching versionszqERROR: The installed Tcl version is not threaded. PyInstaller only supports the splash screen using threaded Tcl.zjERROR: Could not determine the path to Tcl and/or Tk shared library, which are required for splash screen.z The _tkinter module appears to be a built-in, which likely means that python was built with statically-linked Tcl/Tk libraries and is incompatible with splash screen.)rg   r`   r   is_macos_system_frameworkrE   r:   r;   tcl_threadedrY   r[   rR   )r   rg   r`   messages       r-   rH   z"Splash._check_tcl_tk_compatibility  s     ,,**
==m 
 :#6NNBDOR\ *$NN$&14> &&&  ((0J4P4P4X8  44a W%% 5Yr?   c           	      h   i }| j                   ot        j                  d       |j                  | j                   d   | j                   d   | j                  | j
                  | j                  | j                  d       t        j                  || j                        }| j                  rHdj                  d t        d	 |j                               D              }t        j                   d
d|      }t#        | j$                  dd      5 }|j'                  |       ddd       |S # 1 sw Y   |S xY w)z
        Generate the script for the splash screen.

        If minify_script is True, all unnecessary parts will be removed.
        Nz!Add text support to splash screenr   r~   )pad_xpad_ycolorfont	font_sizedefault_text)text_optionsr"   
c              3   F   K   | ]  }|j                  d       s|r|  yw)#N)
startswith)r+   lines     r-   r.   z)Splash.generate_script.<locals>.<genexpr>  s'      s+ s   !c                 "    | j                         S )N)strip)r   s    r-   <lambda>z(Splash.generate_script.<locals>.<lambda>  s    $**, r?   z + wzutf-8)encoding)r   r:   rV   ra   r   r   r   r    r   build_scriptr"   r   rJ   map
splitlinesresubr   r   write)r4   drX   script_files       r-   rW   zSplash.generate_script  s    ==$LL<=HHq)q)!^^ $ 1 1  "..ATM_M_`YY !$%>@Q@Q@S!T F VVD#v.F $""C': 	&kf%	&	&s   D''D1c                 x    t        j                  |       } |D ]   \  }}}t        j                  |      | k(  s  y y)NTF)pathlibPurePath)tkinter_filerd   	dest_namerm   typecodes        r-   rT   zSplash._uses_tkinter  sE     ''5-5 	)Ix)\9	 r?   N)__name__
__module____qualname____doc__rD   r   r   _GUTSrv   r   staticmethodrH   rW   rT   r)   r?   r-   r   r      s    dP 
~&	 	'	^$	n%	n%	~&	(	.)	N#	.)	(	(	>"	N#	>"	/	_% 
.)1E6	^
@ *& *&X D  r?   r   )r   r7   r   r   r   PyInstallerr   loggingPyInstaller.archive.writersr   PyInstaller.buildingr   PyInstaller.building.datastructr   PyInstaller.building.utilsr   r   r	   PyInstaller.compatr
   r   PyInstaller.dependr   	getLoggerr   r:   r   r)   r?   r-   <module>r      sN    
 	 	   & 4 1 2 L L 0 (			8	$JV Jr?   