Hey,
yes it is. The trick is c4d.LV_CHECKBOX_HIDE, the relevant bits happen in GetDropDownMenu.
Cheers,
Ferdinand
I removed the command, you can directly run this in the script manager:
import c4d
PLUGIN_ID = 12345678
PLUGIN_NAME = "ListView Dropdown Prototype"
ID_TREE_VIEW = 1000
ID_FILE_NAME = 1001
ID_IMPORT_OPTION = 1002
ID_IMPORT_OPTION_DEFAULT = 1100
ID_IMPORT_OPTION_HIGH = 1101
ID_IMPORT_OPTION_MEDIUM = 1102
ID_IMPORT_OPTION_LOW = 1103
dummyfile_list = ["hud.stp", "material_reference.wrl", "front_axle.stp", "body.wrl", "wheel_variant.stp"]
class DummyFile:
def __init__(self, file_name, import_option="Default"):
self.file_name = file_name
self.import_option = import_option
class DummyFileListView(c4d.gui.TreeViewFunctions):
def __init__(self, dialog):
self.dialog = dialog
self.files = [DummyFile(file_name) for file_name in dummyfile_list]
def GetFirst(self, root, userdata):
return self.files[0] if self.files else None
def GetNext(self, root, userdata, dummy_file):
current_index = self.files.index(dummy_file)
next_index = current_index + 1
return self.files[next_index] if next_index < len(self.files) else None
def GetDown(self, root, userdata, dummy_file):
return None
def GetId(self, root, userdata, dummy_file):
return id(dummy_file)
def GetName(self, root, userdata, dummy_file):
return dummy_file.file_name
def IsSelected(self, root, userdata, dummy_file):
return False
def GetColumnWidth(self, root, userdata, dummy_file, column_id, area):
if column_id == ID_FILE_NAME:
return area.DrawGetTextWidth(dummy_file.file_name) + 24
if column_id == ID_IMPORT_OPTION:
return 120
return 96
def GetDropDownMenu(self, root, userdata, dummy_file, column_id, menu_info):
if column_id != ID_IMPORT_OPTION:
menu_info["state"] = c4d.LV_CHECKBOX_HIDE
return
if not dummy_file.file_name.lower().endswith(".stp"):
menu_info["state"] = c4d.LV_CHECKBOX_HIDE
return
options = {
ID_IMPORT_OPTION_DEFAULT: "Default",
ID_IMPORT_OPTION_HIGH: "High",
ID_IMPORT_OPTION_MEDIUM: "Medium",
ID_IMPORT_OPTION_LOW: "Low",
}
for option_id, label in options.items():
menu_info["menu"].SetString(option_id, label)
menu_info["entry"] = next(
option_id for option_id, label in options.items()
if label == dummy_file.import_option
)
menu_info["state"] = c4d.LV_CHECKBOX_ENABLED
def SetDropDownMenu(self, root, userdata, dummy_file, column_id, entry):
if column_id != ID_IMPORT_OPTION:
return
#this is logical but does not do the trick ....
if not dummy_file.file_name.lower().endswith(".stp"):
return
options = {
ID_IMPORT_OPTION_DEFAULT: "Default",
ID_IMPORT_OPTION_HIGH: "High",
ID_IMPORT_OPTION_MEDIUM: "Medium",
ID_IMPORT_OPTION_LOW: "Low",
}
dummy_file.import_option = options.get(entry, dummy_file.import_option)
self.dialog.tree_view.Refresh()
class ListViewDropdownDialog(c4d.gui.GeDialog):
def __init__(self):
self.tree_view = None
self.file_list_view = DummyFileListView(self)
def CreateLayout(self):
self.SetTitle(PLUGIN_NAME)
tree_view_settings = c4d.BaseContainer()
tree_view_settings.SetBool(c4d.TREEVIEW_BORDER, c4d.BORDER_THIN_IN)
tree_view_settings.SetBool(c4d.TREEVIEW_HAS_HEADER, True)
tree_view_settings.SetBool(c4d.TREEVIEW_HIDE_LINES, True)
tree_view_settings.SetBool(c4d.TREEVIEW_RESIZE_HEADER, True)
tree_view_settings.SetBool(c4d.TREEVIEW_FIXED_LAYOUT, True)
tree_view_settings.SetBool(c4d.TREEVIEW_ALTERNATE_BG, True)
if c4d.GetC4DVersion() >= 24000:
tree_view_settings.SetInt32(c4d.TREEVIEW_VERTICAL_SPACE, 4)
self.tree_view = self.AddCustomGui(ID_TREE_VIEW, c4d.CUSTOMGUI_TREEVIEW, "", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 500, 220, tree_view_settings, )
if not self.tree_view:
return False
layout = c4d.BaseContainer()
layout.SetLong(ID_FILE_NAME, c4d.LV_TREE)
layout.SetLong(ID_IMPORT_OPTION, c4d.LV_DROPDOWN)
self.tree_view.SetLayout(2, layout)
self.tree_view.SetHeaderText(ID_FILE_NAME, "Dummy file")
self.tree_view.SetHeaderText(ID_IMPORT_OPTION, "STP import option")
self.tree_view.SetRoot(self.tree_view, self.file_list_view, None)
return True
def InitValues(self):
self.tree_view.Refresh()
return True
if __name__ == "__main__":
dialog = ListViewDropdownDialog()
dialog.Open(c4d.DLG_TYPE_MODAL, 0, -1, -1, 500, 220)