Example #1
0
 def validate(self, default, **optional):
     if not_unicode_or_ascii(default) and not IIcon.providedBy(default):
         raise GrokImportError(
             "The '%s' directive can only be called with "
             "unicode or ASCII." % self.name)
     for key, value in optional.items():
         if not_unicode_or_ascii(value) and not IIcon.providedBy(default):
             raise GrokImportError(
                 "The '%s' directive can only be called with "
                 "unicode or ASCII." % self.name)
Example #2
0
def registerIcon(config, extension_name, cls, icon):
    """Register icon for a class.
    """
    if icon is None:
        return

    if not IIcon.providedBy(icon):
        extension = extensionRegistry.get_extension(extension_name)
        fs_path = os.path.join(extension.module_directory, icon)
        name = ''.join((
                'icon-',
                cls.meta_type.strip().replace(' ', '-'),
                os.path.splitext(icon)[1] or '.png'))

        factory = IconResourceFactory(name, fs_path)
        config.action(
            discriminator = ('resource', name, IHTTPRequest, Interface),
            callable = provideAdapter,
            args = (factory, (IHTTPRequest,), Interface, name))

        icon = Icon("++resource++" + name)

    icon_registry.register(('meta_type', cls.meta_type), icon)
    cls.icon = icon.icon