
    \g`&                         d Z ddlmZmZm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 ddlmZ ddlmZ ddlmZmZmZmZmZ dgZd	Zd
ZdZ ej        e          Zd Zd Zd ZeedfdZ eddfdZ!	 	 ddZ"ddZ#dS )zJ
Utilities to process and convert svg images to png using palette colors.
    )absolute_importdivisionprint_functionN)QSize)QIcon)QApplication)IMAGES_PATHPACKAGE_PATHQRC_FILESTYLES_SCSS_FILEPATHSVG_PATHbase_palettez
<RCC warning="WARNING! File created programmatically. All changes made in this file will be lost!">
  <qresource prefix="{resource_prefix}">
z    <file>rc/{fname}</file>zi
  </qresource>
  <qresource prefix="{style_prefix}">
      <file>style.qss</file>
  </qresource>
</RCC>
c                     |j         }|j        }|j        }|j        }|                     d          \  }}| ||dz   |z   ||dz   |z   ||dz   |z   |i}|S )zG
    Return map of files (i.e states) to color from given palette.
    .z
_disabled.z_focus.z	_pressed.)COLOR_BACKGROUND_4COLOR_ACCENT_5COLOR_ACCENT_2COLOR_TEXT_1split)	fnamepalettecolor_disabledcolor_focuscolor_pressedcolor_normalnameextfile_colorss	            7lib/python3.11/site-packages/qdarkstyle/utils/images.py_get_file_color_mapr    .   sz     /N(K*M'LC  ID#||c!>y3{S -	K     c                 *   t          | d          5 }|                                }ddd           n# 1 swxY w Y   d}|                    ||          }t          |d          5 }|                    |           ddd           dS # 1 swxY w Y   dS )z+
    Replace base svg with fill color.
    rNz#ff0000w)openreadreplacewrite)svg_pathtemp_svg_pathcolorfhdata
base_colornew_datas          r   _create_colored_svgr0   B   s    
h		 wwyy               J||J..H	mS	!	! R
                 s   266%BBBc                     t          ||          }t          |           }|                    |          }|                                }|                    |           dS )z2
    Convert svg files to png files using Qt.
    N)r   r   pixmaptoImagesave)r)   png_pathheightwidthsizeiconr2   imgs           r   convert_svg_to_pngr;   P   sV     D??D[[F
..

CHHXr!   c                 N   t          g           }|#t          d           t          j        d           |j        #t          d           t          j        d           t
          j                            | d          }t
          j                            ||j        d          }t
          j                            ||j        d          }t          	                    d           t          	                    d	|z             t          	                    d
|z             t          	                    d|z             t          |d          5 }|                                }ddd           n# 1 swxY w Y   |                                }	|	                                D ]3\  }
}|                    d|
z   dz   |                                          }4t          |d          5 }|                    |           ddd           n# 1 swxY w Y   t#          ||dd           ||fS )zC
    Create palette image svg and png image on specified path.
    NzDPlease pass a palette class in order to create its associated images   $A QDarkStyle palette requires an ID!zbase_palette.svgzpalette.svgzpalette.pngzCreating palette image ...zBase SVG: %sz
To SVG: %sz
To PNG: %sr#   z{{ z }}zw+i  )r   printsysexitIDospathjoin_loggerinfor%   r&   color_paletteitemsr'   lowerr(   r;   )base_svg_pathrD   r   _base_palette_svg_pathpalette_svg_pathpalette_png_pathr,   r-   rH   
color_namecolor_values               r   create_palette_imagerR   [   sj    	RA " 	# 	# 	#z4555GLL8JKKw||D'*mDDw||D'*mDDLL-...LL"77888LL 00111LL 00111	#S	)	) Rwwyy               ))++M#0#6#6#8#8 M M
K||EJ.68I8I8K8KLL		%	% 
               ')94FFF---s$   E--E14E1$HH
H
c           	      8	   t          g           }|#t          d           t          j        d           |j        #t          d           t          j        d           |s+t
          j                            t          |j        d          }t          j
                    }d t          j        |           D             }d}dd	d
}t                              d           t                              d| z             t                              d|z             t                              d|z             t          |          }d}	d}
t                      }t          |          }|                                D ]d\  }}|}t                              d|d|           |D ]8}|                    d          d         }|t&          vrt
          j                            | |          }t)          ||          }t                              dt
          j                            |          z             |                                D ]N\  }}t
          j                            ||          }t-          |||           |                    d|          }t
          j                            ||          }t1          ||||           |	dz  }	t                              dt
          j                            |          z             ||k    rt
          j                            |          }t
          j                            |          }dt
          j                            ||          z   }	 |                    |           =# t4          $ r Y Jw xY wP|
dz  }
t                              dt
          j                            |          z             :ft                              d|z             t                              d|
z             t                              d|	z             t                              d|z             t                              dt          |          z             t                              d|z             dS )a  Create resources `rc` png image files from base svg files and palette.

    Search all SVG files in `base_svg_path` excluding IMAGE_BLACKLIST,
    change its colors using `palette` creating temporary SVG files, for each
    state generating PNG images for each size `heights`.

    Args:
        base_svg_path (str, optional): [description]. Defaults to SVG_PATH.
        rc_path (str, optional): [description].
        palette (Palette, optional): Palette.
    NzBPlease pass a palette class in order to create its associated filer=   r>   rcc                 <    g | ]}|                     d           |S ).svg)endswith).0fs     r   
<listcomp>z!create_images.<locals>.<listcomp>   s)    MMM!**V:L:LM!MMMr!       z.pngz@2x.png)r[   @   zCreating images ...zSVG folder: %szTMP folder: %szPNG folder: %sr   z Size HxW (px): z X r   )r   z  Working on: %srV   z   Creating: %s/z  Ignored blacklist: %sz# SVG files: %sz# SVG ignored: %sz# PNG files: %sz# RC links: %sz# RC links not in RC: %szRC links not in RC: %s)r   r?   r@   rA   rB   rC   rD   rE   r
   tempfilemkdtemplistdirrF   rG   lenget_rc_links_from_scssrI   debugr   IMAGE_BLACKLISTr    basenamer0   r'   r;   remove
ValueError)rK   rc_pathr   rL   temp_dir
svg_fnamesbase_heightheightsnum_svgnum_pngnum_ignoredrc_listnum_rc_listr6   r   r7   	svg_fnamesvg_namer)   color_filescolor_svg_namer+   r*   	png_fnamer5   rc_basepng_baserc_names                               r   create_imagesrz      sW    	RA   	! 	! 	!z4555 ?',,|WZ>>!!HMMRZ66MMMJK  G
 LL&'''LL!M1222LL!H,---LL!G+,,,*ooGGK %&&Gg,,K}} )= )=66655ABBB# $	= $	=I s++A.H ..7<<yAA1)WMMM0 " 0 0 ; ;< = = = .9->->-@-@ ! !)NE$&GLL>$J$JM'-GGG . 6 6vs C CI!w||GY??H&}hNNNqLGMM"3$&G$4$4Y$?$?#@ A A A
 ,,"$'"2"27";";#%7#3#3I#>#>"%Wh(G(G"G!#NN73333) ! ! ! D! -!, q 7 " 0 0 ; ;< = = = =G$	=L LL"W,---LL${2333LL"W,---LL!K/000LL+c'll:;;;LL)G344444s   0N
N	N		qss_icons
qdarkstylec                 h   g }|#t          d           t          j        d           |j        #t          d           t          j        d           t          j                            t          |j        d          }t          j                            t          |j        t                    }| dz   |j        z   } |dz   |j        z   }t          
                    d           t          
                    d| z             t          
                    d	|z             t          
                    d
|z             t          t	          j        |                    D ]0}|                    t                              |                     1t                               |           d                    |          z   t"                              |          z   }t          
                    d|z             t%          |d          5 }|                    |           ddd           dS # 1 swxY w Y   dS )ax  
    Generate the QRC file programmaticaly.

    Search all RC folder for PNG images and create a QRC file.

    Args:
        resource_prefix (str, optional): Prefix used in resources.
            Defaults to 'qss_icons'.
        style_prefix (str, optional): Prefix used to this style.
            Defaults to 'qdarkstyle'.
        palette (Palette, optional): Palette.
    Nz;Please pass a palette class in order to create its qrc filer=   r>   rT   r]   zGenerating QRC file ...zResource prefix: %szStyle prefix: %szSearching in: %s)r   )resource_prefix
)style_prefixzWriting in: %sr$   )r?   r@   rA   rB   rC   rD   rE   r
   r   rF   rG   sortedr`   appendTEMPLATE_QRC_FILEformatTEMPLATE_QRC_HEADERTEMPLATE_QRC_FOOTERr%   r(   )	r~   r   r   filesrh   qrc_filepathr   qrc_contentr,   s	            r   generate_qrc_filer      s4    E  	 	 	z4555gll<T::G7<<gj(CCL%+gj8O#%
2LLL*+++LL&8999LL#l2333LL#g-... 
7++,, < <&--E-::;;;; '--o-NNYYu%%&(//\/JJKK LL!L0111 
lC	 	  B
                 s   H''H+.H+	\/.*\.pngc                    t          t          d          5 }|                                }ddd           n# 1 swxY w Y   |                    d          }t	          j        d| z   dz             }g }|D ]A}t	          j        ||          }|r(|                    |                    d                     Bt          t          |                    }|S )z
    Get all rc links from scss file returning the list of unique links.

    Args:
        pattern (str): regex pattern to find the links.

    Returns:
        list(str): list of unique links found.
    r#   Nr   ()r=   )r%   r   r&   r   recompilesearchr   grouplistset)patternr,   r-   linescompiled_exprp   linematchs           r   rb   rb      s    
"C	(	( Bwwyy               JJtE:cGmc122LG + +	,-- 	+NN5;;q>>***3w<<  GNs   7;;)r{   r|   N)r   )$__doc__
__future__r   r   r   loggingrC   r   r@   r^   qtpy.QtCorer   
qtpy.QtGuir   qtpy.QtWidgetsr   r|   r	   r
   r   r   r   rd   r   r   r   	getLogger__name__rF   r    r0   r;   rR   rz   r   rb    r!   r   <module>r      s   
 A @ @ @ @ @ @ @ @ @  				 				 



              ' ' ' ' ' '8 8 8 8 8 8 8 8 8 8 8 8 8 8 "" 
 2   '
H
%
%  (     (0k!%'. '. '. '.T !)$ c5 c5 c5 c5L AM"2 2 2 2j     r!   