@@ -626,3 +626,35 @@ def append(self, obj, strict=True):
626626 "to data type \' %s\' !" % self ._dtype )
627627
628628 self ._values .append (dtypes .get (new_value [0 ], self .dtype ))
629+
630+ def pprint (self , indent = 2 , max_length = 80 , current_depth = - 1 ):
631+ """
632+ Pretty print method to visualize Properties and Section-Property trees.
633+
634+ :param indent: number of leading spaces for every child Property.
635+ :param max_length: maximum number of characters printed in one line.
636+ :param current_depth: number of hierarchical levels printed from the
637+ starting Section.
638+ """
639+ property_spaces = ""
640+ prefix = ""
641+ if current_depth >= 0 :
642+ property_spaces = " " * ((current_depth + 2 ) * indent )
643+ prefix = "|-"
644+
645+ if self .unit is None :
646+ value_string = str (self .values )
647+ else :
648+ value_string = "{}{}" .format (self .values , self .unit )
649+
650+ p_len = len (property_spaces ) + len (self .name ) + len (value_string )
651+ if p_len >= max_length - 4 :
652+ split_len = int ((max_length - len (property_spaces )
653+ + len (self .name ) - len (prefix ))/ 2 )
654+ str1 = value_string [0 : split_len ]
655+ str2 = value_string [- split_len :]
656+ print (("{}{} {}: {} ... {}" .format (property_spaces , prefix ,
657+ self .name , str1 , str2 )))
658+ else :
659+ print (("{}{} {}: {}" .format (property_spaces , prefix , self .name ,
660+ value_string )))
0 commit comments