I want a treeview (more a treeList) with two LV_USER fields and no LV_TREE field.
I started with the given example and I succeed, but the text colors are incorrect.
Initially all white, but after a click all black.
How can I set the text foreground and background color?
The background color is actually defined by the usergui.
customgui.SetBool(c4d.TREEVIEW_ALTERNATE_BG, True) # Alternate background per line.
I tried setting the text color using GeUserArea.DrawSetTextCol(c4d.Vector(0,0,0), c4d.Vector(128,128,128)) and GeUserArea.DrawSetPen(c4d.Vector(255,255,255)) but no success.
Here some code.
def CreateLayout(self):
# Create the TreeView GUI.
customgui = c4d.BaseContainer()
customgui.SetBool(c4d.TREEVIEW_BORDER, c4d.BORDER_THIN_IN)
customgui.SetBool(c4d.TREEVIEW_HAS_HEADER, True) # True if the tree view may have a header line.
customgui.SetBool(c4d.TREEVIEW_HIDE_LINES, False) # True if no lines should be drawn.
customgui.SetBool(c4d.TREEVIEW_MOVE_COLUMN, True) # True if the user can move the columns.
customgui.SetBool(c4d.TREEVIEW_RESIZE_HEADER, True) # True if the column width can be changed by the user.
customgui.SetBool(c4d.TREEVIEW_FIXED_LAYOUT, True) # True if all lines have the same height.
customgui.SetBool(c4d.TREEVIEW_ALTERNATE_BG, True) # Alternate background per line.
customgui.SetBool(c4d.TREEVIEW_CURSORKEYS, True) # True if cursor keys should be processed.
customgui.SetBool(c4d.TREEVIEW_NOENTERRENAME, False) # Suppresses the rename popup when the user presses enter.
customgui.SetBool(c4d.TREEVIEW_OUTSIDE_DROP, True) # True if an object may be dropped under all the objects in the tree view.
self._treegui = self.AddCustomGui( 1000, c4d.CUSTOMGUI_TREEVIEW, "", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 300, 300, customgui)
if not self._treegui:
print "[ERROR]: Could not create TreeView"
return False
self.AddButton(1001, c4d.BFH_CENTER, name="Add")
self.AddButton(1002, c4d.BFH_CENTER, name="Insert Under")
return True
def InitValues(self):
# Initialize the column layout for the TreeView.
layout = c4d.BaseContainer()
layout.SetLong(ID_CHECKBOX, c4d.LV_CHECKBOX)
#layout.SetLong(ID_NAME, c4d.LV_TREE)
layout.SetLong(ID_NAME, c4d.LV_USER)
layout.SetLong(ID_OTHER, c4d.LV_USER)
self._treegui.SetLayout(3, layout)
# Set the header titles.
self._treegui.SetHeaderText(ID_CHECKBOX, "Check")
self._treegui.SetHeaderText(ID_NAME, "Name")
self._treegui.SetHeaderText(ID_OTHER, "Other")
self._treegui.Refresh()
# Set TreeViewFunctions instance used by our CUSTOMGUI_TREEVIEW
self._treegui.SetRoot(self._treegui, self._listView, None)
return True
In ListView()
def DrawCell(self, root, userdata, obj, col, drawinfo, bgColor):
"""
Draw into a Cell, only called for column of type LV_USER
"""
if col == ID_NAME:
name = "Jan "
geUserArea = drawinfo["frame"]
#geUserArea.DrawSetTextCol(c4d.Vector(0,0,0), c4d.Vector(128,128,128))
#geUserArea.DrawSetPen(c4d.Vector(255,255,255))
w = geUserArea.DrawGetTextWidth(name)
h = geUserArea.DrawGetFontHeight()
xpos = drawinfo["xpos"]
ypos = drawinfo["ypos"] + drawinfo["height"]
drawinfo["frame"].DrawText(name, xpos, ypos - h * 1.1)
if col == ID_OTHER:
name = "Pim " + obj.otherData
geUserArea = drawinfo["frame"]
#geUserArea.DrawSetTextCol(c4d.Vector(255,255,255), c4d.Vector(0,0,0))
#geUserArea.DrawSetPen(c4d.Vector(0,0,0))
w = geUserArea.DrawGetTextWidth(name)
h = geUserArea.DrawGetFontHeight()
xpos = drawinfo["xpos"]
ypos = drawinfo["ypos"] + drawinfo["height"]
drawinfo["frame"].DrawText(name, xpos, ypos - h * 1.1)
return