Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/Tools/pynche/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/Tools/pynche/__pycache__/ColorDB.cpython-37.pyc

B

� fc"�@s0dZddlZddlZddlTGdd�de�ZdadZdZGdd	�d	�Z	Gd
d�de	�Z
Gdd
�d
e	�ZGdd�de�ZGdd�de	�Z
e�d�e
fe�d�e
fe�d�efe�d�efe�d�e
fgZd2dd�ZiZdd�Ziadd�Zdd�Zdd �Zed!k�r,ed"�Ze�s"ed#�e�d$�d%Ze�e�\ZZZZ eed&eeeee ��e�!e �\Z"Z#ed'e"d(e�$e#��d)\Z%Z&Z'd*\Z%Z&Z'd+\Z%Z&Z'ed,ed-�ddl(Z(e(�(�Z)e�*e%e&e'�Z*e(�(�Z+ed.e*d/e+e)d0�xTe�,�D]HZ-e�e-�\Z%Z&Z'e�.e%e&e'�Z#ed1e-e%e&e'e�$e#d$d��f��q�WdS)3aGColor 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@seZdZdS)�BadColorN)�__name__�
__module__�__qualname__�rr�9/opt/alt/python37/lib64/python3.7/Tools/pynche/ColorDB.pyrsr� z, c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ColorDBc
Cs�d}|j|_i|_i|_d|_x�|D]�}|j�|�}|sXtd|jd|tj	d�|d7}q$|�
|�\}}}|�|�}|��}	|||f}
|j�
|
|gf�\}}||kr�||kr�|�|�||f|j|
<|
|j|	<|d}q$WdS)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__cCsdd�|�ddd�D�S)NcSsg|]}t|��qSr)�int)�.0�xrrr�
<listcomp>Msz'ColorDB._extractrgb.<locals>.<listcomp>r"r#r$)�group)rr!rrrrLszColorDB._extractrgbcCs
|�d�S)Nr)r,)rr!rrrrOszColorDB._extractnamecCs|jS)N)r)rrrr�filenameRszColorDB.filenamecCs.y
|j|Stk
r(t|�d�YnXdS)zReturn name for rgbtupleN)r�KeyErrorr)r�rgbtuplerrr�
find_byrgbUs
zColorDB.find_byrgbcCs6|��}y
|j|Stk
r0t|�d�YnXdS)z"Return (red, green, blue) for nameN)rrr.r)rrrrr�find_byname\s

zColorDB.find_bynamecCs�d}d}xr|j��D]d\}}|j|��\}}	}
||}||	}||
}
|||||
|
}|dksp||kr|}|}qW|S)z3Return the name of color nearest (red, green, blue)����)r�valuesrr)rr"r#r$�nearestZnearest_namerr&�r�g�bZrdeltaZgdeltaZbdeltaZdistancerrrr5dszColorDB.nearestcCsF|js@g|_x"|j��D]\}}|j�|�qW|jjtjd�|jS)N)r%)rrr4r�sort�strr)rrr&rrr�unique_namesvszColorDB.unique_namescCsHy|j|||f\}}Wn$tk
r<t|||f�d�YnX|g|S)N)rr.r)rr"r#r$rr&rrr�
aliases_ofs
zColorDB.aliases_ofN)rrrr'rrr-r0r1r5r;r<rrrrr
%s&	r
c@seZdZe�d�ZdS)�
RGBColorDBz?\s*(?P<red>\d+)\s+(?P<green>\d+)\s+(?P<blue>\d+)\s+(?P<name>.*)N)rrr�re�compilerrrrrr=�sr=c@seZdZe�d�Zdd�ZdS)�HTML40DBz+(?P<name>\S+)\s+(?P<hexrgb>#[0-9a-fA-F]{6})cCst|�d��S)N�hexrgb)�rrggbb_to_tripletr,)rr!rrrr�szHTML40DB._extractrgbN)rrrr>r?rrrrrrr@�s
r@c@seZdZe�d�Zdd�ZdS)�LightlinkDBz,(?P<name>(.+))\s+(?P<hexrgb>#[0-9a-fA-F]{6})cCs|�d���S)Nr)r,�strip)rr!rrrr�szLightlinkDB._extractnameN)rrrr>r?rrrrrrrC�s
rCc@s&eZdZe�d�Zdd�Zdd�ZdS)�	WebsafeDBz(?P<hexrgb>#[0-9a-fA-F]{6})cCst|�d��S)NrA)rBr,)rr!rrrr�szWebsafeDB._extractrgbcCs|�d���S)NrA)r,�upper)rr!rrrr�szWebsafeDB._extractnameN)rrrr>r?rrrrrrrrE�s
rEZXorgZXConsortiumZHTMLZ	lightlinkZWebsafec	Csvd}t|�}zV|��}|sdS|dkr,t}n|g}x$|D]\}}|�|�}|r8Pq8WdS||�}Wd|��X|a|S)N)�open�readline�	FILETYPES�search�close�
DEFAULT_DB)	rZfiletype�colordbrr Z	filetypesZtypereZclass_r!rrr�get_colordb�s$

rNcCsrt�|�}|dkrn|ddkr&t|��|dd�}|dd�}|dd�}t|d�t|d�t|d�f}|t|<|S)	z9Converts a #rrggbb color to the tuple (red, green, blue).Nr�#r
����)�	_namedictrrr()Zcolorr/r"r#r$rrrrB�s
rBcCs&t�|�}|dkr"d|}|t|<|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+�sz-triplet_to_fractional_rgb.<locals>.<listcomp>r)r/rrr�triplet_to_fractional_rgb�srXcCs0d}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:)r
r
�)����)���zfinding nearest toz...zfound nearest color�inZsecondsz%20s: (%3d/%3d/%3d) == %s)N)/�__doc__rr>�types�	ExceptionrrLZSPACEZ
COMMASPACEr
r=r@rCrEr?rIrNrTrBrUrVrXrYrrMr�exit�targetr1r"r#r$r/r0rr&�joinr6r7r8ZtimeZt0r5Zt1r;�nr<rrrr�<module>s`b