<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , print_function <EOL> from numbers import Number <EOL> from warnings import warn <EOL> from . base import BaseShape <EOL> from . . dml . fill import FillFormat <EOL> from . . dml . line import LineFormat <EOL> from . . enum . shapes import MSO_AUTO_SHAPE_TYPE , MSO_SHAPE_TYPE <EOL> from . . spec import autoshape_types <EOL> from . . text . text import TextFrame <EOL> from . . util import lazyproperty <EOL> class Adjustment ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , def_val , actual = None ) : <EOL> super ( Adjustment , self ) . __init__ ( ) <EOL> self . name = name <EOL> self . def_val = def_val <EOL> self . actual = actual <EOL> @ property <EOL> def effective_value ( self ) : <EOL> """<STR_LIT>""" <EOL> raw_value = self . actual <EOL> if raw_value is None : <EOL> raw_value = self . def_val <EOL> return self . _normalize ( raw_value ) <EOL> @ effective_value . setter <EOL> def effective_value ( self , value ) : <EOL> if not isinstance ( value , Number ) : <EOL> tmpl = "<STR_LIT>" <EOL> raise ValueError ( tmpl % value ) <EOL> self . actual = self . _denormalize ( value ) <EOL> @ staticmethod <EOL> def _denormalize ( value ) : <EOL> """<STR_LIT>""" <EOL> return int ( value * <NUM_LIT> ) <EOL> @ staticmethod <EOL> def _normalize ( raw_value ) : <EOL> """<STR_LIT>""" <EOL> return raw_value / <NUM_LIT> <EOL> @ property <EOL> def val ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . actual if self . actual is not None else self . def_val <EOL> class AdjustmentCollection ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , prstGeom ) : <EOL> super ( AdjustmentCollection , self ) . __init__ ( ) <EOL> self . _adjustments_ = self . _initialized_adjustments ( prstGeom ) <EOL> self . _prstGeom = prstGeom <EOL> def __getitem__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . _adjustments_ [ key ] . effective_value <EOL> def __setitem__ ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> self . _adjustments_ [ key ] . effective_value = value <EOL> self . _rewrite_guides ( ) <EOL> def _initialized_adjustments ( self , prstGeom ) : <EOL> """<STR_LIT>""" <EOL> if prstGeom is None : <EOL> return [ ] <EOL> davs = AutoShapeType . default_adjustment_values ( prstGeom . prst ) <EOL> adjustments = [ Adjustment ( name , def_val ) for name , def_val in davs ] <EOL> self . _update_adjustments_with_actuals ( adjustments , prstGeom . gd_lst ) <EOL> return adjustments <EOL> def _rewrite_guides ( self ) : <EOL> """<STR_LIT>""" <EOL> guides = [ ( adj . name , adj . val ) for adj in self . _adjustments_ ] <EOL> self . _prstGeom . rewrite_guides ( guides ) <EOL> @ staticmethod <EOL> def _update_adjustments_with_actuals ( adjustments , guides ) : <EOL> """<STR_LIT>""" <EOL> adjustments_by_name = dict ( ( adj . name , adj ) for adj in adjustments ) <EOL> for gd in guides : <EOL> name = gd . name <EOL> actual = int ( gd . fmla [ <NUM_LIT:4> : ] ) <EOL> try : <EOL> adjustment = adjustments_by_name [ name ] <EOL> except KeyError : <EOL> continue <EOL> adjustment . actual = actual <EOL> return <EOL> @ property <EOL> def _adjustments ( self ) : <EOL> """<STR_LIT>""" <EOL> return tuple ( self . _adjustments_ ) <EOL> def __len__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . _adjustments_ ) <EOL> class AutoShapeType ( object ) : <EOL> """<STR_LIT>""" <EOL> _instances = { } <EOL> def __new__ ( cls , autoshape_type_id ) : <EOL> """<STR_LIT>""" <EOL> if autoshape_type_id not in cls . _instances : <EOL> inst = super ( AutoShapeType , cls ) . __new__ ( cls ) <EOL> cls . _instances [ autoshape_type_id ] = inst <EOL> return cls . _instances [ autoshape_type_id ] <EOL> def __init__ ( self , autoshape_type_id ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return <EOL> if autoshape_type_id not in autoshape_types : <EOL> raise KeyError ( <EOL> "<STR_LIT>" <EOL> % autoshape_type_id <EOL> ) <EOL> autoshape_type = autoshape_types [ autoshape_type_id ] <EOL> self . _autoshape_type_id = autoshape_type_id <EOL> self . _basename = autoshape_type [ '<STR_LIT>' ] <EOL> self . _loaded = True <EOL> @ property <EOL> def autoshape_type_id ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _autoshape_type_id <EOL> @ property <EOL> def basename ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _basename <EOL> @ classmethod <EOL> def default_adjustment_values ( cls , prst ) : <EOL> """<STR_LIT>""" <EOL> return autoshape_types [ prst ] [ '<STR_LIT>' ] <EOL> @ property <EOL> def desc ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _desc <EOL> @ classmethod <EOL> def id_from_prst ( cls , prst ) : <EOL> """<STR_LIT>""" <EOL> return MSO_AUTO_SHAPE_TYPE . from_xml ( prst ) <EOL> @ property <EOL> def prst ( self ) : <EOL> """<STR_LIT>""" <EOL> return MSO_AUTO_SHAPE_TYPE . to_xml ( self . _autoshape_type_id ) <EOL> class Shape ( BaseShape ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , sp , parent ) : <EOL> super ( Shape , self ) . __init__ ( sp , parent ) <EOL> self . _sp = sp <EOL> @ lazyproperty <EOL> def adjustments ( self ) : <EOL> """<STR_LIT>""" <EOL> return AdjustmentCollection ( self . _sp . prstGeom ) <EOL> @ property <EOL> def auto_shape_type ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _sp . is_autoshape : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return self . _sp . prst <EOL> @ lazyproperty <EOL> def fill ( self ) : <EOL> """<STR_LIT>""" <EOL> return FillFormat . from_fill_parent ( self . _sp . spPr ) <EOL> def get_or_add_ln ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _sp . get_or_add_ln ( ) <EOL> @ property <EOL> def has_text_frame ( self ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> @ property <EOL> def has_textframe ( self ) : <EOL> """<STR_LIT>""" <EOL> msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> warn ( msg , UserWarning , stacklevel = <NUM_LIT:2> ) <EOL> return self . has_text_frame <EOL> @ lazyproperty <EOL> def line ( self ) : <EOL> """<STR_LIT>""" <EOL> return LineFormat ( self ) <EOL> @ property <EOL> def ln ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _sp . ln <EOL> @ property <EOL> def shape_type ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . is_placeholder : <EOL> return MSO_SHAPE_TYPE . PLACEHOLDER <EOL> if self . _sp . is_autoshape : <EOL> return MSO_SHAPE_TYPE . AUTO_SHAPE <EOL> if self . _sp . is_textbox : <EOL> return MSO_SHAPE_TYPE . TEXT_BOX <EOL> msg = '<STR_LIT>' <EOL> raise NotImplementedError ( msg ) <EOL> @ property <EOL> def text ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . text_frame . text <EOL> @ text . setter <EOL> def text ( self , text ) : <EOL> self . text_frame . text = text <EOL> @ property <EOL> def text_frame ( self ) : <EOL> """<STR_LIT>""" <EOL> txBody = self . _element . get_or_add_txBody ( ) <EOL> return TextFrame ( txBody , self ) <EOL> @ property <EOL> def textframe ( self ) : <EOL> """<STR_LIT>""" <EOL> msg = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> warn ( msg , UserWarning , stacklevel = <NUM_LIT:2> ) <EOL> return self . text_frame </s>
