-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathreplacePaths.py
88 lines (55 loc) · 2.18 KB
/
replacePaths.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
#This Source Code Form is subject to the terms of the Mozilla Public
#License, v. 2.0. If a copy of the MPL was not distributed with this
#file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#Created by Fabrice Fernandez on 19/06/2019.
import os
from NatronGui import *
from PySide.QtGui import *
import NatronEngine
# REPLACE 'READ' OR 'WRITE' NODE PATH #
def replacePaths():
# get current Natron instance running in memory #
app = natron.getGuiInstance(0)
# create dialog window #
dialog = app.createModalDialog()
# set dialog title #
dialog.setWindowTitle("Replace paths")
# set dialog margins #
dialog.setContentsMargins(0, 0, 10, 10)
# set window size #
dialog.resize( 400, 100 )
# UI creation #
line01 = dialog.createStringParam("line01","")
line01.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
line02 = dialog.createStringParam("line02","")
line02.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# user list #
myList = dialog.createChoiceParam("list00","Nodes : ")
entries = [ ("Selected", ""),("All", "") ]
myList.setOptions(entries)
myList.setDefaultValue("Selected")
myList.restoreDefaultValue()
sep01 = dialog.createSeparatorParam("sep01","")
oldPath = dialog.createPathParam("oldPath","Source path : ")
newPath = dialog.createPathParam("newPath","Destination path : ")
line03 = dialog.createStringParam("line03","")
line03.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
sep02 = dialog.createSeparatorParam("sep02","")
# Refresh UI #
dialog.refreshUserParamsGUI()
if dialog.exec_():
userChoice = myList.getValue()
if userChoice == 1:
app.selectAllNodes()
# get selected nodes #
selectedNodes = app.getSelectedNodes()
for currentNode in selectedNodes:
myID = currentNode.getPluginID()
if myID == "fr.inria.built-in.Read" :
oldPathParamValue = oldPath.getValue()
newPathParamValue = newPath.getValue()
currentPath = str(currentNode.getParam('filename').get())
print ('Old path : ' + currentPath)
currentPath = currentPath.replace(oldPathParamValue,newPathParamValue)
print ('New path : ' + currentPath)
oldReadPath = currentNode.getParam('filename').set(currentPath)