[ui] Improve sequence display

- allows multiple "*" in the files search expression
- fix a bug if we only provide a folder
- keep the current frame if the frame range has not changed
This commit is contained in:
Fabien Castan 2024-08-16 17:22:21 +02:00
parent 53679485a9
commit 15c1ce16b5
2 changed files with 41 additions and 41 deletions

View file

@ -147,23 +147,19 @@ class FilepathHelper(QObject):
extension = ".*" extension = ".*"
return [self.basename(f) for f in glob.glob(os.path.join(folderPath, f"*{extension}")) if os.path.isfile(f)] return [self.basename(f) for f in glob.glob(os.path.join(folderPath, f"*{extension}")) if os.path.isfile(f)]
@Slot(str, result="QVariantList") @Slot(str, bool, result="QVariantList")
def resolveSequence(self, path): def resolveSequence(self, path, includesSeqMissingFiles):
""" """
Get id of each file in the sequence. Get id of each file in the sequence.
""" """
# use of pyseq to get the sequences # use of pyseq to get the sequences
seq = pyseq.get_sequences(self.asStr(path)) seqs = pyseq.get_sequences(self.asStr(path))
ids = [[s.start(), s.end()] for s in seq] frameRanges = [[seq.start(), seq.end()] for seq in seqs]
folder = self.dirname(path) # create the resolved path for each sequence
if includesSeqMissingFiles:
missingFiles = [s.missing() for s in seq] resolved = [[seq.format("%D%h%p%t") % frameNumber for frameNumber in range(seq.start(), seq.end() + 1)] for seq in seqs]
else:
# create the resolved path for each sequence and if a frame is missing add a empty string resolved = [[fileItem.path for fileItem in seq] for seq in seqs]
resolved = [[os.path.join(folder, s.head() + str(s.format("%p") % frame) + s.tail()) if frame not in missingFiles[seq.index(s)] return frameRanges, resolved
else "" for frame in range(ids[seq.index(s)][0], ids[seq.index(s)][1] + 1)] if s.frames()
else os.path.join(folder, s.head())
for s in seq]
return ids, resolved

View file

@ -251,52 +251,56 @@ FocusScope {
function buildOrderedSequence(pathTemplate) { function buildOrderedSequence(pathTemplate) {
// Resolve the path template on the sequence of viewpoints // Resolve the path template on the sequence of viewpoints
// ordered by path // ordered by path
let outputFiles = []
let objs = [] if (displayedNode && displayedNode.hasSequenceOutput && displayedAttr) {
if (displayedNode && displayedNode.hasSequenceOutput && displayedAttr &&
(displayedAttr.desc.semantic === "imageList" || displayedAttr.desc.semantic === "sequence")) {
let sequence = Filepath.resolveSequence(pathTemplate)
let ids = sequence[0]
let resolved = sequence[1]
// reset current frame to 0 if it is imageList but not sequence // reset current frame to 0 if it is imageList but not sequence
if (displayedAttr.desc.semantic === "imageList") { if (displayedAttr.desc.semantic === "imageList") {
let includesSeqMissingFiles = false // list only the existing files
let [_, filesSeqs] = Filepath.resolveSequence(pathTemplate, includesSeqMissingFiles)
// concat in one array all sequences in resolved // concat in one array all sequences in resolved
resolved = [].concat.apply([], resolved) outputFiles = [].concat.apply([], filesSeqs)
frameRange.min = 0 let newFrameRange = [0, outputFiles.length - 1]
frameRange.max = resolved.length - 1
currentFrame = 0 if(frameRange.min != newFrameRange[0] || frameRange.max != newFrameRange[1]) {
frameRange.min = newFrameRange[0]
frameRange.max = newFrameRange[1]
// Change the current frame, only if the frame range is different
currentFrame = frameRange.min
}
enableSequencePlayerAction.checked = true
} }
if (displayedAttr.desc.semantic === "sequence") { if (displayedAttr.desc.semantic === "sequence") {
// if there is several sequences, take the first one, else take the only one let includesSeqMissingFiles = true
if (typeof resolved[0] === "object") let [frameRanges, filesSeqs] = Filepath.resolveSequence(pathTemplate, includesSeqMissingFiles)
resolved = resolved[0] let newFrameRange = [0, 0]
ids = ids[0] if (filesSeqs.length > 0) {
frameRange.min = ids[0] // if there is one or several sequences, take the first one
frameRange.max = ids[ids.length - 1] outputFiles = filesSeqs[0]
currentFrame = frameRange.min newFrameRange = frameRanges[0]
}
enableSequencePlayerAction.checked = true
} }
enableSequencePlayerAction.checked = true
return resolved
} else { } else {
let objs = []
for (let i = 0; i < _reconstruction.viewpoints.count; i++) { for (let i = 0; i < _reconstruction.viewpoints.count; i++) {
objs.push(_reconstruction.viewpoints.at(i)) objs.push(_reconstruction.viewpoints.at(i))
} }
objs.sort((a, b) => { return a.childAttribute("path").value < b.childAttribute("path").value ? -1 : 1; }) objs.sort((a, b) => { return a.childAttribute("path").value < b.childAttribute("path").value ? -1 : 1; })
let seq = [];
for (let i = 0; i < objs.length; i++) { for (let i = 0; i < objs.length; i++) {
seq.push(Filepath.resolve(pathTemplate, objs[i])) outputFiles.push(Filepath.resolve(pathTemplate, objs[i]))
} }
frameRange.min = 0 frameRange.min = 0
frameRange.max = seq.length - 1 frameRange.max = outputFiles.length - 1
return seq
} }
return outputFiles
} }
function getSequence() { function getSequence() {