-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_LUT_Explorer_utility.py
212 lines (166 loc) · 8.45 KB
/
ui_LUT_Explorer_utility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# LUT Explorer Utility. Requires DaVinci Resolve Studio 17
# Copyright (c) 2021 Bryan Randell
import sys
import os
if sys.platform.startswith('win'):
# lut_folder = "C:\\ProgramData\\Blackmagic Design\\DaVinci Resolve\\Support\\LUT"
lut_folder = "C:\\ProgramData\\Blackmagic Design\\DaVinci Resolve\\Support\\LUT\\Film Looks"
else:
lut_folder = "Library/Application Support/Blackmagic Design/DaVinci Resolve/LUT"
"""
Useless in Davinci because the resolve object is already called natively
import DaVinciResolveScript
try:
import DaVinciResolveScript as dvr
resolve = dvr.scriptapp('Resolve')
except:
from python_utils.python_get_resolve import GetResolve
resolve = GetResolve()
"""
from lut_file_reader import lut
# Row Creation
def list_lut_row_creation(lut_path, tree_item, tree_LutID, img_thumbnail):
item_num = 1
for root, dir, files in os.walk(lut_path):
for file in files:
if file.endswith('cube') or file.endswith('dat'):
item_row = tree_item[tree_LutID].NewItem()
# item_row.Icon[0] = ui.Icon({'File': 'C:\\ProgramData\\Blackmagic Design\\DaVinci Resolve\\Support\\Workflow Integration Plugins\\img\\icon.png'})
# item_row.Text[0] = ui.Icon({'File': 'C:\\ProgramData\\Blackmagic Design\\DaVinci Resolve\\Support\\Workflow Integration Plugins\\img\\icon.png'})
# item_row.Icon[0] = ui.Icon({'File': lut(os.path.join(root, file), file.split('.')[0])})
item_row.Icon[0] = ui.Icon({'File': lut(img_thumbnail, os.path.join(root, file))})
item_row.Text[0] = '{:03d}'.format(item_num)
item_row.Text[1] = '{}'.format(file)
item_row.Text[2] = '{}'.format(os.path.join(root, file))
tree_item[tree_LutID].AddTopLevelItem(item_row)
item_num += 1
def list_lut_row_creation_filtered(lut_path, tree_item, tree_LutID, filter_string,img_thumbnail):
item_num = 1
for root, dir, files in os.walk(lut_path):
for file in files:
if file.endswith('cube') or file.endswith('dat'):
if file.lower().find(filter_string.lower()) != -1:
item_row = tree_item[tree_LutID].NewItem()
item_row.Icon[0] = ui.Icon({'File': lut(img_thumbnail, os.path.join(root, file))})
item_row.Text[0] = '{:03d}'.format(item_num)
item_row.Text[1] = '{}'.format(file)
item_row.Text[2] = '{}'.format(os.path.join(root, file))
print(file)
print(filter_string)
tree_item[tree_LutID].AddTopLevelItem(item_row)
item_num += 1
# if file.lower().find(filter_string.lower()) != -1:
# print(item_num)
# the method .GetCurrentClipThumbnailImage() only works in the color page
if resolve.GetCurrentPage() != 'color':
resolve.OpenPage('color')
project_manager = resolve.GetProjectManager()
current_project = project_manager.GetCurrentProject()
print(current_project.GetName())
timeline = current_project.GetCurrentTimeline()
img_thumbnail = timeline.GetCurrentClipThumbnailImage()
# some element IDs
winID = "com.blackmagicdesign.resolve.LUT_utility"
# should be unique for single instancing
line_edit_searchID = 'LineEditSearch'
button_refreshID = 'Button_Refresh'
button_explorerID = "Button_Explorer"
tree_LutID = 'Tree_LUT'
# calling DavinciResolve UI in Workflow Integration
ui = fusion.UIManager
dispatcher = bmd.UIDispatcher(ui)
# # check for existing instance
# main_window = ui.FindWindow(winID)
# if main_window:
# main_window.Show()
# main_window.Raise()
# exit()
# otherwise, we set up a new window, with HTML header (using the Examples logo.png)
header = '<html><body><h1 style="horizontal-align:middle;">'
header = header + '<b>DaVinci Resolve LUT Explorer Utility</b>'
header = header + '</h1></body></html>'
explication_text = "Left click on the LUT from the list above\nto add it on your active Timeline Clip first node"
# define the window UI layout
main_window = dispatcher.AddWindow({'ID': winID, 'Geometry': [100, 100, 1000, 500], 'WindowTitle': "DaVinci Resolve LUT Explorer Utility", },
ui.VGroup([
ui.Label({'Text': header, 'Weight': 0.2, 'Font': ui.Font({'Family': "Times New Roman"}), "Alignment" : { "AlignHCenter" : True , "AlignTop" : True }}),
ui.HGroup({ 'Weight': 0.1 }, [
ui.LineEdit({'ID': line_edit_searchID, 'Text': '', 'PlaceholderText': 'Filter LUTs by Name', 'Events': {'EditingFinished': True}}),
ui.Button({'ID': button_refreshID, 'Text': 'Refresh List'},)
]),
ui.HGroup({ 'Weight': 0.1 }, [
ui.Label({'Text': 'LUT List', 'Weight': 0.1, 'Font': ui.Font({'Family': "Times New Roman", 'PixelSize': 20})}),
ui.Button({'ID': button_explorerID, 'Text': 'Select LUT Folder'}, ),
]),
# ui.HGroup({'Weight': 0.2}, [
# ui.Label({'Text': "Current LUT folder :{}".format(lut_folder), 'Weight': 0.1, 'Font': ui.Font({'Family': "Times New Roman", 'PixelSize': 14})}),
# ]),
ui.Tree({'ID': tree_LutID, 'UniformRowHeights':False,'IconSize':[img_thumbnail['width'],img_thumbnail['height']],"ItemsExpandable":True, "ExpandsOnDoubleClick": True, 'SortingEnabled': True,'Events' : {'Move': True, 'ItemClicked': True}, }),
ui.HGroup({ 'Weight': 0.2 }, [
ui.Label({'Text': explication_text, 'Weight': 0.1, 'Font': ui.Font({'Family': "Times New Roman", 'PixelSize': 14}), "Alignment" : { "AlignHCenter" : True , "AlignTop" : True }}),
]),
]))
# Tree Item definition
main_window_item = main_window.GetItems()
# Header/Column Creation
column_header = main_window_item[tree_LutID].NewItem()
# column_header.Icon[0] = "Icon"
column_header.Text[0] = 'Index'
column_header.Text[1] = 'Name'
column_header.Text[2] = 'LUT PATH'
main_window_item[tree_LutID].SetHeaderItem(column_header)
main_window_item[tree_LutID].ColumnCount = 3
main_window_item[tree_LutID].ColumnWidth[0] = 300
main_window_item[tree_LutID].ColumnWidth[1] = 300
main_window_item[tree_LutID].ColumnWidth[2] = 100
list_lut_row_creation(lut_folder, main_window_item, tree_LutID,img_thumbnail)
# Functions for Event handlers
def OnClose(ev):
dispatcher.ExitLoop()
def OnClickRefresh(ev):
"""
Clear the timeline list and loop over timeline indexes
:param ev:
:return:
"""
main_window_item[tree_LutID].Clear()
timeline = current_project.GetCurrentTimeline()
img_thumbnail = timeline.GetCurrentClipThumbnailImage()
list_lut_row_creation(lut_folder, main_window_item, tree_LutID, img_thumbnail)
print('List Refreshed')
# def OnClickFilter(ev):
# print(tree_item['LineEditSearch'].SelectedText())
def OnTextChanged(ev):
# print('test has changed')
main_window_item[tree_LutID].Clear()
timeline = current_project.GetCurrentTimeline()
img_thumbnail = timeline.GetCurrentClipThumbnailImage()
list_lut_row_creation_filtered(lut_folder,
main_window_item,
tree_LutID,
main_window_item[line_edit_searchID].Text,
img_thumbnail)
def OnClickTree(ev):
print(main_window_item[tree_LutID].CurrentItem().Text[2])
current_project.GetCurrentTimeline().GetCurrentVideoItem().SetLUT(1, main_window_item[tree_LutID].CurrentItem().Text[2])
def OnClickExplorer(ev):
global lut_folder
lut_folder = fusion.RequestDir('C:\\ProgramData\\Blackmagic Design\\DaVinci Resolve\\Support\\LUT')
print(lut_folder)
main_window_item[tree_LutID].Clear()
timeline = current_project.GetCurrentTimeline()
img_thumbnail = timeline.GetCurrentClipThumbnailImage()
list_lut_row_creation(lut_folder, main_window_item, tree_LutID, img_thumbnail)
# assign event handlers
main_window.On[winID].Close = OnClose
main_window.On[line_edit_searchID].EditingFinished = OnTextChanged
main_window.On[tree_LutID].ItemClicked = OnClickTree
main_window.On[button_refreshID].Clicked = OnClickRefresh
main_window.On[button_explorerID].Clicked = OnClickExplorer
# main_window.On['Button_Filter'].Clicked = OnClickFilter
# main_window.On['Tree'].ItemDoubleClicked = OnDoubleClickTree
# Main dispatcher loop
main_window.Show()
dispatcher.RunLoop()