Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support recursive folders #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Sculpt_Alphas_Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,21 @@ def draw(self, context):
#--------------------------------------------------------------------------------------
# F U N C T I O N A L I T I E S
#--------------------------------------------------------------------------------------
def check_extension(filename):
return any([filename.lower().endswith(ext) for ext in [".jpeg", ".jpg", ".png", ".tif"]])

def category_folders(lib_path):
length = len(lib_path)
folders = []
for dirpath, _, filenames in os.walk(lib_path, followlinks=True):
if any(check_extension(filename) for filename in filenames):
folders.append(dirpath[length:].lstrip(os.sep))
return folders

# CATEGORIES PREVIEWS FUNCTION
def preview_sub_folders_categories(self, context):
lib_path = context.preferences.addons[__name__].preferences.sculpt_alphas_library

list_of_category_folders = []
for folder in os.listdir(lib_path):
if os.path.isdir(os.path.join(lib_path, folder)):
list_of_category_folders.append(folder)

list_of_category_folders = category_folders(lib_path)
return [(name, name, "") for name in list_of_category_folders]

# CATEGORY ITEMS PREVIEWS FUNCTION
Expand All @@ -93,7 +98,7 @@ def preview_items_in_folders(self, context):
if directory and os.path.exists(directory):
image_paths = []
for fn in os.listdir(directory):
if fn.lower().endswith(".jpeg") or fn.lower().endswith(".jpg") or fn.lower().endswith(".png") or fn.lower().endswith(".tif"):
if check_extension(fn):
image_paths.append(fn)

for i, name in enumerate(image_paths):
Expand Down Expand Up @@ -228,4 +233,5 @@ def unregister():
preview_collections.clear()

if __name__ == "__main__":
register()
register()