示例#1
0
    def setProps(self, props={}, **kwprops):
        """
        If font is given as a string or a dict, convert it into a Font object.
        If rotation is a string representing a number, convert it.

        Then call Artist.setProps.
        """

        # A property might be defined in both props and kwprops,
        # so do all of this twice
        for d in (props, kwprops):
            if 'font' in d.keys():
                currentFont = Font()
                if 'font' in self.props().keys():
                    currentFont = self.props('font')

                if isinstance(d['font'], str):
                    currentFont.setFamily(d['font'])
                    d['font'] = currentFont
                elif isinstance(d['font'], dict):
                    currentFont.setProps(d['font'])
                    d['font'] = currentFont

            if 'rotation' in d.keys():
                try:
                    d['rotation'] = float(d['rotation'])
                except ValueError:
                    pass

        Artist.setProps(self, props, **kwprops)