This public method returns a string with up to four
components: family name, size, and optional weight and slant.
Example: "luxi mono 14 bold italic".
However, the font we have built may not be exactly what the
user specified. Not all fonts are available in all sizes, for
example. So we use the .actual() method on the
font to retrieve the options actually in force.
def getName ( self ):
"""Return a string describing the current font's options.
[ if self.__currentFont is None ->
return None
else ->
return a string describing the current font's options ]
"""
#-- 1 --
if self.__currentFont is None:
return None
#-- 2 --
# [ attrs := a list containing self.__currentFont's
# actual family name and actual size (as a string) ]
attrs = [ self.__currentFont.actual ( "family" ),
str ( self.__currentFont.actual ( "size" ) ) ]
#-- 3 --
# [ if self.__currentFont is bold ->
# attrs +:= "bold"
# else -> I ]
if self.__currentFont.actual ( "weight" ) == tkFont.BOLD:
attrs.append ( "bold" )
#-- 4 --
# [ if self.__currentFont is italic ->
# attrs +:= "italic"
# else -> I ]
if self.__currentFont.actual ( "slant" ) == tkFont.ITALIC:
attrs.append ( "italic" )
The .join() string method assembles
this list into a string, with the pieces separated
by one space.
#-- 5 --
return " ".join ( attrs )