1
1
from __future__ import division
2
2
import re , warnings
3
+ import matplotlib
3
4
import matplotlib .cbook as cbook
4
5
from transforms import Bbox , IdentityTransform , TransformedBbox , TransformedPath
5
6
from path import Path
@@ -640,9 +641,12 @@ def __init__(self, o):
640
641
type) and it is your responsibility to make sure this is so.
641
642
"""
642
643
if cbook .iterable (o ) and len (o ): o = o [0 ]
644
+
645
+ self .oorig = o
643
646
if not isinstance (o , type ):
644
647
o = type (o )
645
648
self .o = o
649
+
646
650
self .aliasd = self .get_aliases ()
647
651
648
652
def get_aliases (self ):
@@ -735,7 +739,7 @@ def is_alias(self, o):
735
739
if ds is None : return False
736
740
return ds .startswith ('alias for ' )
737
741
738
- def aliased_name (self , s , target ):
742
+ def aliased_name (self , s ):
739
743
"""
740
744
return 'PROPNAME or alias' if *s* has an alias, else return
741
745
PROPNAME.
@@ -745,12 +749,29 @@ def aliased_name(self, s, target):
745
749
property, which does not, return 'transform'
746
750
"""
747
751
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
+
748
768
if s in self .aliasd :
749
769
aliases = '' .join ([' or %s' % x for x in self .aliasd [s ].keys ()])
750
770
else :
751
771
aliases = ''
752
772
return ':meth:`%s <%s>`%s' % (s , target , aliases )
753
773
774
+
754
775
def pprint_setters (self , prop = None , leadingspace = 2 ):
755
776
"""
756
777
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):
772
793
attrs .sort ()
773
794
lines = []
774
795
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
+
775
824
########
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 ]
777
826
accepts = [self .get_valid_values (prop ) for prop , target in attrs ]
778
827
779
828
col0_len = max ([len (n ) for n in names ])
@@ -796,7 +845,7 @@ def pprint_setters(self, prop=None, leadingspace=2):
796
845
797
846
for prop , path in attrs :
798
847
accepts = self .get_valid_values (prop )
799
- name = self .aliased_name (prop , path )
848
+ name = self .aliased_name_rest (prop , path )
800
849
801
850
lines .append ('%s%s: %s' % (pad , name , accepts ))
802
851
return lines
@@ -805,20 +854,27 @@ def pprint_getters(self):
805
854
"""
806
855
Return the getters and actual values as list of strings.
807
856
"""
808
- getters = [name for name in dir (self .o )
857
+
858
+ o = self .oorig
859
+ getters = [name for name in dir (o )
809
860
if name .startswith ('get_' )
810
- and callable (getattr (self .o , name ))]
861
+ and callable (getattr (o , name ))]
862
+ #print getters
811
863
getters .sort ()
812
864
lines = []
813
865
for name in getters :
814
- func = getattr (self . o , name )
866
+ func = getattr (o , name )
815
867
if self .is_alias (func ): continue
868
+
816
869
try : val = func ()
817
870
except : continue
818
871
if getattr (val , 'shape' , ()) != () and len (val )> 6 :
819
872
s = str (val [:6 ]) + '...'
820
873
else :
821
874
s = str (val )
875
+ s = s .replace ('\n ' , ' ' )
876
+ if len (s )> 50 :
877
+ s = s [:50 ] + '...'
822
878
name = self .aliased_name (name [4 :])
823
879
lines .append (' %s = %s' % (name , s ))
824
880
return lines
@@ -898,16 +954,16 @@ def getp(o, property=None):
898
954
insp = ArtistInspector (o )
899
955
900
956
if property is None :
901
- print '\n ' .join (insp .pprint_getters ())
957
+ ret = insp .pprint_getters ()
958
+ print '\n ' .join (ret )
902
959
return
903
960
904
961
func = getattr (o , 'get_' + property )
905
- return func ()
906
962
907
- def get (o , * args , ** kwargs ):
908
- return getp (o , * args , ** kwargs )
909
- get .__doc__ = getp .__doc__
963
+ return func ()
910
964
965
+ # alias
966
+ get = getp
911
967
912
968
def setp (h , * args , ** kwargs ):
913
969
"""
@@ -984,7 +1040,11 @@ def setp(h, *args, **kwargs):
984
1040
return [x for x in cbook .flatten (ret )]
985
1041
986
1042
def 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 ))
988
1048
989
1049
kwdocd = dict ()
990
1050
kwdocd ['Artist' ] = kwdoc (Artist )
0 commit comments