Exemplo n.º 1
0
def resource(name, pkg=None):
    if pkg is None:
        pkg = '%s.resources' % calling_package()
    resource = resource_filename(pkg, name)
    if not resource_exists(resource):
        raise OSError('Resource does not exist %s' % repr(resource))
    return resource
Exemplo n.º 2
0
def resource(name, pkg=None):
    if pkg is None:
        pkg = '%s.resources' % calling_package()
    resource = resource_filename(pkg, name)
    if not resource_exists(resource):
        raise OSError('Resource does not exist %s' % repr(resource))
    return resource
Exemplo n.º 3
0
def image_resources(pkg=None, directory='resources'):
    if pkg is None:
        pkg = calling_package()
    pkg_dir = '%s.%s' % (pkg, directory)
    images = []
    for i in resource_listdir(pkg, directory):
        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
Exemplo n.º 4
0
def external_resource(name, package=None):
    """
    Returns the absolute path to the external resource requested. If a package is not explicitly specified then the
    calling package name is used.

    :param name: path relative to package path of the external resource.
    :param package: package name in dotted format.
    :return: the absolute path to the external resource.
    """
    if not package:
        package = '%s.resources.external' % calling_package()
    return resource_filename(package, name)
Exemplo n.º 5
0
def image_resources(pkg=None, directory='resources'):
    if pkg is None:
        pkg = calling_package()
    pkg_dir = '%s.%s' % (pkg, directory)
    images = []
    for i in resource_listdir(pkg, directory):
        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
Exemplo n.º 6
0
def external_resource(name, package=None):
    """
    Returns the absolute path to the external resource requested. If a package is not explicitly specified then the
    calling package name is used.

    :param name: path relative to package path of the external resource.
    :param package: package name in dotted format.
    :return: the absolute path to the external resource.
    """
    if not package:
        package = '%s.resources.external' % calling_package()
    return resource_filename(package, name)
Exemplo n.º 7
0
def icon_resource(name, package=None):
    """
    Returns the absolute URI path to an image. If a package is not explicitly specified then the calling package name is
    used.

    :param name: path relative to package path of the image resource.
    :param package: package name in dotted format.
    :return: the file URI path to the image resource (i.e. file:///foo/bar/image.png).
    """
    if not package:
        package = '%s.resources.images' % calling_package()
    name = resource_filename(package, name)
    if not name.startswith('/'):
        return 'file://%s' % abspath(name)
    return 'file://%s' % name
Exemplo n.º 8
0
def icon_resource(name, package=None):
    """
    Returns the absolute URI path to an image. If a package is not explicitly specified then the calling package name is
    used.

    :param name: path relative to package path of the image resource.
    :param package: package name in dotted format.
    :return: the file URI path to the image resource (i.e. file:///foo/bar/image.png).
    """
    if not package:
        package = '%s.resources.images' % calling_package()
    name = resource_filename(package, name)
    if not name.startswith('/'):
        return 'file://%s' % abspath(name)
    return 'file://%s' % name
Exemplo n.º 9
0
def image_resources(package=None, directory='resources'):
    """
    Returns all images under the directory relative to a package path. If no directory or package is specified then the
    resources module of the calling package will be used. Images are recursively discovered.

    :param package: package name in dotted format.
    :param directory: path relative to package path of the resources directory.
    :return: a list of images under the specified resources path.
    """
    if not package:
        package = calling_package()
    package_dir = '.'.join([package, directory])
    images = []
    for i in resource_listdir(package, directory):
        fname = resource_filename(package_dir, i)
        if resource_isdir(package_dir, i):
            images.extend(image_resources(package_dir, i))
        elif what(fname):
            images.append(fname)
    return images
Exemplo n.º 10
0
def image_resources(package=None, directory='resources'):
    """
    Returns all images under the directory relative to a package path. If no directory or package is specified then the
    resources module of the calling package will be used. Images are recursively discovered.

    :param package: package name in dotted format.
    :param directory: path relative to package path of the resources directory.
    :return: a list of images under the specified resources path.
    """
    if not package:
        package = calling_package()
    package_dir = '.'.join([package, directory])
    images = []
    for i in resource_listdir(package, directory):
        fname = resource_filename(package_dir, i)
        if resource_isdir(package_dir, i):
            images.extend(image_resources(package_dir, i))
        elif what(fname):
            images.append(fname)
    return images
Exemplo n.º 11
0
def icon_resource(name, pkg=None):
    if pkg is None:
        pkg = '%s.resources.images' % calling_package()
    return imageicon(pkg, name)
Exemplo n.º 12
0
def external_resource(name, pkg=None):
    if pkg is None:
        pkg = '%s.resources.external' % calling_package()
    return resource_filename(pkg, name)
Exemplo n.º 13
0
def icon_resource(name, pkg=None):
    if pkg is None:
        pkg = '%s.resources.images' % calling_package()
    return imageicon(pkg, name)
Exemplo n.º 14
0
def external_resource(name, pkg=None):
    if pkg is None:
        pkg = '%s.resources.external' % calling_package()
    return resource_filename(pkg, name)