I'm trying to implement style generation for vision projects by using datasets. I have a dataset that has foreground, background, bold, and italics values for 4 different urgency levels. Foreground and background are both colors, and bold and italics are both boolean. I can get the colors to apply, but when I try to update the font, I run into trouble. Here's what I'm trying:
def setStyle(component, errorLevel, styles = None):
if not styles:
styles = system.tag.readBlocking("[default]styles")[0].value
def getColumnByName(name):
return styles.getColumnNames().index(name)
def getStyleValue(name):
return styles.getValueAt(errorLevel, getColumnByName(name))
def getUpdatedFontValue(font):
bold = getStyleValue("bold") * font.BOLD
italic = getStyleValue("italics") * font.ITALIC
return font.derive(bold | italic)
component.foreground = getStyleValue("foreground")
component.background = getStyleValue("background")
component.font = getUpdatedFontValue(component.font)
When I run this code, I get the following error:
Traceback (most recent call last):
File "<event:propertyChange>", line 1, in <module>
File "<module:setStyle>", line 13, in setStyle
NameError: global name 'font' is not defined
I think font
should be defined in the function definition, what am I doing wrong?