From 5aafbb5eef06305f8a8fd489c55b5ff71b16580e Mon Sep 17 00:00:00 2001 From: allfro Date: Sun, 7 Apr 2013 21:21:41 -0400 Subject: [PATCH] Added `image_resources()` function to get all images from transform pack --- src/canari/resource.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/canari/resource.py b/src/canari/resource.py index 3a928a2..c8e8b6f 100644 --- a/src/canari/resource.py +++ b/src/canari/resource.py @@ -2,7 +2,8 @@ from utils.stack import modulecallee -from pkg_resources import resource_filename +from imghdr import what +from pkg_resources import resource_filename, resource_listdir, resource_isdir __author__ = 'Nadeem Douba' __copyright__ = 'Copyright 2012, Canari Project' @@ -47,5 +48,18 @@ def icon_resource(name, pkg=None): return imageicon(pkg, name) +def image_resources(pkg=None, dir='resources'): + if pkg is None: + pkg = modulecallee().__name__.split('.')[0] + pkg_dir = '%s.%s' % (pkg, dir) + images = [] + for i in resource_listdir(pkg, dir): + fname = resource_filename(pkg_dir, i) + if resource_isdir(pkg_dir, i): + images.extend(image_resources(pkg_dir, i)) + elif what(fname) is not None: + images.append(fname) + return images + # etc conf = resource_filename(etc, 'canari.conf') -- 2.45.1