forked from openNuke/toolset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_load.py
230 lines (210 loc) · 10.1 KB
/
_load.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
import PySide
from PySide import QtGui
from PySide import QtCore
import nuke, nukescripts
import os, re
import json
import urllib2
global rootPath
rootPath = "https://raw.githubusercontent.com/opennuke/toolkit/master/" #path must start with http
########################
class toolSetWidget(QtGui.QWidget):
def __init__(self,parent=None):
global rootPath
self.rootPath = rootPath
QtGui.QWidget.__init__(self, parent)
self.shortCutList = []
self.loadToolPane()
def loadToolPane(self):
self.toolsDict = toolSetData().toolsDict #ToDo pass this to the class before registering the pane
self.tabs = QtGui.QTabWidget(self)
self.scriptsTab = QtGui.QWidget()
self.nodesTab = QtGui.QWidget()
self.scriptsMainLayout = QtGui.QVBoxLayout()
self.nodesMainLayout = QtGui.QVBoxLayout()
for cat in ['nodes', 'python' ]:
self.widgetDict = {}
types = self.toolsDict[cat].keys()
types.sort()
for type in types:
if self.toolsDict[cat][type]:
groupBox = QtGui.QGroupBox(type)
self.widgetDict[type] = {}
columnCount = 0
rowCount = 0
grid = QtGui.QGridLayout()
for tool in self.toolsDict[cat][type]:
## If tool has 'label list then it has multiple buttons with different calls ##
if isinstance(tool['label'], list) :
stepRange = len(tool['label'])
toolLabel = tool['label']
toolCall = tool['call']
columnCount += 1
else:
stepRange = 1
toolLabel = [tool['label']]
toolCall = [tool['call']]
for x in range(0,stepRange) :
button = QtGui.QPushButton(toolLabel[x])
button.setToolTip(tool['tooltip'])
grid.addWidget(button, rowCount, columnCount)
buttonRunner = lambda toolPath = tool['file'], call = toolCall[x]: self.runTool( toolPath, call )
self.connect( button, QtCore.SIGNAL( 'clicked()' ), buttonRunner )
self.widgetDict[type][toolLabel[x]] = button
if columnCount == 2:
columnCount = 0
rowCount += 1
else:
columnCount += 1
while 0 < columnCount < 3:
grid.addWidget(QtGui.QLabel(''), rowCount, columnCount)
columnCount += 1
print "button added: "+tool['file']
groupBox.setLayout(grid)
if cat == 'python':
self.scriptsMainLayout.addWidget(groupBox)
self.scriptsTab.setLayout(self.scriptsMainLayout)
if cat == 'nodes':
self.nodesMainLayout.addWidget(groupBox)
self.nodesTab.setLayout(self.nodesMainLayout)
self.tabs.addTab(self.scriptsTab, " Python ")
self.tabs.addTab(self.nodesTab, " Nodes ")
def runTool(self, toolPath, call):
toolPath = os.path.join(rootPath, os.path.split(toolPath)[1])
self.toolData = getData(toolPath).gotData
if os.path.splitext(os.path.split(toolPath)[1])[1]==".nk":
print os.path.splitext(os.path.split(toolPath)[1])[1]
clipboard = QtGui.QApplication.clipboard()
clipboard.setText(self.toolData)
if len(nuke.selectedNodes()):
sn = nuke.selectedNode()
np=nuke.nodePaste("%clipboard%")
g=nuke.selectedNode()
g.setInput(0, sn)
g.setXpos(sn.xpos())
g.setYpos(sn.ypos()+ 60)
else:
nuke.nodePaste("%clipboard%")
elif os.path.splitext(os.path.split(toolPath)[1])[1]==".py":
print call
#code_obj = compile(self.toolData, '<string>, 'exec')
#exec(code_obj) in globals(), locals()
#exec(call)
exec(self.toolData+'\n'+call)
########################
class UI_enumerationSelect(nukescripts.PythonPanel):
def __init__(self,labelChoices,title):
self.title=title
self.labelChoices=labelChoices
nukescripts.PythonPanel.__init__(self, self.title)
self.typeKnob = nuke.Enumeration_Knob('select', 'Select release', self.labelChoices)
self.addKnob(self.typeKnob)
########################
class toolSetData():
def __init__(self):
global rootPath
self.rootPath = rootPath
self.toolsDict={}
## Select Location of Release Path ##
if self.licence():
## Get Release Path Dict ##
self.toolLoadJsonDict = getData(os.path.join(self.rootPath, "_load.json")).gotData
selectedToolList=[]
selectedToolList = self.toolLoadJsonDict[self.selectToolList()]
## load self.toolDict and add to self.toolsDict ##
for toolName in selectedToolList:
print "json: "+toolName
self.toolDict = getData(os.path.join(self.rootPath, toolName +'.json')).gotData
self.addToolDict()
def selectToolList(self):
#### Select witch release to load ###
toolChoices=self.toolLoadJsonDict.keys()
pRelease = UI_enumerationSelect(toolChoices,'Select NukeTool selection from repository?')
if pRelease.showModalDialog():
self.selectedToolListName = pRelease.typeKnob.value()
return self.selectedToolListName
def addToolDict(self):
## load self.toolDict and add to self.toolsDict ##
toolType = self.toolDict['type']
category= self.toolDict['category']
label = self.toolDict['label']
file = self.toolDict['file']
tooltip = self.toolDict['tooltip']
originalAuthor = self.toolDict['originalAuthor']
dateCreated = self.toolDict['dateCreated']
status = self.toolDict['status']
documentation = self.toolDict['documentation']
source = self.toolDict['source']
call = self.toolDict['call']
## HACK - tehre must be a cleaner way of doing this? ##
## Check if [toolType][category] exsits and if save so old 'toolList and extend with new tool ##
if toolType in self.toolsDict:
if category in self.toolsDict[toolType]:
toolList=self.toolsDict[toolType][category]
else:
toolList=[]
else:
toolList=[]
toolList.extend([{'call':call,'file':file,'label':label,'tooltip':tooltip,'originalAuthor':originalAuthor,'dateCreated':dateCreated,'status':status,'source':source}])
## if [toolType][category] exists then add rather than replace ##
if toolType in self.toolsDict.keys():
self.toolsDict[toolType].update({category:[]})
else:
self.toolsDict.update({toolType:{category:[]}})
## Add the toolList
self.toolsDict[toolType][category] = self.toolsDict[toolType][category]+toolList
def licence(self):
return nuke.ask(getData(os.path.join(self.rootPath, "LICENCE")).gotData)
########################
class isRootPathLocal():
def __init__(self):
global rootPath
pLoc = UI_enumerationSelect(['web','local'], '_load.json file location?' )
if pLoc.showModalDialog():
selectedLocationLabel = pLoc.typeKnob.value()
if selectedLocationLabel=='local':
rootPath = os.path.split(nuke.getFilename('Select _load.json', '_load.json'))[0]
########################
class getData():
def __init__(self,path):
if path[0:4] == "http":
try:
response = urllib2.urlopen(path)
except urllib2.request.URLError:
nuke.message('errr. path to '+path+' not reached')
else:
response = open((path), 'r')
if os.path.splitext(os.path.split(path)[1])[1] == '.json':
self.gotData = json.load(response)
else:
self.gotData = response.read()
response.close()
########################
def runPane():
paneExistsCheck = nuke.getPaneFor('org.vfxwiki.nuketoolkit')
if not paneExistsCheck:
pane = nuke.getPaneFor('Properties.1')
nukescripts.registerWidgetAsPanel('toolSetWidget', 'openNuke', 'org.vfxwiki.nuketoolkit', True).addToPane(pane)
else:
nuke.message("errr. unable to load pane, as it already exists. \nClose the 'WebTools' pane, and try again.")
def setUpMenus():
#Set up base menu for scripts and nodes:
toolbar = nuke.menu("Nuke")
menuEdit = toolbar.findItem('Edit').items()
count=0
for x in menuEdit:
count=count+1
if x.name() == 'Node':
menuIndex=count
menuTopEdit = toolbar.addMenu('Edit/Scripts', index=menuIndex)
toolSetBar = nuke.menu("Nodes").findItem('ToolSets')
toolSetMenu = toolSetBar.addMenu('WebTools', index=3)
nukescripts.traversePluginPaths(toolSetMenu, False, [], True)
########################
def run():
isRootPathLocal() ## set the 'global rootPath'
runPane() ## create the panel running the ToolSetWidget() to load toolSetData()
run()
if 1==3:
setUpMenus()
########################