Skip to content

Commit aab34a2

Browse files
authored
Merge pull request #2797 from alicevision/fix/dragDropFiles
Improve behaviour when dropping folders
2 parents bbad762 + 4f2f895 commit aab34a2

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

meshroom/multiview.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
# Supported image extensions
4-
imageExtensions = (
4+
imageExtensions = [
55
# bmp:
66
'.bmp',
77
# cineon:
@@ -57,21 +57,23 @@
5757
'.zfile',
5858
# osl:
5959
'.osl', '.oso', '.oslgroup', '.oslbody',
60-
)
61-
videoExtensions = (
60+
]
61+
videoExtensions = [
6262
'.avi', '.mov', '.qt',
6363
'.mkv', '.webm',
6464
'.mp4', '.mpg', '.mpeg', '.m2v', '.m4v',
6565
'.wmv',
6666
'.ogv', '.ogg',
6767
'.mxf',
68-
)
69-
panoramaInfoExtensions = ('.xml')
70-
meshroomSceneExtensions = ('.mg')
68+
]
69+
panoramaInfoExtensions = ['.xml']
70+
meshroomSceneExtensions = ['.mg']
7171

7272

7373
def hasExtension(filepath, extensions):
7474
""" Return whether filepath is one of the following extensions. """
75+
if os.path.isdir(filepath):
76+
return False
7577
return os.path.splitext(filepath)[1].lower() in extensions
7678

7779

@@ -134,13 +136,29 @@ def findFilesByTypeInFolder(folder, recursive=False):
134136
continue
135137
elif os.path.isdir(currentFolder):
136138
if recursive:
139+
# Get through all of the depth levels
137140
for root, directories, files in os.walk(currentFolder):
138141
for filename in files:
139142
output.addFile(os.path.join(root, filename))
140143
else:
141-
output.addFiles([os.path.join(currentFolder, filename) for filename in os.listdir(currentFolder)])
144+
# Only get the first level of depth, so top-level folders'
145+
# files will be added, if they exist.
146+
# This may prevent from importing nothing at all when files
147+
# are nested a level down
148+
try:
149+
root, directories, files = next(os.walk(currentFolder))
150+
output.addFiles([os.path.join(root, file) for file in files])
151+
for directory in directories:
152+
for file in os.listdir(os.path.join(root, directory)):
153+
filepath = os.path.join(root, directory, file)
154+
if os.path.isfile(filepath):
155+
output.addFile(filepath)
156+
except (StopIteration, OSError):
157+
# Directory empty or inaccessible, skip processing
158+
pass
159+
142160
else:
143-
# if not a directory or a file, it may be an expression
161+
# If not a directory or a file, it may be an expression
144162
import glob
145163
paths = glob.glob(currentFolder)
146164
filesByType = findFilesByTypeInFolder(paths, recursive=recursive)

meshroom/ui/graph.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,8 @@ def removeAttribute(self, attribute):
952952

953953
@Slot(Attribute)
954954
def removeImage(self, image):
955+
if image is None:
956+
return
955957
with self.groupedGraphModification("Remove Image"):
956958
# look if the viewpoint's intrinsic is used by another viewpoint
957959
# if not, remove it

meshroom/ui/reconstruction.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,12 +763,15 @@ def handleFilesUrl(self, filesByType, cameraInit=None, position=None):
763763
@Slot("QList<QUrl>", result="QVariantMap")
764764
def getFilesByTypeFromDrop(self, urls):
765765
"""
766+
Given a list of filepaths, sort them into distinct categories and return a map for all
767+
these categories.
766768
767769
Args:
768770
urls: list of filepaths
769771
770772
Returns:
771-
{images, videos, panoramaInfo, meshroomScenes, otherFiles}: Map containing the lists of paths for recognized images, videos, Meshroom scenes and other files.
773+
{images, videos, panoramaInfo, meshroomScenes, otherFiles}: Map containing the lists of paths for
774+
recognized images, videos, Meshroom scenes and other files.
772775
"""
773776
# Build the list of images paths
774777
filesByType = multiview.FilesByType()

0 commit comments

Comments
 (0)