-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectExplorerUI.py
487 lines (363 loc) · 14.9 KB
/
projectExplorerUI.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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
import time
import os
import sys
import subprocess
import shutil
try:
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2 import __version__
except ImportError:
from PySide.QtCore import *
from PySide.QtGui import *
from PySide import __version__
import projectExplorer_core
reload(projectExplorer_core)
core = projectExplorer_core.ExplorerCore()
currentDir = os.path.dirname(__file__).replace("\\", '/')
__VERISON__ = "1.2"
# V1.0 All main functions working
# V1.1 Fix Wrong configure path
# V1.2 Support shot's sub-folder
class PreferenceWindow(QDialog) :
def __init__(self, parent = None):
super (PreferenceWindow, self).__init__(parent)
mainLayout = QGridLayout()
formLayout = QFormLayout()
self.rootPath_input = QLineEdit(self)
self.rootPath_input.setText(core.configData['EXT_VAR']['ROOT'])
formLayout.addRow("Root path:", self.rootPath_input)
self.submitbtn = QPushButton(self)
self.submitbtn.setText("Save")
mainLayout.addLayout( formLayout,0,0, columnSpan = 3)
mainLayout.addWidget(self.submitbtn, 1,0)
self.setLayout(mainLayout)
self.submitbtn.clicked.connect(self.submit_onClicked)
def submit_onClicked(self, *args):
projectExplorer_core.updatePref(data = {"ROOT":self.rootPath_input.text()})
self.close()
class ExplorerWindow(QMainWindow):
setting = settings = QSettings( "Shape and Light", "Nuke Explorer")
def __init__(self, parent = None):
super(ExplorerWindow, self).__init__(parent)
self.InitUI()
self.setupUI()
self.initConnect()
def InitUI(self):
self.setWindowTitle("Nuke project explorer V%s"%__VERISON__)
mainWidget = QWidget(self)
self.menuBar = QMenuBar(self)
self.settingMenu = QMenu("&Setting", self)
self.preferenceAction = QAction("&Preference", self, triggered = self.callPrefWindow)
self.settingMenu.addAction(self.preferenceAction)
self.helpMenu = QMenu("&Help", self)
self.openDocument = QAction("&Open Document", self, triggered = self.callDocumentLink)
self.openRepo = QAction("&Source code", self, triggered = self.callGithubLink)
self.helpMenu.addAction(self.openDocument)
self.helpMenu.addAction(self.openRepo)
self.menuBar.addMenu(self.settingMenu)
self.menuBar.addMenu(self.helpMenu)
mainLayout = QVBoxLayout()
mainLayout.setContentsMargins(5,5,5,5)
self.headWidget = HeaderWidget(self)
self.fileWidget = fileWidget(self)
self.buttonLayout = QHBoxLayout()
self.saveButton = QPushButton("Save++", self)
self.openButton = QPushButton("Open", self)
verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.buttonLayout.addItem(verticalSpacer)
self.buttonLayout.addWidget(self.saveButton)
self.buttonLayout.addWidget(self.openButton)
self.buttonLayout.setStretch(0,1)
mainWidget.setLayout(mainLayout)
self.setCentralWidget(mainWidget)
mainLayout.addWidget(self.headWidget)
mainLayout.addWidget(self.fileWidget)
mainLayout.addLayout(self.buttonLayout)
mainLayout.setStretch(1,1)
self.setMenuBar(self.menuBar)
def setupUI(self):
# Restore Data
self.settings.beginGroup("MainWindow")
self.restoreGeometry(self.settings.value("geometry"))
self.restoreState(self.settings.value("state"))
self.settings.endGroup()
prev_project = self.settings.value("projectData/project")
prev_shot = self.settings.value("projectData/shot")
print prev_project
# Setup
# Set previous project
projectList = core.listProjects()
self.headWidget.projectComboBox.addItems(projectList)
if prev_project in projectList :
index = self.headWidget.projectComboBox.findText(prev_project, Qt.MatchExactly)
self.headWidget.projectComboBox.setCurrentIndex(index)
# Set file current project
self.fileWidget.setProject(self.currentProject)
# Set previous shot
if self.fileWidget.shotListWidget.findItems(prev_shot, Qt.MatchExactly):
shotItem = self.fileWidget.shotListWidget.findItems(prev_shot, Qt.MatchExactly)
self.fileWidget.shotListWidget.setCurrentItem(shotItem[0])
self.fileWidget.updateFileList()
def initConnect(self):
self.headWidget.projectComboBox.activated.connect(lambda : self.fileWidget.setProject(self.currentProject))
self.saveButton.clicked.connect(self.save_OnClicked)
self.openButton.clicked.connect(self.open_onClicked)
self.fileWidget.shotListWidget.itemClicked.connect(self.fileWidget.updateFileList)
self.fileWidget.fileListWidget.itemDoubleClicked.connect(self.open_onClicked)
def closeEvent(self, event):
print "Saving current state data ..."
self.settings.beginGroup("MainWindow")
self.settings.setValue("geometry", self.saveGeometry())
self.settings.setValue("state", self.saveState())
self.settings.endGroup()
self.settings.beginGroup("projectData")
self.settings.setValue("project", self.currentProject)
self.settings.setValue("shot", self.fileWidget.currentShot)
self.settings.endGroup()
def save_OnClicked(self):
savePath = core.saveIncrement(self.currentProject, self.fileWidget.currentShot)
projectExplorer_core.saveFrame(thumbnailPath = projectExplorer_core.thumbnailPath(savePath))
self.fileWidget.updateFileList()
def open_onClicked(self):
print self.fileWidget.currentFile
core.openScript(self.fileWidget.currentFile)
def callPrefWindow(self):
prefWin = PreferenceWindow(parent = self)
prefWin.exec_()
def callDocumentLink(self):
print "callDocumentLink"
QDesktopServices.openUrl(QUrl('https://github.com/Shayen/SAL-Nuke-ProjectExplorer'))
def callGithubLink(self):
print "callGithubLink"
QDesktopServices.openUrl(QUrl('https://github.com/Shayen/SAL-Nuke-ProjectExplorer'))
@property
def currentProject(self):
return self.headWidget.projectComboBox.currentText()
class thumbnailWidget(QWidget):
placeHolder_path = currentDir + '/image/image_placeholder.jpg'
placeHolder_pixmap = QPixmap(placeHolder_path)
def __init__(self, parent= None):
super(thumbnailWidget, self).__init__(parent)
mainLayout = QVBoxLayout()
self.thumbnail = QLabel("- place holder -", self)
mainLayout.addWidget(self.thumbnail)
self.setLayout(mainLayout)
self.setThumbnail(self.placeHolder_path)
def setThumbnail(self, imagepath):
if not os.path.exists(imagepath):
imagepath = self.placeHolder_path
# pixmap =QPixmap(imagepath)
img = QImage(imagepath)
scaled_percent = 280.0 / max(img.width(),img.height())
pixmap = QPixmap(img).scaled(QSize(img.width()*scaled_percent,img.height()*scaled_percent, mode = Qt.SmoothTransformation))
self.thumbnail.setPixmap(pixmap)
class HeaderWidget(QWidget):
def __init__(self, parent= None):
super(HeaderWidget, self).__init__(parent)
mainLayout = QVBoxLayout()
self.title = QLabel("Nuke Project Explorer", self)
newfont = QFont("Arial Black", 18)
self.title.setFont(newfont)
self.projectLayout = QHBoxLayout()
self.projectLabel = QLabel("Project : ", self)
self.projectComboBox = QComboBox(self)
self.projectSetting = QPushButton(self)
self.projectSetting.setIcon(QIcon(currentDir + "/image/setting.png"))
verticalSpacer = QSpacerItem(20, 10, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.projectLayout.addWidget(self.projectLabel)
self.projectLayout.addWidget(self.projectComboBox)
self.projectLayout.addWidget(self.projectSetting)
self.projectLayout.addItem(verticalSpacer)
self.projectLayout.setStretch(3,1)
mainLayout.addWidget(self.title)
mainLayout.addLayout(self.projectLayout)
self.setLayout(mainLayout)
class fileWidget(QWidget):
project = ''
def __init__(self, parent= None):
super(fileWidget, self).__init__(parent)
mainLayout = QHBoxLayout()
ShotLayout = QVBoxLayout()
self.thumbnailWidget = thumbnailWidget(self)
self.shotListWidget = QListWidget(self)
self.shotLabelLayout = QHBoxLayout()
self.addShotButton = QPushButton("+",self)
self.addShotButton.setMaximumWidth(20)
verticalSpacer = QSpacerItem(20, 10, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.shotLabelLayout.addWidget(QLabel(self.tr("Shot : ")))
self.shotLabelLayout.addItem(verticalSpacer)
self.shotLabelLayout.addWidget(self.addShotButton)
self.shotLabelLayout.setStretch(1,1)
ShotLayout.addWidget(self.thumbnailWidget)
ShotLayout.addLayout(self.shotLabelLayout)
ShotLayout.addWidget(self.shotListWidget)
ShotLayout.setStretch(3,1)
self.fileListWidget = QListWidget(self)
self.fileListWidget.setContextMenuPolicy(Qt.CustomContextMenu)
mainLayout.addLayout(ShotLayout)
mainLayout.addWidget(self.fileListWidget)
mainLayout.setStretchFactor(ShotLayout,0)
mainLayout.setStretchFactor(self.fileListWidget,1)
self.setLayout(mainLayout)
self.setupUI()
self.initConnect()
def initConnect(self):
self.fileListWidget.itemClicked.connect(self.setThumbnail)
self.addShotButton.clicked.connect(self.addShot)
# Add right click menu
self.fileListWidget.connect(
self.fileListWidget, SIGNAL("customContextMenuRequested(QPoint)"),
self.fileListWidgetItemRightClicked)
def setupUI(self):
pass
def setThumbnail(self):
thumbnailPath = projectExplorer_core.thumbnailPath(self.currentFile)
if not os.path.exists(thumbnailPath):
thumbnailPath = self.thumbnailWidget.placeHolder_path
self.thumbnailWidget.setThumbnail(thumbnailPath)
def setProject(self, projectName):
self.project = projectName
self.fileListWidget.clear()
self.shotListWidget.clear()
self.shotListWidget.addItems(core.listShots(self.project))
def updateFileList(self):
self.fileListWidget.clear()
for version in core.listVersion(self.project, self.currentShot) :
version_path = projectExplorer_core._replaceData(core.getConfigData("PATH_TEMPLATE"), self.project, self.currentShot)
item = QListWidgetItem(self.fileListWidget)
if version.endswith(".nk"):
item.setIcon(QIcon(currentDir + "/image/NukeDoc16.png"))
widgetitem = fileListItem(version)
widgetitem.setData(version_path.replace('${_SCRIPTNAME}', version))
item.setSizeHint(widgetitem.sizeHint())
# self.fileListWidget.addItem(item)
self.fileListWidget.addItem(item)
self.fileListWidget.setItemWidget(item, widgetitem)
def addShot(self):
path = projectExplorer_core._replaceData(core.getConfigData("PATH_TEMPLATE").split('/${_SHOTSNAME}/')[0],
project = self.project)
is_folderExists = True
while is_folderExists:
shotname, ok = QInputDialog.getText(self, "Create new shot", "Shot name:")
if ok:
is_folderExists = shotname in os.listdir(path)
else:
return
folderPath = "%s/%s"%(path, shotname)
os.mkdir(folderPath)
# Refresh shot-list
self.setProject(self.project)
def __renameScript(self, filepath):
oldname = os.path.basename(filepath)
dirname = os.path.dirname(filepath)
is_folderExists = True
while is_folderExists:
newname, ok = QInputDialog.getText(self, "Rename", "new name:", QLineEdit.Normal, oldname)
if ok:
is_folderExists = newname in os.listdir(dirname)
else:
return
newPath = "%s/%s"%(dirname, newname)
os.rename(filepath, newPath)
self.updateFileList()
def __duplicateScript(self, filepath):
def getLastVersion(dirname, basename):
count = 0
for filename in os.listdir(dirname):
if filename.startswith(basename):
count += 1
if count > 0 :
return (count + 1)
else :
return 1
dirname = os.path.dirname(filepath)
basename, ext = os.path.splitext(os.path.basename(filepath))
if '_copy' in basename:
basename = basename.split("_copy")[0]
increment_number = getLastVersion(dirname, basename)
newname = basename + '_copy' + str(increment_number) + ext
while newname in os.listdir(dirname):
increment_number += 1
newname = basename + '_copy' + str(increment_number) + ext
newpath = '%s/%s'%(dirname, newname)
shutil.copy2(filepath, newpath)
self.updateFileList()
def fileListWidgetItemRightClicked(self, QPos):
self.listMenu = QMenu()
menu_copyNameItem = self.listMenu.addAction("Copy name")
menu_copyPathItem = self.listMenu.addAction("Copy path")
self.listMenu.addSeparator()
menu_rename = self.listMenu.addAction("Rename")
menu_duplicate = self.listMenu.addAction("Duplicate")
self.listMenu.addSeparator()
menu_updatethumbnail = self.listMenu.addAction("Update Thumbnail")
menu_openExplorer = self.listMenu.addAction("Open Containing Folder ...")
menu_openExplorer.triggered.connect(lambda : openExplorer(os.path.dirname(self.currentFile)))
menu_copyNameItem.triggered.connect(lambda : copyTextToClipboard(os.path.basename(self.currentFile)))
menu_copyPathItem.triggered.connect(lambda : copyTextToClipboard(self.currentFile))
menu_rename.triggered.connect(lambda : self.__renameScript(self.currentFile))
menu_updatethumbnail.triggered.connect(self.__menu_updatethumbnail_onCLicked)
menu_duplicate.triggered.connect(lambda : self.__duplicateScript(self.currentFile))
parentPosition = self.fileListWidget.mapToGlobal(QPos)
self.listMenu.exec_(parentPosition)
def __menu_updatethumbnail_onCLicked(self):
msgBox = QMessageBox().question(self, "Confirm Dialog", "Do you want to update thumbnail?",
QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Cancel)
if msgBox == QMessageBox.Ok:
projectExplorer_core.saveFrame(thumbnailPath=projectExplorer_core.thumbnailPath(self.currentFile))
else:
return
self.setThumbnail()
@property
def currentShot(self):
if not self.shotListWidget.currentItem():
return None
return self.shotListWidget.currentItem().text()
@property
def currentFile(self):
if not self.fileListWidget.currentItem():
return None
return self.fileListWidget.itemWidget(self.fileListWidget.currentItem()).data
class fileListItem(QWidget):
def __init__(self, text = '', parent = None):
super(fileListItem, self).__init__(parent)
mainLayout = QHBoxLayout()
self.itemname = QLabel(self)
verticalSpacer = QSpacerItem(20, 10, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.itemModified = QLabel(self)
mainLayout.addWidget(self.itemname)
mainLayout.addItem(verticalSpacer)
mainLayout.addWidget(self.itemModified)
mainLayout.setStretch(1,1)
mainLayout.setContentsMargins(1,6,10,6)
self.setLayout(mainLayout)
self.setText(text)
self.setStyleSheet("font-size: 10pt;")
def setText(self, text):
self.itemname.setText(text)
def setData(self, data):
self.data = data
mtime = time.strftime('%m/%d/%Y %H:%M:%S',time.localtime(os.path.getmtime(data)))
self.itemModified.setText(mtime)
def text(self):
return self.itemname.text()
def copyTextToClipboard(text):
clipBoard = QApplication.clipboard()
clipBoard.setText(text)
def openExplorer(filePath):
"""Open File explorer after finish."""
win_publishPath = filePath.replace('/', '\\')
subprocess.Popen('explorer \/select,\"%s\"' % win_publishPath)
def _nuke_main_window():
"""Returns Nuke's main window"""
for obj in QApplication.instance().topLevelWidgets():
if (obj.inherits('QMainWindow') and
obj.metaObject().className() == 'Foundry::UI::DockMainWindow'):
return obj
else:
raise RuntimeError('Could not find DockMainWindow instance')
def main ():
window = ExplorerWindow( parent = _nuke_main_window() )
window.show()