Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/Tools/pynche/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/Tools/pynche/__pycache__/ColorDB.cpython-34.pyc

�
e fB"�@sdZddlZddlZddlTGdd�de�ZdadZdZGdd	�d	�Z	Gd
d�de	�Z
Gdd
�d
e	�ZGdd�de�ZGdd�de	�Z
ejd�e
fejd�e
fejd�efejd�efejd�e
fgZddd�ZiZdd�Ziadd�Zdd�Zdd �Zed!kred"�Zes�ed#�ejd$�nd%Zeje�\ZZZZ eed&eeeee ��ej!e �\Z"Z#ed'e"d(ej$e#��d6\Z%Z&Z'd7\Z%Z&Z'd8\Z%Z&Z'ed0ed1�ddl(Z(e(j(�Z)ej*e%e&e'�Z*e(j(�Z+ed2e*d3e+e)d4�xtej,�D]cZ-eje-�\Z%Z&Z'ej.e%e&e'�Z#ed5e-e%e&e'ej$e#d$d��f�q�WndS)9aGColor Database.

This file contains one class, called ColorDB, and several utility functions.
The class must be instantiated by the get_colordb() function in this file,
passing it a filename to read a database out of.

The get_colordb() function will try to examine the file to figure out what the
format of the file is.  If it can't figure out the file format, or it has
trouble reading the file, None is returned.  You can pass get_colordb() an
optional filetype argument.

Supporte file types are:

    X_RGB_TXT -- X Consortium rgb.txt format files.  Three columns of numbers
                 from 0 .. 255 separated by whitespace.  Arbitrary trailing
                 columns used as the color name.

The utility functions are useful for converting between the various expected
color formats, and for calculating other color values.

�N)�*c@seZdZdS)�BadColorN)�__name__�
__module__�__qualname__�rr�9/opt/alt/python34/lib64/python3.4/Tools/pynche/ColorDB.pyrsr� z, c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ColorDBc
Cs>d}|j|_i|_i|_d|_x
|D]}|jj|�}|s�td|jd|dtj	�|d7}q4n|j
|�\}}}|j|�}|j�}	|||f}
|jj
|
|gf�\}}||kr||kr|j|�n||f|j|
<|
|j|	<|d}q4WdS)N�zError inz line�file�)�name�_ColorDB__name�_ColorDB__byrgb�_ColorDB__byname�_ColorDB__allnames�_re�match�print�sys�stderr�_extractrgb�_extractname�lower�get�append)
�self�fp�lineno�line�mo�red�green�bluerZkeyname�keyZ	foundname�aliasesrrr�__init__&s*			

!
zColorDB.__init__cCs dd�|jddd�D�S)NcSsg|]}t|��qSr)�int)�.0�xrrr�
<listcomp>Ms	z'ColorDB._extractrgb.<locals>.<listcomp>r"r#r$)�group)rr!rrrrLszColorDB._extractrgbcCs
|jd�S)Nr)r,)rr!rrrrOszColorDB._extractnamecCs|jS)N)r)rrrr�filenameRszColorDB.filenamecCs4y|j|SWntk
r/t|��YnXdS)zReturn name for rgbtupleN)r�KeyErrorr)r�rgbtuplerrr�
find_byrgbUs
zColorDB.find_byrgbcCs@|j�}y|j|SWntk
r;t|��YnXdS)z"Return (red, green, blue) for nameN)rrr.r)rrrrr�find_byname\s

zColorDB.find_bynamecCs�d}d}x�|jj�D]�\}}|j|j�\}}	}
||}||	}||
}
|||||
|
}|dks�||kr|}|}qqW|S)z3Return the name of color nearest (red, green, blue)r
����r3)r�valuesrr)rr"r#r$�nearestZnearest_namerr&�r�g�bZrdeltaZgdeltaZbdeltaZdistancerrrr5ds



zColorDB.nearestcCsb|js[g|_x-|jj�D]\}}|jj|�q"W|jjdtj�n|jS)Nr%)rrr4r�sort�strr)rrr&rrr�unique_namesvs		zColorDB.unique_namescCsUy |j|||f\}}Wn'tk
rIt|||f��YnX|g|S)N)rr.r)rr"r#r$rr&rrr�
aliases_ofs
 
zColorDB.aliases_ofN)rrrr'rrr-r0r1r5r;r<rrrrr
%s&	r
c@seZdZejd�ZdS)�
RGBColorDBz?\s*(?P<red>\d+)\s+(?P<green>\d+)\s+(?P<blue>\d+)\s+(?P<name>.*)N)rrr�re�compilerrrrrr=�sr=c@s+eZdZejd�Zdd�ZdS)�HTML40DBz+(?P<name>\S+)\s+(?P<hexrgb>#[0-9a-fA-F]{6})cCst|jd��S)N�hexrgb)�rrggbb_to_tripletr,)rr!rrrr�szHTML40DB._extractrgbN)rrrr>r?rrrrrrr@�sr@c@s+eZdZejd�Zdd�ZdS)�LightlinkDBz,(?P<name>(.+))\s+(?P<hexrgb>#[0-9a-fA-F]{6})cCs|jd�j�S)Nr)r,�strip)rr!rrrr�szLightlinkDB._extractnameN)rrrr>r?rrrrrrrC�srCc@s7eZdZejd�Zdd�Zdd�ZdS)�	WebsafeDBz(?P<hexrgb>#[0-9a-fA-F]{6})cCst|jd��S)NrA)rBr,)rr!rrrr�szWebsafeDB._extractrgbcCs|jd�j�S)NrA)r,�upper)rr!rrrr�szWebsafeDB._extractnameN)rrrr>r?rrrrrrrrE�srEZXorgZXConsortiumZHTMLZ	lightlinkZWebsafec	
Cs�d}t|�}zx|j�}|s+dS|dkr@t}n	|g}x1|D]%\}}|j|�}|rPPqPqPWdS||�}Wd|j�X|a|S)N)�open�readline�	FILETYPES�search�close�
DEFAULT_DB)	rZfiletype�colordbrr Z	filetypesZtypereZclass_r!rrr�get_colordb�s$		rNcCs�tj|�}|dkr�|ddkr:t|��n|dd�}|dd�}|dd�}t|d�t|d�t|d�f}|t|<n|S)	z9Converts a #rrggbb color to the tuple (red, green, blue).Nr�#r
����)�	_namedictrrr()Zcolorr/r"r#r$rrrrB�s*
rBcCs6tj|�}|dkr2d|}|t|<n|S)z/Converts a (red, green, blue) tuple to #rrggbb.Nz
#%02x%02x%02x)�	_tripdictr)r/Zhexnamerrr�triplet_to_rrggbb�s


rVcCsdd�|D�S)NcSsg|]}|d�qS)�r)r)r*rrrr+�s	z-triplet_to_fractional_rgb.<locals>.<listcomp>r)r/rrr�triplet_to_fractional_rgb�srXcCs6d}d}d}||d||d||dS)Ng�A`��"�?gbX9���?g�v��/�?rr
rr)r/r6r7r8rrr�triplet_to_brightness�srY�__main__z/usr/openwin/lib/rgb.txtz!No parseable color database foundr
Znavy�:zname:zaliases:��������zfinding nearest toz...zfound nearest color�inZsecondsz%20s: (%3d/%3d/%3d) == %s)r
r
r\)r]r^r_)r`rarb)/�__doc__rr>�types�	ExceptionrrLZSPACEZ
COMMASPACEr
r=r@rCrEr?rIrNrTrBrUrVrXrYrrMr�exit�targetr1r"r#r$r/r0rr&�joinr6r7r8ZtimeZt0r5Zt1r;�nr<rrrr�<module>s`
b