-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.py
414 lines (302 loc) · 17.8 KB
/
layout.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
import re
import tkinter as tk
import textwrap
import webbrowser
from init import (mainWindow, InitializeTkWindow)
from resolve import mediaPool
import config as c
from binSelector import BinSelector
from resolveBinTree import ResolveBinTree
from resolveImporter import ResolveImporter
from tkinter import ttk
from tkinter import Grid
from tkinter import messagebox
from tkinter import filedialog
from tkinter.messagebox import showerror, askokcancel, WARNING
mainFrame = ttk.Frame(mainWindow)
folderPathFrame = ttk.LabelFrame(mainFrame, text="Auto Importer")
controlFrame = ttk.Frame(mainFrame)
configFrame = ttk.LabelFrame(mainFrame, text="Auto Importer Configuration")
extraFunctionsFrame = ttk.LabelFrame(mainFrame, text="Extra Functions")
# for during importing
disabledControlsDuringImport = []
def initializeFrames():
mainFrame.grid(column=0, row=0, padx = 10, pady = 10)
for i in range(10):
mainFrame.grid_rowconfigure(i, weight=1)
mainFrame.grid_columnconfigure(i, weight=1)
folderPathFrame.grid(row = 0, sticky="nsew", pady=(0, 10), ipady=3)
configFrame.grid(row = 1, sticky="nsew", pady=(0, 10), ipady=3)
extraFunctionsFrame.grid(row = 2, sticky="nsew", pady=(0, 10), ipady=3)
controlFrame.grid(row = 3, sticky="nsew", pady=(0, 10), ipady=3)
Grid.columnconfigure(controlFrame, 0, weight = 1)
def initializeFolderPathFrame():
importFolderLabel = ttk.Label(folderPathFrame, text="Select Target Directory:")
importFolderLabel.grid(row = 0, columnspan=3, sticky=tk.W)
folderPathEntry = ttk.Entry(folderPathFrame, textvariable = c.folderPath)
folderPathEntry.grid(row = 1, columnspan=2, ipadx = 172, pady = 10, sticky=tk.EW)
disabledControlsDuringImport.append(folderPathEntry)
def folderPathEntry_FocusOut(e):
ResolveImporter.validateImportPath()
folderPathEntry.bind('<FocusOut>', folderPathEntry_FocusOut)
def openFolderButton_Click():
path = filedialog.askdirectory(
title='Select Target Directory to auto-import',
initialdir='/')
if path:
c.folderPath.set(path)
openFolderButton = ttk.Button(folderPathFrame, text='Select Folder', command=openFolderButton_Click, width=25)
disabledControlsDuringImport.append(openFolderButton)
openFolderButton.grid(column = 2, row = 1, columnspan=1, padx=(10, 0))
rootBinLabel = ttk.Label(folderPathFrame, text="Select a root bin:")
rootBinLabel.grid(row = 2, column=0, columnspan=2, sticky=tk.W)
def selectRootBin(e):
c.importToBin = rootBinSelector.getSelectedBin()
print(f"Initialized Root bin: {c.importToBin}")
rootBinSelector = BinSelector(folderPathFrame, c.importToBinPath, selectRootBin, False, width=23)
rootBinSelector.grid(row=2, column=2, columnspan=1, sticky=tk.W, padx=(10, 0))
disabledControlsDuringImport.append(rootBinSelector)
# Update the selected bin
selectRootBin(None)
def initializeConfigFrame():
currentRow = 0
ignoredFileExtensionsLabel = ttk.Label(configFrame, text="Ignored File Extensions:")
ignoredFileExtensionsLabel.grid(row=currentRow, column=0, columnspan=1, sticky=tk.EW)
ignoredFileExtensionsEntry = ttk.Entry(configFrame, textvariable = c.ignoredFileExtensions)
ignoredFileExtensionsEntry.grid(row=currentRow, column=1, columnspan=2, sticky=tk.EW, padx=(20, 0), ipadx=97)
disabledControlsDuringImport.append(ignoredFileExtensionsEntry)
def ignoredFileExtensionsEntry_FocusOut(e):
extensionsMatcher = re.compile(r'^[\w\-,]+$')
ignoredExtensionsString = c.ignoredFileExtensions.get().replace('.', '').replace(' ', '')
if not re.fullmatch(extensionsMatcher, ignoredExtensionsString):
showerror(title="Error", message="Invalid ignored extensions. Please list one or more file extensions separated by commas.")
return
c.ignoredFileExtensions.set(ignoredExtensionsString)
ignoredFileExtensionsEntry.bind('<FocusOut>', ignoredFileExtensionsEntry_FocusOut)
currentRow += 1
removeFilesLabel = ttk.Label(configFrame, text="Automatically remove from Resolve:")
removeFilesLabel.grid(row=currentRow, column=0, sticky=tk.EW, pady = (10,0))
def removeExtraFiles_Toggle():
isOn = removeExtraFilesCheckboxString.get() == "1"
c.removeExtraFiles.set(isOn)
if isOn:
messagebox.showwarning(title="Read before starting the Auto Importer", message=textwrap.dedent("""\
This will make the Auto Importer remove any unused file that is in Resolve but not in the Target Directory in Resolve.
This is designed to allow you to manage your files only in your filesystem and Resolve to match your changes.
Note: This will never delete files that are already in use."""))
removeExtraFilesCheckboxString = tk.StringVar(value="1" if c.removeExtraFiles.get() else "0")
removeExtraFilesCheckbox = ttk.Checkbutton(configFrame, text="Remove Extra Files", command=removeExtraFiles_Toggle,
variable=removeExtraFilesCheckboxString, onvalue="1", offvalue="0")
removeExtraFilesCheckbox.grid(row=currentRow, column=1, sticky=tk.W, padx=(20, 0), pady = (10,0))
disabledControlsDuringImport.append(removeExtraFilesCheckbox)
def removeEmptyBinsArchives_Toggle():
isOn = removeEmptyBinsCheckboxString.get() == "1"
c.removeEmptyBins.set(isOn)
if isOn:
messagebox.showwarning(title="Read before starting the Auto Importer", message=textwrap.dedent("""\
This will make the Auto Importer look for empty bins in Resolve and remove them.
This is designed to allow you to manage your files only in your filesystem and Resolve to match your changes.
Note: This will never delete folders with items in them.
Note: If you enabled the \"Remove Extra Files\" option — the Auto Importer will delete any folder that has only unused files in it."""))
removeEmptyBinsCheckboxString = tk.StringVar(value="1" if c.removeEmptyBins.get() else "0")
removeEmptyBinsCheckbox = ttk.Checkbutton(configFrame, text="Delete Empty Bins", command=removeEmptyBinsArchives_Toggle,
variable=removeEmptyBinsCheckboxString, onvalue="1", offvalue="0")
removeEmptyBinsCheckbox.grid(row=currentRow, column=2, sticky=tk.W, padx=(10, 0), pady = (10,0))
disabledControlsDuringImport.append(removeEmptyBinsCheckbox)
currentRow += 1
keepBinsLabel = ttk.Label(configFrame, text="Ignored Bins (never delete them):")
keepBinsLabel.grid(row=currentRow, column=0, sticky=tk.EW, pady = (10,0))
currentRow += 1
ignoredBinsEntry = ttk.Entry(configFrame, textvariable = c.ignoredBinsEntry)
ignoredBinsEntry.grid(row = currentRow, columnspan=2, ipadx = 172, pady = 10, sticky=tk.EW)
ignoredBinsEntry["state"] = "readonly"
def updateIgnoredBins(keepBinLabel):
c.ignoredBins.clear()
addedKeepBin = "," + ignoredBinSelector.getSelectedBin().getPath() if keepBinLabel else ""
binsEntry = c.ignoredBinsEntry.get() + addedKeepBin
binPaths = list(dict.fromkeys(binsEntry.split(",")))
binPaths.reverse()
masterBin = ResolveBinTree.get()
finalPaths = ""
for binPath in binPaths:
if not binPath:
continue
bin = masterBin.findBinFromPath(binPath)
if bin:
c.ignoredBins.insert(0, bin)
finalPaths = "," + bin.getPath() + finalPaths
if len(finalPaths) > 1:
finalPaths = finalPaths[1:]
c.ignoredBinsEntry.set(finalPaths)
clearLabel = "Clear"
def addIgnoredBin(e):
if ignoredBinSelector.getSelectedBin():
updateIgnoredBins(ignoredBinSelector.getSelectedBin().getPath())
else:
c.ignoredBins.clear()
c.ignoredBinsEntry.set("")
ignoredBinSelector.set(clearLabel)
ignoredBinSelector = BinSelector(configFrame, clearLabel, addIgnoredBin, True, clearLabel, width=23)
ignoredBinSelector.grid(row=currentRow, column=2, columnspan=1, sticky=tk.W, padx=(10, 0))
disabledControlsDuringImport.append(ignoredBinSelector)
updateIgnoredBins(None)
currentRow += 1
unzipArchivesLabel = ttk.Label(configFrame, text="Unzip & Delete archives:")
unzipArchivesLabel.grid(row=currentRow, column=0, sticky=tk.EW)
def unzipArchives_Toggle():
isOn = unzipArchivesCheckboxString.get() == "1"
c.unzipArchives.set(isOn)
if isOn:
messagebox.showwarning(title="Read before starting the Auto Importer", message="This will make the Auto Importer unzip all archives in the specified directory and then import the files inside. Useful when working with B-Roll websites.")
unzipArchivesCheckboxString = tk.StringVar(value="1" if c.unzipArchives.get() else "0")
unzipArchivesCheckbox = ttk.Checkbutton(configFrame, text="Unzip Archives", command=unzipArchives_Toggle,
variable=unzipArchivesCheckboxString, onvalue="1", offvalue="0")
unzipArchivesCheckbox.grid(row=currentRow, column=1, sticky=tk.W, padx=(20, 0))
disabledControlsDuringImport.append(unzipArchivesCheckbox)
def deleteUnzippedArchives_Toggle():
isOn = deleteUnzippedArchivesCheckboxString.get() == "1"
c.deleteUnzippedArchives.set(isOn)
if isOn:
messagebox.showwarning(title="Read before starting the Auto Importer", message="This will make the Auto Importer delete all unzipped archives after extraction from the import folder.")
deleteUnzippedArchivesCheckboxString = tk.StringVar(value="1" if c.deleteUnzippedArchives.get() else "0")
deleteUnzippedArchivesCheckbox = ttk.Checkbutton(configFrame, text="Delete Unzipped Archives", command=deleteUnzippedArchives_Toggle,
variable=deleteUnzippedArchivesCheckboxString, onvalue="1", offvalue="0")
deleteUnzippedArchivesCheckbox.grid(row=currentRow, column=2, sticky=tk.W, padx=(10, 0))
disabledControlsDuringImport.append(deleteUnzippedArchivesCheckbox)
def initializeExtraFunctionsFrame():
currentRow = 0
timelineBinLabel = ttk.Label(extraFunctionsFrame, text = "Automatically move all timelines to bin:")
timelineBinLabel.grid(row = currentRow, columnspan=2, pady = (10, 10), sticky=tk.EW)
def selectTimelinesBin(e):
c.timelinesBin = timelineBinSelector.getSelectedBin()
print(f"Initialized Timelines bin: {c.timelinesBin}")
timelineBinSelector = BinSelector(extraFunctionsFrame, c.timelinesBinPath, selectTimelinesBin, True, width=23)
timelineBinSelector.grid(row=currentRow, column=2, columnspan=3, pady = (10, 10), sticky=tk.E)
disabledControlsDuringImport.append(timelineBinSelector)
selectTimelinesBin(None)
currentRow += 1
compoundClipsBinLabel = ttk.Label(extraFunctionsFrame, text = "Automatically move all compound clips to bin:")
compoundClipsBinLabel.grid(row = currentRow, columnspan=2, pady = (0, 10), sticky=tk.EW)
def selectCompoundClipsBin(e):
c.compoundClipsBin = compounClipsBinSelector.getSelectedBin()
print(f"Initialized Compound clips bin: {c.compoundClipsBin}")
compounClipsBinSelector = BinSelector(extraFunctionsFrame, c.compoundClipsBinPath, selectCompoundClipsBin, True, width=23)
compounClipsBinSelector.grid(row=currentRow, column=2, columnspan=3, pady = (0, 10), sticky=tk.E)
disabledControlsDuringImport.append(compounClipsBinSelector)
selectCompoundClipsBin(None)
currentRow += 1
fusionCompsBinLabel = ttk.Label(extraFunctionsFrame, text = "Automatically move all fusion comps to bin:")
fusionCompsBinLabel.grid(row = currentRow, columnspan=2, pady = (0, 10), sticky=tk.EW)
def selectFusionCompsBin(e):
c.fusionCompsBin = fusionCompsBinSelector.getSelectedBin()
print(f"Initialized Fusion comps bin: {c.fusionCompsBin}")
fusionCompsBinSelector = BinSelector(extraFunctionsFrame, c.fusionCompsBinPath, selectFusionCompsBin, True, width=23)
fusionCompsBinSelector.grid(row=currentRow, column=2, columnspan=3, pady = (0, 10), sticky=tk.E)
disabledControlsDuringImport.append(fusionCompsBinSelector)
selectFusionCompsBin(None)
currentRow += 1
manuallyRemoveLabel = ttk.Label(extraFunctionsFrame, text="Manually Delete:")
manuallyRemoveLabel.grid(row=currentRow, column=0, sticky=tk.EW, padx=(0, 172))
def deleteUnusedFilesButton_Click():
unusedFiles = ResolveBinTree.get().getUnusedFiles()
filePaths = ""
i = 0
for unusedFile in unusedFiles:
if i >= 2:
filePaths += f"\nand {len(unusedFiles) - i} more...\n"
break
filePaths += f"{unusedFile.GetClipProperty()['File Path']}\n"
i += 1
confirm = askokcancel(title="Confirm Deletion of Unused Files",
message=f"{len(unusedFiles)} unused files will be deleted from both Resolve and your filesystem:\n\n{filePaths}\nThose can easily be found using a Smart Bin.\n\nNote: Use the help button to go to a page that explains that and more.", icon = WARNING)
if confirm:
print(f"[{c.importToBin.getName()}] Deleting {len(unusedFiles)} unused files.")
c.importToBin.deleteClips(unusedFiles, deleteFiles=True, refresh=True)
removeUnusedFilesButton = ttk.Button(extraFunctionsFrame, text="Unused Files", command=deleteUnusedFilesButton_Click)
removeUnusedFilesButton.grid(row=currentRow, column=1, sticky=tk.W, padx=(20, 0), ipadx=14)
disabledControlsDuringImport.append(removeUnusedFilesButton)
def removeMissingClipsButton_Click():
missingClips = ResolveBinTree.get().getMissingClips()
clipPaths = ""
i = 0
for clip in missingClips:
if i >= 9:
clipPaths += f"\nand {len(missingClips) - i} more...\n"
break
clipPaths += f"{clip.GetClipProperty()['File Path']}\n"
i += 1
confirm = askokcancel(title="Confirm Deletion of Missing Clips",
message=f"{len(missingClips)} missing clips will be removed from Resolve:\n\n{clipPaths}\nThose can easily be found using a Smart Bin.\n\nNote: Use the help button to go to a page that explains that and more.", icon = WARNING)
if confirm:
print(f"[{c.importToBin.getName()}] Deleting {len(missingClips)} missing clips.")
c.importToBin.deleteClips(missingClips, refresh=True)
removeMissingClipsButton = ttk.Button(extraFunctionsFrame, text="Missing Clips", command=removeMissingClipsButton_Click)
removeMissingClipsButton.grid(row=currentRow, column=2, sticky=tk.W, padx=(20, 0), ipadx=14)
disabledControlsDuringImport.append(removeMissingClipsButton)
def removeEmptyBinsButton_Click():
emptyBins = ResolveBinTree.get().getEmptyChildBins([c.importToBin], recursive=True, delete=False)
binPaths = ""
i = 0
for bin in emptyBins:
if i >= 9:
binPaths += f"\nand {len(emptyBins) - i} more...\n"
break
binPaths += f"{bin.getPath()}\n"
i += 1
confirm = askokcancel(title="Confirm Deletion of Empty Bins",
message=f"{len(emptyBins)} empty bins will be removed from Resolve. \n\n{binPaths}\nRemoving empty bins should not have any significant impact on your project.", icon = WARNING)
if confirm:
initialBin = mediaPool.GetCurrentFolder()
ResolveBinTree.get().getEmptyChildBins([c.importToBin], recursive=True, delete=True)
mediaPool.SetCurrentFolder(initialBin)
removeEmptyBinsButton = ttk.Button(extraFunctionsFrame, text="Empty Bins", command=removeEmptyBinsButton_Click)
removeEmptyBinsButton.grid(row=currentRow, column=3, sticky=tk.W, padx=(20, 0), ipadx=14)
disabledControlsDuringImport.append(removeEmptyBinsButton)
def initializeControlFrame():
tk.Label(controlFrame).grid(row = 0) # spacer
tk.Label(controlFrame, textvariable=c.importedMessage).grid(row = 1, sticky=tk.W) # message
progressIndicator = ttk.Progressbar(
controlFrame,
orient='horizontal',
mode='indeterminate',
length=260,
)
progressIndicator.grid(row = 2, column=0, columnspan=2, sticky=tk.W)
progressIndicator.grid_remove()
progressIndicator.start()
def helpButton_Click():
webbrowser.open(c.DOCUMENTATION_URL)
buttonWidth = 28
helpButton = ttk.Button(controlFrame, text="Help", command=helpButton_Click, width = buttonWidth)
helpButton.grid(row = 2, column=1, padx=(0,15))
startButton = ttk.Button(controlFrame, text='Start Importer', command=ResolveImporter.toggleImport, width=buttonWidth)
startButton.grid(row = 2, column=2)
def updateStartButtonText(*args):
if c.importing.get() == True:
for control in disabledControlsDuringImport:
control["state"] = "disabled"
text = "Stop Auto Importer"
progressIndicator.grid()
else:
for control in disabledControlsDuringImport:
control["state"] = "readonly" if isinstance(control, BinSelector) else "normal"
text = "Start Auto Importer"
progressIndicator.grid_remove()
startButton["text"] = text
c.importing.trace('w', updateStartButtonText)
def showWindow():
InitializeTkWindow()
def mainWindow_onClose():
if c.importing.get() == True:
messagebox.showerror("Quit", "Please stop the importer before quitting")
elif messagebox.askokcancel("Quit", "Do you want to quit?"):
c.saveCache()
mainWindow.destroy()
mainWindow.protocol("WM_DELETE_WINDOW", mainWindow_onClose)
mainWindow.mainloop()
def initializeWindow():
initializeFrames()
initializeFolderPathFrame()
initializeConfigFrame()
initializeExtraFunctionsFrame()
initializeControlFrame()