11from __future__ import division
22import re , warnings
3+ import matplotlib
34import matplotlib .cbook as cbook
45from transforms import Bbox , IdentityTransform , TransformedBbox , TransformedPath
56from path import Path
@@ -640,9 +641,12 @@ def __init__(self, o):
640641 type) and it is your responsibility to make sure this is so.
641642 """
642643 if cbook .iterable (o ) and len (o ): o = o [0 ]
644+
645+ self .oorig = o
643646 if not isinstance (o , type ):
644647 o = type (o )
645648 self .o = o
649+
646650 self .aliasd = self .get_aliases ()
647651
648652 def get_aliases (self ):
@@ -735,7 +739,7 @@ def is_alias(self, o):
735739 if ds is None : return False
736740 return ds .startswith ('alias for ' )
737741
738- def aliased_name (self , s , target ):
742+ def aliased_name (self , s ):
739743 """
740744 return 'PROPNAME or alias' if *s* has an alias, else return
741745 PROPNAME.
@@ -745,12 +749,29 @@ def aliased_name(self, s, target):
745749 property, which does not, return 'transform'
746750 """
747751
752+ if s in self .aliasd :
753+ return s + '' .join ([' or %s' % x for x in self .aliasd [s ].keys ()])
754+ else :
755+ return s
756+
757+
758+ def aliased_name_rest (self , s , target ):
759+ """
760+ return 'PROPNAME or alias' if *s* has an alias, else return
761+ PROPNAME formatted for ReST
762+
763+ E.g. for the line markerfacecolor property, which has an
764+ alias, return 'markerfacecolor or mfc' and for the transform
765+ property, which does not, return 'transform'
766+ """
767+
748768 if s in self .aliasd :
749769 aliases = '' .join ([' or %s' % x for x in self .aliasd [s ].keys ()])
750770 else :
751771 aliases = ''
752772 return ':meth:`%s <%s>`%s' % (s , target , aliases )
753773
774+
754775 def pprint_setters (self , prop = None , leadingspace = 2 ):
755776 """
756777 If *prop* is *None*, return a list of strings of all settable properies
@@ -772,8 +793,36 @@ def pprint_setters(self, prop=None, leadingspace=2):
772793 attrs .sort ()
773794 lines = []
774795
796+ for prop , path in attrs :
797+ accepts = self .get_valid_values (prop )
798+ name = self .aliased_name (prop )
799+
800+ lines .append ('%s%s: %s' % (pad , name , accepts ))
801+ return lines
802+
803+ def pprint_setters_rest (self , prop = None , leadingspace = 2 ):
804+ """
805+ If *prop* is *None*, return a list of strings of all settable properies
806+ and their valid values. Format the output for ReST
807+
808+ If *prop* is not *None*, it is a valid property name and that
809+ property will be returned as a string of property : valid
810+ values.
811+ """
812+ if leadingspace :
813+ pad = ' ' * leadingspace
814+ else :
815+ pad = ''
816+ if prop is not None :
817+ accepts = self .get_valid_values (prop )
818+ return '%s%s: %s' % (pad , prop , accepts )
819+
820+ attrs = self ._get_setters_and_targets ()
821+ attrs .sort ()
822+ lines = []
823+
775824 ########
776- names = [self .aliased_name (prop , target ) for prop , target in attrs ]
825+ names = [self .aliased_name_rest (prop , target ) for prop , target in attrs ]
777826 accepts = [self .get_valid_values (prop ) for prop , target in attrs ]
778827
779828 col0_len = max ([len (n ) for n in names ])
@@ -796,7 +845,7 @@ def pprint_setters(self, prop=None, leadingspace=2):
796845
797846 for prop , path in attrs :
798847 accepts = self .get_valid_values (prop )
799- name = self .aliased_name (prop , path )
848+ name = self .aliased_name_rest (prop , path )
800849
801850 lines .append ('%s%s: %s' % (pad , name , accepts ))
802851 return lines
@@ -805,20 +854,27 @@ def pprint_getters(self):
805854 """
806855 Return the getters and actual values as list of strings.
807856 """
808- getters = [name for name in dir (self .o )
857+
858+ o = self .oorig
859+ getters = [name for name in dir (o )
809860 if name .startswith ('get_' )
810- and callable (getattr (self .o , name ))]
861+ and callable (getattr (o , name ))]
862+ #print getters
811863 getters .sort ()
812864 lines = []
813865 for name in getters :
814- func = getattr (self . o , name )
866+ func = getattr (o , name )
815867 if self .is_alias (func ): continue
868+
816869 try : val = func ()
817870 except : continue
818871 if getattr (val , 'shape' , ()) != () and len (val )> 6 :
819872 s = str (val [:6 ]) + '...'
820873 else :
821874 s = str (val )
875+ s = s .replace ('\n ' , ' ' )
876+ if len (s )> 50 :
877+ s = s [:50 ] + '...'
822878 name = self .aliased_name (name [4 :])
823879 lines .append (' %s = %s' % (name , s ))
824880 return lines
@@ -898,16 +954,16 @@ def getp(o, property=None):
898954 insp = ArtistInspector (o )
899955
900956 if property is None :
901- print '\n ' .join (insp .pprint_getters ())
957+ ret = insp .pprint_getters ()
958+ print '\n ' .join (ret )
902959 return
903960
904961 func = getattr (o , 'get_' + property )
905- return func ()
906962
907- def get (o , * args , ** kwargs ):
908- return getp (o , * args , ** kwargs )
909- get .__doc__ = getp .__doc__
963+ return func ()
910964
965+ # alias
966+ get = getp
911967
912968def setp (h , * args , ** kwargs ):
913969 """
@@ -984,7 +1040,11 @@ def setp(h, *args, **kwargs):
9841040 return [x for x in cbook .flatten (ret )]
9851041
9861042def kwdoc (a ):
987- return '\n ' .join (ArtistInspector (a ).pprint_setters (leadingspace = 2 ))
1043+ hardcopy = matplotlib .rcParams ['docstring.hardcopy' ]
1044+ if hardcopy :
1045+ return '\n ' .join (ArtistInspector (a ).pprint_setters_rest (leadingspace = 2 ))
1046+ else :
1047+ return '\n ' .join (ArtistInspector (a ).pprint_setters (leadingspace = 2 ))
9881048
9891049kwdocd = dict ()
9901050kwdocd ['Artist' ] = kwdoc (Artist )
0 commit comments