Open3
Fusion Script ui.Treeのサンプルコード
コンポ内のノードのパススルー、名前、種別がわかるTreeをUIManagerで出力
import DaVinciResolveScript as dvr_script
resolve = dvr_script.scriptapp("Resolve")
fusion = dvr_script.scriptapp("Fusion")
ui = fusion.UIManager
dispatcher = dvr_script.UIDispatcher(ui)
comp = fusion.GetCurrentComp()
layout = ui.Tree({"ID":"Tree_1","FixedSize":[350,400],"ColumnCount":4})
win = dispatcher.AddWindow({"ID":"sample_window"},layout)
TreeList = [["","Active","Name","Type"],[0,50,120,120]]
for i,ColumnWidth in enumerate(TreeList[1]):
win.Find("Tree_1").ColumnWidth[i] = ColumnWidth
win.Find("Tree_1").SetHeaderLabels(TreeList[0])
nodes = comp.GetToolList()
NodeParameterList = [node.Name for node in nodes.values()]
for i,name in enumerate(NodeParameterList):
item = win.Find("Tree_1").NewItem()
item.Text[1] = "✅" if nodes[1 + i].GetAttrs('TOOLB_PassThrough') == False else "🔳"
item.Text[2] = name
item.Text[3] = nodes[1 + i].GetAttrs("TOOLS_RegID")
win.Find('Tree_1').AddTopLevelItem(item)
def on_close(ev):
dispatcher.ExitLoop()
win.Hide()
win.On.sample_window.Close = on_close
win.Show()
dispatcher.RunLoop()
Treeのアイテムクリックのイベントハンドラを使い、特定の列のアイテムを選択したときにトリガーするように動作
このサンプルコードでは、1列目の「Active」をクリックした際にTree上のチェックボックスを切り替えとパススルーの切り替えを行う
import DaVinciResolveScript as dvr_script
resolve = dvr_script.scriptapp("Resolve")
fusion = dvr_script.scriptapp("Fusion")
ui = fusion.UIManager
dispatcher = dvr_script.UIDispatcher(ui)
comp = fusion.GetCurrentComp()
layout = ui.Tree({"ID":"Tree_1","FixedSize":[350,400],"ColumnCount":4})
win = dispatcher.AddWindow({"ID":"sample_window"},layout)
TreeList = ["","Active","Name","Type"],[0,50,120,120]
for i,ColumnWidth in enumerate(TreeList[1]):
win.Find("Tree_1").ColumnWidth[i] = ColumnWidth
win.Find("Tree_1").SetHeaderLabels(TreeList[0])
nodes = comp.GetToolList()
NodeParameterList = [node.Name for node in nodes.values()]
for i,name in enumerate(NodeParameterList):
item = win.Find("Tree_1").NewItem()
item.Text[1] = "✅" if nodes[1 + i].GetAttrs('TOOLB_PassThrough') == False else "🔳"
item.Text[2] = name
item.Text[3] = nodes[1 + i].GetAttrs("TOOLS_RegID")
win.Find('Tree_1').AddTopLevelItem(item)
def OnCurrentItemChanged(ev):
CurrentItem = win.Find("Tree_1").CurrentItem()
NodeName = CurrentItem.Text[2]
comp.SetActiveTool(comp.FindTool(NodeName))
win.On.Tree_1.CurrentItemChanged = OnCurrentItemChanged
def OnCurrentColumnSelect(ev):
CurrentItem = win.Find("Tree_1").CurrentItem()
CurrentColoumnItem = win.Find("Tree_1").CurrentColumn()
ActiveTool = comp.ActiveTool
if CurrentColoumnItem == 1:
CurrentItem.Text[1] = "🔳" if CurrentItem.Text[1] == "✅" else "✅"
NodeEnabled = False if ActiveTool.GetAttrs("TOOLB_PassThrough") else True
ActiveTool.SetAttrs({"TOOLB_PassThrough":NodeEnabled})
else:
pass
win.On.Tree_1.ItemClicked = OnCurrentColumnSelect
def on_close(ev):
dispatcher.ExitLoop()
win.Hide()
win.On.sample_window.Close = on_close
win.Show()
dispatcher.RunLoop()
検索バーをLineEditで追加して部分検索を可能にした
LineEdit内のテキストが変更がイベントハンドラとしてトリガーし、ツリー内のアイテムが更新される
import DaVinciResolveScript as dvr_script
import sys
resolve = dvr_script.scriptapp("Resolve")
fusion = dvr_script.scriptapp("Fusion")
ui = fusion.UIManager
dispatcher = dvr_script.UIDispatcher(ui)
comp = fusion.GetCurrentComp()
layout = ui.VGroup([ui.LineEdit({"ID":"LineEdit_1","FixedSize":[350,20],"PlaceholderText":"Search"}),
ui.Tree({"ID":"Tree_1","FixedSize":[350,400],"ColumnCount":4}),
])
win = dispatcher.AddWindow({"ID":"sample_window"},layout)
TreeList = ["","Active","Name","Type"],[0,50,120,120]
for i,ColumnWidth in enumerate(TreeList[1]):
win.Find("Tree_1").ColumnWidth[i] = ColumnWidth
win.Find("Tree_1").SetHeaderLabels(TreeList[0])
def regular_insert_data():
NameList_regular = [node.Name for node in list(comp.GetToolList().values())]
win.Find("Tree_1").Clear()
for i,name in enumerate(NameList_regular):
item = win.Find("Tree_1").NewItem()
item.Text[1] = "✅" if comp.GetToolList()[1 + i].GetAttrs('TOOLB_PassThrough') == False else "🔳"
item.Text[2] = name
item.Text[3] = comp.GetToolList()[1 + i].GetAttrs("TOOLS_RegID")
win.Find('Tree_1').AddTopLevelItem(item)
def filter_insert_data():
Text = str(win.Find("LineEdit_1").Text)
NameFilter = win.Find("Tree_1").FindItems(Text,{"MatchContains":True},2)
NameList_filter = [node.Text[2] for node in list(NameFilter.values())]
win.Find("Tree_1").Clear()
for i,name in enumerate(NameList_filter):
item = win.Find("Tree_1").NewItem()
item.Text[1] = "✅" if comp.GetToolList()[1 + i].GetAttrs('TOOLB_PassThrough') == False else "🔳"
item.Text[2] = name
item.Text[3] = comp.GetToolList()[1 + i].GetAttrs("TOOLS_RegID")
win.Find('Tree_1').AddTopLevelItem(item)
def OnCurrentItemChanged(ev):
CurrentItem = win.Find("Tree_1").CurrentItem()
NodeName = CurrentItem.Text[2]
comp.SetActiveTool(comp.FindTool(NodeName))
win.On.Tree_1.CurrentItemChanged = OnCurrentItemChanged
def OnCurrentColumnSelect(ev):
CurrentItem = win.Find("Tree_1").CurrentItem()
CurrentColoumnItem = win.Find("Tree_1").CurrentColumn()
ActiveTool = comp.ActiveTool
if CurrentColoumnItem == 1:
CurrentItem.Text[1] = "🔳" if CurrentItem.Text[1] == "✅" else "✅"
NodeEnabled = False if ActiveTool.GetAttrs("TOOLB_PassThrough") else True
ActiveTool.SetAttrs({"TOOLB_PassThrough":NodeEnabled})
else:
pass
win.On.Tree_1.ItemClicked = OnCurrentColumnSelect
def OnLineEditTextChanged(ev):
Text = str(win.Find("LineEdit_1").Text)
if Text == "":
regular_insert_data()
else:
filter_insert_data()
win.On.LineEdit_1.TextChanged = OnLineEditTextChanged
def OnWindowShow(ev):
regular_insert_data()
win.On['sample_window'].Open = OnWindowShow
def OnWindowClose(ev):
dispatcher.ExitLoop()
win.Hide()
win.On.sample_window.Close = OnWindowClose
regular_insert_data()
win.Show()
dispatcher.RunLoop()