<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , print_function , unicode_literals <EOL> from . . enum . dml import MSO_COLOR_TYPE , MSO_THEME_COLOR <EOL> from . . oxml . dml . color import ( <EOL> CT_HslColor , CT_PresetColor , CT_SchemeColor , CT_ScRgbColor , CT_SRgbColor , <EOL> CT_SystemColor <EOL> ) <EOL> class ColorFormat ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , eg_colorChoice_parent , color ) : <EOL> super ( ColorFormat , self ) . __init__ ( ) <EOL> self . _xFill = eg_colorChoice_parent <EOL> self . _color = color <EOL> @ property <EOL> def brightness ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _color . brightness <EOL> @ brightness . setter <EOL> def brightness ( self , value ) : <EOL> self . _validate_brightness_value ( value ) <EOL> self . _color . brightness = value <EOL> @ classmethod <EOL> def from_colorchoice_parent ( cls , eg_colorChoice_parent ) : <EOL> xClr = eg_colorChoice_parent . eg_colorChoice <EOL> color = _Color ( xClr ) <EOL> color_format = cls ( eg_colorChoice_parent , color ) <EOL> return color_format <EOL> @ property <EOL> def rgb ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _color . rgb <EOL> @ rgb . setter <EOL> def rgb ( self , rgb ) : <EOL> if not isinstance ( rgb , RGBColor ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if not isinstance ( self . _color , _SRgbColor ) : <EOL> srgbClr = self . _xFill . get_or_change_to_srgbClr ( ) <EOL> self . _color = _SRgbColor ( srgbClr ) <EOL> self . _color . rgb = rgb <EOL> @ property <EOL> def theme_color ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _color . theme_color <EOL> @ theme_color . setter <EOL> def theme_color ( self , mso_theme_color_idx ) : <EOL> if not isinstance ( self . _color , _SchemeColor ) : <EOL> schemeClr = self . _xFill . get_or_change_to_schemeClr ( ) <EOL> self . _color = _SchemeColor ( schemeClr ) <EOL> self . _color . theme_color = mso_theme_color_idx <EOL> @ property <EOL> def type ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _color . color_type <EOL> def _validate_brightness_value ( self , value ) : <EOL> if value < - <NUM_LIT:1.0> or value > <NUM_LIT:1.0> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if isinstance ( self . _color , _NoneColor ) : <EOL> msg = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> raise ValueError ( msg ) <EOL> class _Color ( object ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , xClr ) : <EOL> color_cls = { <EOL> type ( None ) : _NoneColor , <EOL> CT_HslColor : _HslColor , <EOL> CT_PresetColor : _PrstColor , <EOL> CT_SchemeColor : _SchemeColor , <EOL> CT_ScRgbColor : _ScRgbColor , <EOL> CT_SRgbColor : _SRgbColor , <EOL> CT_SystemColor : _SysColor , <EOL> } [ type ( xClr ) ] <EOL> return super ( _Color , cls ) . __new__ ( color_cls ) <EOL> def __init__ ( self , xClr ) : <EOL> super ( _Color , self ) . __init__ ( ) <EOL> self . _xClr = xClr <EOL> @ property <EOL> def brightness ( self ) : <EOL> lumMod , lumOff = self . _xClr . lumMod , self . _xClr . lumOff <EOL> if lumOff is not None : <EOL> brightness = lumOff . val <EOL> return brightness <EOL> if lumMod is not None : <EOL> brightness = lumMod . val - <NUM_LIT:1.0> <EOL> return brightness <EOL> return <NUM_LIT:0> <EOL> @ brightness . setter <EOL> def brightness ( self , value ) : <EOL> if value > <NUM_LIT:0> : <EOL> self . _tint ( value ) <EOL> elif value < <NUM_LIT:0> : <EOL> self . _shade ( value ) <EOL> else : <EOL> self . _xClr . clear_lum ( ) <EOL> @ property <EOL> def color_type ( self ) : <EOL> tmpl = "<STR_LIT>" <EOL> raise NotImplementedError ( tmpl % self . __class__ . __name__ ) <EOL> @ property <EOL> def rgb ( self ) : <EOL> """<STR_LIT>""" <EOL> tmpl = "<STR_LIT>" <EOL> raise AttributeError ( tmpl % self . __class__ . __name__ ) <EOL> @ property <EOL> def theme_color ( self ) : <EOL> """<STR_LIT>""" <EOL> return MSO_THEME_COLOR . NOT_THEME_COLOR <EOL> def _shade ( self , value ) : <EOL> lumMod_val = <NUM_LIT:1.0> - abs ( value ) <EOL> color_elm = self . _xClr . clear_lum ( ) <EOL> color_elm . add_lumMod ( lumMod_val ) <EOL> def _tint ( self , value ) : <EOL> lumOff_val = value <EOL> lumMod_val = <NUM_LIT:1.0> - lumOff_val <EOL> color_elm = self . _xClr . clear_lum ( ) <EOL> color_elm . add_lumMod ( lumMod_val ) <EOL> color_elm . add_lumOff ( lumOff_val ) <EOL> class _HslColor ( _Color ) : <EOL> @ property <EOL> def color_type ( self ) : <EOL> return MSO_COLOR_TYPE . HSL <EOL> class _NoneColor ( _Color ) : <EOL> @ property <EOL> def color_type ( self ) : <EOL> return None <EOL> @ property <EOL> def theme_color ( self ) : <EOL> """<STR_LIT>""" <EOL> tmpl = "<STR_LIT>" <EOL> raise AttributeError ( tmpl % self . __class__ . __name__ ) <EOL> class _PrstColor ( _Color ) : <EOL> @ property <EOL> def color_type ( self ) : <EOL> return MSO_COLOR_TYPE . PRESET <EOL> class _SchemeColor ( _Color ) : <EOL> def __init__ ( self , schemeClr ) : <EOL> super ( _SchemeColor , self ) . __init__ ( schemeClr ) <EOL> self . _schemeClr = schemeClr <EOL> @ property <EOL> def color_type ( self ) : <EOL> return MSO_COLOR_TYPE . SCHEME <EOL> @ property <EOL> def theme_color ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _schemeClr . val <EOL> @ theme_color . setter <EOL> def theme_color ( self , mso_theme_color_idx ) : <EOL> self . _schemeClr . val = mso_theme_color_idx <EOL> class _ScRgbColor ( _Color ) : <EOL> @ property <EOL> def color_type ( self ) : <EOL> return MSO_COLOR_TYPE . SCRGB <EOL> class _SRgbColor ( _Color ) : <EOL> def __init__ ( self , srgbClr ) : <EOL> super ( _SRgbColor , self ) . __init__ ( srgbClr ) <EOL> self . _srgbClr = srgbClr <EOL> @ property <EOL> def color_type ( self ) : <EOL> return MSO_COLOR_TYPE . RGB <EOL> @ property <EOL> def rgb ( self ) : <EOL> """<STR_LIT>""" <EOL> return RGBColor . from_string ( self . _srgbClr . val ) <EOL> @ rgb . setter <EOL> def rgb ( self , rgb ) : <EOL> self . _srgbClr . val = str ( rgb ) <EOL> class _SysColor ( _Color ) : <EOL> @ property <EOL> def color_type ( self ) : <EOL> return MSO_COLOR_TYPE . SYSTEM <EOL> class RGBColor ( tuple ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , r , g , b ) : <EOL> msg = '<STR_LIT>' <EOL> for val in ( r , g , b ) : <EOL> if not isinstance ( val , int ) or val < <NUM_LIT:0> or val > <NUM_LIT:255> : <EOL> raise ValueError ( msg ) <EOL> return super ( RGBColor , cls ) . __new__ ( cls , ( r , g , b ) ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % self <EOL> @ classmethod <EOL> def from_string ( cls , rgb_hex_str ) : <EOL> """<STR_LIT>""" <EOL> r = int ( rgb_hex_str [ : <NUM_LIT:2> ] , <NUM_LIT:16> ) <EOL> g = int ( rgb_hex_str [ <NUM_LIT:2> : <NUM_LIT:4> ] , <NUM_LIT:16> ) <EOL> b = int ( rgb_hex_str [ <NUM_LIT:4> : ] , <NUM_LIT:16> ) <EOL> return cls ( r , g , b ) </s>
