forked from fredrikaverpil/pyVFX-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyVFXViewer.py
811 lines (581 loc) · 22.7 KB
/
pyVFXViewer.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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
''' Run mode '''
''' ------------- '''
runMode = 'standalone'
try:
import maya.cmds as cmds
import maya.OpenMayaUI as omui
import shiboken
runMode = 'maya'
except:
pass
try:
import nuke
from nukescripts import panels
runMode = 'nuke'
except:
pass
''' Imports regardless of Qt type '''
''' ------------------------------ '''
import os, sys, time, subprocess
import xml.etree.ElementTree as xml
from cStringIO import StringIO
''' PySide or PyQt - that is the question... '''
''' ---------------------------------------- '''
QtType = 'PySide' # Edit this to switch between PySide and PyQt
if QtType == 'PySide':
from PySide import QtCore, QtGui, QtUiTools
if (runMode == 'nuke'):
if 'win' in sys.platform:
sys.path.append(r'C:/Python26/Lib/site-packages') # Edit this to point to the path containing the pysideuic module on Windows
elif 'linux' in sys.platform:
sys.path.append(r'/usr/lib/python2.6/dist-packages') # Edit this to point to the path containing the pysideuic module on Linux
elif 'darwin' in sys.platform:
sys.path.append(r'/Library/Python/2.6/site-packages/') # Edit this to point to the path containing the pysideuic module on OS X
import pysideuic
elif QtType == 'PyQt':
from PyQt4 import QtCore, QtGui, uic
import sip
''' Inits '''
sys.dont_write_bytecode = True
''' Variables '''
print 'This app is now using ' + QtType
uiFile = os.path.join(os.path.dirname(__file__), "mainWindow.ui")
windowTitle = 'pyVFX Viewer'
windowObject = 'pyVFXViewer'
class PyQtPySideFixer(QtGui.QMainWindow):
def __init__(self, parent=None):
"""Super, loadUi, signal connections"""
super(PyQtPySideFixer, self).__init__(parent)
print 'Making a detour (hack), necessary for when using PyQt'
def loadUiType(uiFile):
"""
Pyside lacks the "loadUiType" command, so we have to convert the ui file to py code in-memory first
and then execute it in a special frame to retrieve the form_class.
"""
parsed = xml.parse(uiFile)
widget_class = parsed.find('widget').get('class')
form_class = parsed.find('class').text
with open(uiFile, 'r') as f:
o = StringIO()
frame = {}
if QtType == 'PySide':
pysideuic.compileUi(f, o, indent=0)
pyc = compile(o.getvalue(), '<string>', 'exec')
exec pyc in frame
#Fetch the base_class and form class based on their type in the xml from designer
form_class = frame['Ui_%s'%form_class]
base_class = eval('QtGui.%s'%widget_class)
elif QtType == 'PyQt':
form_class = PyQtPySideFixer
base_class = QtGui.QMainWindow
return form_class, base_class
form, base = loadUiType(uiFile)
def wrapinstance(ptr, base=None):
"""
Utility to convert a pointer to a Qt class instance (PySide/PyQt compatible)
:param ptr: Pointer to QObject in memory
:type ptr: long or Swig instance
:param base: (Optional) Base class to wrap with (Defaults to QObject, which should handle anything)
:type base: QtGui.QWidget
:return: QWidget or subclass instance
:rtype: QtGui.QWidget
"""
if ptr is None:
return None
ptr = long(ptr) #Ensure type
if globals().has_key('shiboken'):
if base is None:
qObj = shiboken.wrapInstance(long(ptr), QtCore.QObject)
metaObj = qObj.metaObject()
cls = metaObj.className()
superCls = metaObj.superClass().className()
if hasattr(QtGui, cls):
base = getattr(QtGui, cls)
elif hasattr(QtGui, superCls):
base = getattr(QtGui, superCls)
else:
base = QtGui.QWidget
return shiboken.wrapInstance(long(ptr), base)
elif globals().has_key('sip'):
base = QtCore.QObject
return sip.wrapinstance(long(ptr), base)
else:
return None
def maya_main_window():
main_window_ptr = omui.MQtUtil.mainWindow()
return wrapinstance( long( main_window_ptr ), QtGui.QWidget ) # Works with both PyQt and PySide
def runStandalone():
app = QtGui.QApplication(sys.argv)
global gui
gui = MediaViewer()
gui.show()
darkorange = True # Edit this to set the darkorange stylesheet
if darkorange:
themePath = os.path.join( os.path.dirname(__file__), 'theme' )
sys.path.append( themePath )
import darkorangeResource
stylesheetFilepath = os.path.join( themePath, 'darkorange.stylesheet' )
with open( stylesheetFilepath , 'r' ) as shfp:
gui.setStyleSheet( shfp.read() )
app.setStyle("plastique")
sys.exit(app.exec_())
def runMaya():
if cmds.window(windowObject, q=True, exists=True):
cmds.deleteUI(windowObject)
global gui
gui = MediaViewer( maya_main_window() )
dockedWindow = False # Edit this to change between docked window and free floating window
if dockedWindow:
allowedAreas = ['right', 'left']
cmds.dockControl( label=windowTitle, area='left', content=windowObject, allowedArea=allowedAreas )
else:
gui.show()
def runNuke():
moduleName = __name__
if moduleName == '__main__':
moduleName = ''
else:
moduleName = moduleName + '.'
dockedWindow = False # Edit this to change between docked window and free floating window (DOES NOT WORK PROPERLY AT THE MOMENT)
if dockedWindow:
pane = nuke.getPaneFor('Properties.1')
panel = panels.registerWidgetAsPanel( moduleName + 'MediaViewer' , windowTitle, ('uk.co.thefoundry.'+windowObject+'Window'), True).addToPane(pane) # View pane and add it to panes menu
global gui
gui = panel.customKnob.getObject().widget
else:
global gui
gui = MediaViewer()
gui.show()
class MediaViewer(form, base):
def __init__(self, parent=None):
"""Super, loadUi, signal connections"""
super(MediaViewer, self).__init__(parent)
if QtType == 'PySide':
print 'Loading UI using PySide'
self.setupUi(self)
elif QtType == 'PyQt':
print 'Loading UI using PyQt'
uic.loadUi(uiFile, self)
self.setObjectName(windowObject)
self.setWindowTitle(windowTitle)
# Directories
self.cacheDir = os.path.join( os.path.dirname(__file__), 'cache' )
if not os.path.exists(self.cacheDir):
os.makedirs(self.cacheDir)
self.scanDir = ''
self.currentDir = 'C:/'
if not os.path.isdir(self.currentDir):
self.currentDir = os.path.dirname(__file__)
self.cacheDir = os.path.join( os.path.dirname(__file__), 'cache')
# Format support
self.formatSupport = ['bmp','gif','jpg','jpeg','png','pbm','pgm','ppm','tiff','tif','xbm','xpm'] # Supported by QImage (Read)
self.log = []
# Thumbnails size
self.thumbnailHeight = 200
# Pagination
self.itemsToLoad = 50
# Load settings
self.settingsGet()
self.progressBar.setValue(0) # Goes between 0-100
self.listDirs()
self.listWidgetDirs.itemClicked.connect( self.listImagery ) # Select folder in list
self.tabWidget.tabCloseRequested.connect( self.closeTab ) # Close tab
self.tabWidget.currentChanged.connect( self.updateOnTabChange ) # Update stuff whenever we select another tab
self.checkBoxScanSubdirs.stateChanged.connect( self.updateTabContents ) # Update current tab to scan subdirs or not scan subdirs
# Somehow this magically enables a statusbar...
#self.statusBar()
# File menu
#self.exitAction.triggered.connect( QtGui.qApp.quit )
self.actionChangeDir.triggered.connect( self.changeDir )
def closeEvent(self, event):
self.settingsSet()
def settingsSet(self):
window = self.geometry()
settings = QtCore.QSettings("pyVFX", "Media Viewer")
settings.beginGroup("Media Viewer");
settings.setValue("window", window);
settings.endGroup();
def settingsGet(self):
# Fetch settings
try:
settings = QtCore.QSettings("pyVFX", "Media Viewer")
settings.beginGroup("Media Viewer")
window = settings.value("window")
settings.endGroup()
if QtType == 'PySide':
self.setGeometry( window )
elif QtType == 'PyQt':
self.setGeometry( window.toRect() )
except:
pass
def updateTabContents(self):
self.tabWidget.blockSignals(True)
# To do: check if we have a tab open or not...
if self.checkBoxScanSubdirs.checkState() == self.tabWidget.currentWidget().subdirs:
# All good
pass
else:
# Wipe contents (remove tab) and scan with subdirs activated
self.progressBar.setValue(0)
# Since the listImagery method reads the position in the listWidgetsDir, it is necessary
# to move the selection to this row before removing the tab.
tabName = self.tabWidget.currentWidget().scanDir[self.tabWidget.currentWidget().scanDir.rfind('/')+1 : len(self.tabWidget.currentWidget().scanDir) ]
for x in range(0, self.listWidgetDirs.count() ):
#print self.listWidgetDirs.item(x).text().encode('ascii', 'ignore')
if self.listWidgetDirs.item(x).text() == tabName:
self.listWidgetDirs.setCurrentRow(x)
# Remove tab
self.tabWidget.removeTab( self.tabWidget.indexOf( self.tabWidget.currentWidget()) )
# Re-create the tab
self.listImagery()
self.tabWidget.blockSignals(False)
def updateOnTabChange(self):
# Check to see whether we have deleted all tabs or not
skip = False
try:
self.tabWidget.currentWidget().maxProgress
except:
skip = True
self.progressBar.reset()
if not skip:
minimum = 0
maximum = self.tabWidget.currentWidget().maxProgress
current = self.tabWidget.currentWidget().currentProgress
self.updateProgress(minimum, maximum, current)
if self.checkBoxScanSubdirs.checkState() == self.tabWidget.currentWidget().subdirs:
# Do not change checkbox
pass
else:
# Changing checkbox value
self.checkBoxScanSubdirs.blockSignals(True)
if self.tabWidget.currentWidget().subdirs:
self.checkBoxScanSubdirs.setCheckState( QtCore.Qt.Checked )
QtGui.QApplication.processEvents()
else:
self.checkBoxScanSubdirs.setCheckState( QtCore.Qt.Unchecked )
QtGui.QApplication.processEvents()
self.checkBoxScanSubdirs.blockSignals(False)
try:
self.scanDir = self.tabWidget.currentWidget().scanDir
except:
pass
def updateProgress(self, minimum, maximum, current):
if current == maximum:
self.progressBar.reset()
else:
self.progressBar.setMinimum( minimum )
self.progressBar.setMaximum( maximum )
self.progressBar.setValue( current )
QtGui.QApplication.processEvents()
def changeDir(self):
fileDialog = QtGui.QFileDialog()
folderName = fileDialog.getExistingDirectory(None, "Select Folder")
if folderName != '':
self.currentDir = folderName
self.listDirs()
def closeTab(self, index):
self.tabWidget.removeTab(index)
def logList(self, logList):
count = 0
for line in logList:
self.log.append(line)
count += 1
if count == len(logList):
self.lineEditInfo.setText(line)
def listDirs(self):
self.listWidgetDirs.clear()
print self.currentDir
dirs = os.walk( self.currentDir ).next()[1]
for directory in dirs:
#dirUnicode = u'' + dir + ''
self.listWidgetDirs.addItem( directory )
def listImagery(self):
self.scanDir = os.path.join( self.currentDir, str(self.listWidgetDirs.currentItem().text()) )
if self.checkBoxScanSubdirs.isChecked():
dirs = [x[0] for x in os.walk( self.scanDir )]
else:
dirs = []
dirs.append(self.scanDir)
imageFiles = []
for dir in dirs:
for file in os.listdir ( dir ):
for format in self.formatSupport:
if file.lower().endswith( format ):
imageFiles.append( os.path.join( dir, file) )
if len(imageFiles) == 0:
self.logList( ['Found 0 files in \"' + self.listWidgetDirs.currentItem().text() + '\".'] )
else:
self.logList( ['Found a total of ' + str( len(imageFiles) ) + ' files in \"' + self.listWidgetDirs.currentItem().text() + '\".'] )
self.createTab(imageFiles)
def checkForExistingTab(self):
retVal = False
for x in range( 0, gui.tabWidget.count() ):
#print 'COMPARING ' + self.scanDir + ' against ' + gui.tabWidget.widget(x).scanDir
if (self.scanDir == gui.tabWidget.widget(x).scanDir):
retVal = True
return retVal
def createTab(self, imageFiles):
# Check to see whether the scanDir is already present inside any of the tab widgets
scanDirFound = self.checkForExistingTab()
if scanDirFound:
# Open existing tab
for x in range( 0, gui.tabWidget.count() ):
if gui.scanDir == gui.tabWidget.widget(x).scanDir:
gui.tabWidget.setCurrentIndex(x)
else:
# Create new tab
newTab = Tab(self, imageFiles)
#self.tabList.append(tab)
self.tabWidget.addTab( newTab, self.listWidgetDirs.currentItem().text() )
self.tabWidget.setCurrentIndex( self.tabWidget.count()-1 )
QtGui.QApplication.processEvents()
newTab.associatedTab = self.tabWidget.currentWidget()
newTab.loadImagery()
class ThreadLoadImage(QtCore.QThread):
def __init__(self, parent, placeholder, imageFilepath):
super(ThreadLoadImage, self).__init__(parent)
#QtCore.QThread.__init__(self)
self.placeholder = placeholder
self.imageFilepath = imageFilepath
def run(self):
proxyFilename = self.imageFilepath.replace('/','-').replace('\\','-').replace(':','')
proxyFilepath = os.path.join(gui.cacheDir, proxyFilename)
# Get "last modified" date of original full-res imagery
(modeFullres, inoFullres, devFullres, nlinkFullres, uidFullres, gidFullres, sizeFullres, atimeFullres, mtimeFullres, ctimeFullres) = os.stat( self.imageFilepath )
#print "fullres last modified: %s" % time.ctime(mtimeProxy)
# Get "last modified" date of proxy image
if os.path.exists( proxyFilepath ):
(modeProxy, inoProxy, devProxy, nlinkProxy, uidProxy, gidProxy, sizeProxy, atimeProxy, mtimeProxy, ctimeProxy) = os.stat( proxyFilepath )
#print "proxy last modified: %s" % time.ctime(mtimeProxy)
else:
atimeProxy = None
mtimeProxy = None
if os.path.exists( proxyFilepath ) and (mtimeProxy >= mtimeFullres):
# Cache exists, contains same "last modified date" as fullres -- so load that instead
self.placeholder.image.load( proxyFilepath )
self.placeholder.scaledImage = self.placeholder.image.scaledToHeight(200, QtCore.Qt.SmoothTransformation)
del self.placeholder.image
else:
# Cache does not exist, load full res and save proxy image
self.placeholder.image.load( self.imageFilepath )
self.placeholder.scaledImage = self.placeholder.image.scaledToHeight(200, QtCore.Qt.SmoothTransformation)
del self.placeholder.image
# Save cache image
jpegWriter = QtGui.QImageWriter()
jpegWriter.setFileName( proxyFilepath )
jpegWriter.write(self.placeholder.scaledImage)
# Make proxy carry the same "last modified" date as the fullres imagery
os.utime( proxyFilepath, (atimeFullres, mtimeFullres) )
self.emit( QtCore.SIGNAL('update(QString)'), "image loaded" )
return
class Thumbnail(QtGui.QWidget):
def __init__(self, parent=None, module='', imageFilepath=''):
super(Thumbnail, self).__init__(parent)
self.placeholder = module
self.imageFilepath = imageFilepath
self.parentTab = parent
self.associatedTab = parent.associatedTab
# If tab associated with this process is the current one in the GUI, show the progress
if self.associatedTab == gui.tabWidget.currentWidget():
minimum = 0
maximum = self.parentTab.maxProgress
current = self.parentTab.currentProgress
#gui.updateProgress(minimum, maximum, current)
#gui.logList( ['Loading fullres image for ' + self.placeholder.textLabel.text() ])
self.placeholder.image = QtGui.QImage(200, gui.thumbnailHeight, QtGui.QImage.Format_ARGB32)
# Threading
self.workThread = ThreadLoadImage(self, self.placeholder, self.imageFilepath)
self.connect( self.workThread, QtCore.SIGNAL("update(QString)"), self.next )
self.workThread.start()
def next(self):
self.placeholder.layout.removeWidget(self.placeholder.imageLabel)
self.placeholder.layout.removeWidget(self.placeholder.textLabel)
self.placeholder.imageLabel.setParent(None) # Prevent the placeholders to show up
self.placeholder.textLabel.setParent(None)
self.placeholder.imageLabel = QtGui.QLabel('')
self.placeholder.imageLabel.setPixmap(QtGui.QPixmap.fromImage( self.placeholder.scaledImage ))
self.placeholder.layout.addWidget( self.placeholder.imageLabel )
self.placeholder.layout.addWidget( self.placeholder.textLabel )
# Update progress bar
self.parentTab.currentProgress += 1
if self.associatedTab == gui.tabWidget.currentWidget():
minimum = 0
maximum = self.parentTab.maxProgress
current = self.parentTab.currentProgress
gui.updateProgress(minimum, maximum, current)
class Placeholder(QtGui.QWidget):
def __init__(self, parent=None, imageFilepath=''):
super(Placeholder, self).__init__(parent)
self.imageFilepath = imageFilepath
self.layout = QtGui.QVBoxLayout(self)
# Create place holder
self.image = QtGui.QImage(200, 200, QtGui.QImage.Format_ARGB32)
self.image.fill(QtGui.qRgb(255,0,0))
self.imageLabel = QtGui.QLabel('')
self.imageLabel.setPixmap(QtGui.QPixmap.fromImage( self.image ))
# Create text label
self.textLabel = QtGui.QLabel( os.path.basename(imageFilepath) )
# Attach image and text to widget
self.layout.addWidget( self.imageLabel )
self.layout.addWidget( self.textLabel )
# Add right-click menu
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.selfRightClick)
def selfRightClick(self, pos):
menu = QtGui.QMenu()
menu.addAction('Reveal ' + self.textLabel.text() + ' on disk', lambda : self.openContainingFolder( self.imageFilepath ) )
#menu.addAction('Open containing folder of ' + self.textLabel.text(), lambda : self.printer( 'open ' + self.imageFilepath ) )
menu.addSeparator()
menu.exec_(self.mapToGlobal(pos))
def mousePressEvent(self, event):
if event.type() in (QtCore.QEvent.MouseButtonPress, QtCore.QEvent.MouseButtonDblClick):
if event.button() == QtCore.Qt.LeftButton:
pass
#self.printer( 'Load hires image into pane: ' + self.textLabel.text() )
#self.connect(self.textLabel, QtCore.SIGNAL('clicked()'), self.click(self.textLabel.text()) )
def printer(self, item):
print item
def openContainingFolder(self, imageFilepath):
# Open folder with file selected
if 'darwin' in sys.platform:
subprocess.call(['open', '-R', imageFilepath])
elif 'win' in sys.platform:
subprocess.call(['open', '/select,' + imageFilepath])
elif 'linux' in sys.platform:
subprocess.call(['xdg-open', os.path.dirname(imageFilepath)])
class Tab(QtGui.QWidget):
def __init__(self, parent=None, imageFiles=['']):
super(Tab, self).__init__(parent)
self.widget_layout = QtGui.QVBoxLayout(self)
self.scrollarea = QtGui.QScrollArea()
self.scrollarea.setWidgetResizable(True)
self.widget_layout.addWidget(self.scrollarea)
self.widget = QtGui.QWidget()
#self.layout = QtGui.QVBoxLayout(self.widget)
self.layout = FlowLayout(self.widget)
self.scrollarea.setWidget(self.widget)
self.layout.setAlignment(QtCore.Qt.AlignLeft)
# The imagery associated with this tab (and which have not yet been loaded)
self.scanDir = gui.scanDir
self.imageFiles = imageFiles
# Subdirs included or not
self.subdirs = False
if gui.checkBoxScanSubdirs.isChecked():
self.subdirs = True
self.removed = False
self.associatedTab = ''
# Prepare progress bar
self.currentProgress = 0
self.maxProgress = len(self.imageFiles)
# Pagination variables for this tab
self.pagesShown = 1
# Pagination signal
self.scrollarea.verticalScrollBar().valueChanged.connect( self.paginationLoadNextItems )
def paginationLoadNextItems(self):
sliderMax = self.scrollarea.verticalScrollBar().maximum()
sliderPos = self.scrollarea.verticalScrollBar().sliderPosition()
if len(self.imageFiles) != 0:
if sliderPos == sliderMax:
self.pagesShown += 1
self.loadImagery()
def loadImagery(self):
imageFilesPage = self.imageFiles
# Create a module for each imagery as well as placeholder
self.moduleList = []
countPagination = 1
for imageFilepath in imageFilesPage:
if (countPagination <= gui.itemsToLoad ):
newModule = Placeholder(self, imageFilepath) # Create a new ui module
self.moduleList.append(newModule) # Put it in the list of modules
self.layout.addWidget( newModule ) # Add this module ui widget to 'modLayout'
countPagination += 1
# Initiate threading, loading data, working, crunching...
countModule = 0
countPagination = 1
for imageFilepath in imageFilesPage:
if (countPagination <= gui.itemsToLoad ):
newModule = self.moduleList[countModule]
Thumbnail(self, newModule, imageFilepath ) # Load imagery, preform processing etc...
countModule += 1
countPagination += 1
# Remove the already loaded files from the list of files to load (auto scroll)
totalSize = len(self.imageFiles)
if totalSize < gui.itemsToLoad:
numberOfItemsToRemove = totalSize
else:
numberOfItemsToRemove = gui.itemsToLoad
for x in range(0, numberOfItemsToRemove):
#print 'Removing ' + os.path.basename(imageFilepath) + ' from self.imageFiles list...'
self.imageFiles.pop(0)
if len(self.imageFiles) == 0:
gui.progressBar.reset()
class FlowLayout(QtGui.QLayout):
def __init__(self, parent=None, margin=0, spacing=-1):
super(FlowLayout, self).__init__(parent)
if parent is not None:
self.setMargin(margin)
self.setSpacing(spacing)
self.itemList = []
def setMargin(self, margin):
pass
def __del__(self):
item = self.takeAt(0)
while item:
item = self.takeAt(0)
def addItem(self, item):
self.itemList.append(item)
def count(self):
return len(self.itemList)
def itemAt(self, index):
if index >= 0 and index < len(self.itemList):
return self.itemList[index]
return None
def takeAt(self, index):
if index >= 0 and index < len(self.itemList):
return self.itemList.pop(index)
return None
def expandingDirections(self):
return QtCore.Qt.Orientations(QtCore.Qt.Orientation(0))
def hasHeightForWidth(self):
return True
def heightForWidth(self, width):
height = self.doLayout(QtCore.QRect(0, 0, width, 0), True)
return height
def setGeometry(self, rect):
super(FlowLayout, self).setGeometry(rect)
self.doLayout(rect, False)
def sizeHint(self):
return self.minimumSize()
def minimumSize(self):
size = QtCore.QSize()
for item in self.itemList:
size = size.expandedTo(item.minimumSize())
#size += QtCore.QSize(2 * self.margin(), 2 * self.margin())
return size
def doLayout(self, rect, testOnly):
x = rect.x()
y = rect.y()
lineHeight = 0
for item in self.itemList:
wid = item.widget()
spaceX = self.spacing() + wid.style().layoutSpacing(QtGui.QSizePolicy.PushButton, QtGui.QSizePolicy.PushButton, QtCore.Qt.Horizontal)
spaceY = self.spacing() + wid.style().layoutSpacing(QtGui.QSizePolicy.PushButton, QtGui.QSizePolicy.PushButton, QtCore.Qt.Vertical)
nextX = x + item.sizeHint().width() + spaceX
if nextX - spaceX > rect.right() and lineHeight > 0:
x = rect.x()
y = y + lineHeight + spaceY
nextX = x + item.sizeHint().width() + spaceX
lineHeight = 0
if not testOnly:
item.setGeometry(QtCore.QRect(QtCore.QPoint(x, y), item.sizeHint()))
x = nextX
lineHeight = max(lineHeight, item.sizeHint().height())
return y + lineHeight - rect.y()
if runMode == 'standalone':
runStandalone()
'''
elif runMode == 'maya':
runMaya()
elif runMode == 'nuke':
runNuke()
'''