Power table row and cell coloring

The way I do it is to build a dictionary of attributes, starting with the formatting of least precedence. Then I add or ‘override’ attributes with additional logic as needed.

attributes = {"background": "#FFFFFF", "foreground": "#000000"}
if rowIndex % 2 == 0:
	attributes["background"] = "#EEECE8"
if colName == "val":
	if self.data.getValueAt(rowIndex, "writeable") == True:
		attributes["background"] = "#FFFF47"
if colName == "alarm" and value is not None:
	attributes["text"] = None
elif colName == "unit" and value is None:
	attributes["text"] = None
	if self.data.getValueAt(rowIndex, "alarm") is not None:
		attributes["iconPath"] = "CustomIcons/Indicator_Red.png"
		if value < 1:
			attributes["iconPath"] = "CustomIcons/Indicator_Green.png"

return attributes
7 Likes