def setupIcon(klass, icon, repository):
    """Load icon into Zope image object and put it in Zope's
    repository for use by the ZMI, for a particular class.
    klass -- the class of the field we're adding
    icon  -- the icon
    """
    # set up misc_ respository if not existing yet
    if not hasattr(OFS.misc_.misc_, repository):
        setattr(OFS.misc_.misc_,
                repository,
                OFS.misc_.Misc_(repository, {}))

    # get name of icon in the misc_ directory
    icon_name = os.path.split(icon)[1]

    # set up image object from icon file
    icon_image = ImageFile(icon, globals())
    icon_image.__roles__ = None

    # put icon image object in misc_/Formulator/
    getattr(OFS.misc_.misc_, repository)[icon_name] = icon_image

    # set icon attribute in field_class to point to this image obj
    setattr(klass, 'icon', 'misc_/%s/%s' %
            (repository, icon_name))
Exemple #2
0
def registerImage(filepath, s):
    """
  manual icon registration
  """
    icon = ImageFile(filepath, globals())
    icon.__roles__ = None
    OFS.misc_.misc_.zms[s] = icon
def createIcon(iconspec, _prefix, pid):
    name = os.path.split(iconspec)[1]
    res = 'misc_/%s/%s' % (pid, name)
    icon = ImageFile(iconspec, _prefix)
    icon.__roles__ = None
    if not hasattr(OFS.misc_.misc_, pid):
        setattr(OFS.misc_.misc_, pid, OFS.misc_.Misc_(pid, {}))
    getattr(OFS.misc_.misc_, pid)[name] = icon
    return res
Exemple #4
0
def createIcon(iconspec, _prefix, pid=_prodname):
    name = os.path.split(iconspec)[1]
    res = 'misc_/%s/%s' % (pid, name)
    icon = ImageFile(iconspec, _prefix)
    icon.__roles__=None
    if not hasattr(OFS.misc_.misc_, pid):
        setattr(OFS.misc_.misc_, pid, OFS.misc_.Misc_(pid, {}))
    getattr(OFS.misc_.misc_, pid)[name]=icon
    return res
Exemple #5
0
def registerIcon(klass, iconspec, _prefix=None):
    """ Make an icon available for a given class.

    o 'klass' is the class being decorated.

    o 'iconspec' is the path within the product where the icon lives.
    """
    modname = klass.__module__
    pid = modname.split('.')[1]
    name = os_path.split(iconspec)[1]
    klass.icon = 'misc_/%s/%s' % (pid, name)
    icon = ImageFile(iconspec, _prefix)
    icon.__roles__ = None
    if not hasattr(misc_images, pid):
        setattr(misc_images, pid, MiscImage(pid, {}))
    getattr(misc_images, pid)[name] = icon
Exemple #6
0
def registerIcon(klass, iconspec, _prefix=None):

    """ Make an icon available for a given class.

    o 'klass' is the class being decorated.

    o 'iconspec' is the path within the product where the icon lives.
    """
    modname = klass.__module__
    pid = modname.split('.')[1]
    name = os_path.split(iconspec)[1]
    klass.icon = 'misc_/%s/%s' % (pid, name)
    icon = ImageFile(iconspec, _prefix)
    icon.__roles__=None
    if not hasattr(misc_images, pid):
        setattr(misc_images, pid, MiscImage(pid, {}))
    getattr(misc_images, pid)[name]=icon
Exemple #7
0
def setupIcon(klass, icon, repository):
    """Load icon into Zope image object and put it in Zope's
    repository for use by the ZMI, for a particular class.
    klass -- the class of the field we're adding
    icon  -- the icon
    """
    # set up misc_ respository if not existing yet
    if not hasattr(OFS.misc_.misc_, repository):
        setattr(OFS.misc_.misc_, repository, OFS.misc_.Misc_(repository, {}))

    # get name of icon in the misc_ directory
    icon_name = os.path.split(icon)[1]

    # set up image object from icon file
    icon_image = ImageFile(icon, globals())
    icon_image.__roles__ = None

    # put icon image object in misc_/Formulator/
    getattr(OFS.misc_.misc_, repository)[icon_name] = icon_image

    # set icon attribute in field_class to point to this image obj
    setattr(klass, 'icon', 'misc_/%s/%s' % (repository, icon_name))
    def registerClass(self,
                      instance_class=None,
                      meta_type='',
                      permission=None,
                      constructors=(),
                      icon=None,
                      permissions=None,
                      legacy=(),
                      visibility="Global",
                      interfaces=_marker,
                      container_filter=None):
        """Register a constructor

        Keyword arguments are used to provide meta data:

        instance_class -- The class of the object that will be created.

          This is not currently used, but may be used in the future to
          increase object mobility.

        meta_type -- The kind of object being created
           This appears in add lists.  If not specified, then the class
           meta_type will be used.

        permission -- The permission name for the constructors.
           If not specified, then a permission name based on the
           meta type will be used.

        constructors -- A list of constructor methods
          A method can me a callable object with a __name__
          attribute giving the name the method should have in the
          product, or the method may be a tuple consisting of a
          name and a callable object.  The method must be picklable.

          The first method will be used as the initial method called
          when creating an object.

        icon -- The name of an image file in the package to
                be used for instances. Note that the class icon
                attribute will be set automagically if an icon is
                provided.

        permissions -- Additional permissions to be registered
           If not provided, then permissions defined in the
           class will be registered.

        legacy -- A list of legacy methods to be added to ObjectManager
                  for backward compatibility

        visibility -- "Global" if the object is globally visible, None else

        interfaces -- a list of the interfaces the object supports

        container_filter -- function that is called with an ObjectManager
           object as the only parameter, which should return a true object
           if the object is happy to be created in that container. The
           filter is called before showing ObjectManager's Add list,
           and before pasting (after object copy or cut), but not
           before calling an object's constructor.

        """
        pack = self.__pack
        initial = constructors[0]
        productObject = self.__prod
        pid = productObject.id

        if icon and instance_class is not None:
            setattr(instance_class, 'icon',
                    'misc_/%s/%s' % (pid, os.path.split(icon)[1]))

        if permissions:
            if isinstance(permissions, basestring):  # You goofed it!
                raise TypeError, ('Product context permissions should be a '
                                  'list of permissions not a string',
                                  permissions)
            for p in permissions:
                if isinstance(p, tuple):
                    p, default = p
                    registerPermissions(((p, (), default), ))
                else:
                    registerPermissions(((p, ()), ))

        ############################################################
        # Constructor permission setup
        if permission is None:
            permission = "Add %ss" % (meta_type or instance_class.meta_type)

        if isinstance(permission, tuple):
            permission, default = permission
        else:
            default = ('Manager', )

        pr = PermissionRole(permission, default)
        registerPermissions(((permission, (), default), ))
        ############################################################

        OM = ObjectManager

        for method in legacy:
            if isinstance(method, tuple):
                name, method = method
                aliased = 1
            else:
                name = method.__name__
                aliased = 0
            if name not in OM.__dict__:
                setattr(OM, name, method)
                setattr(OM, name + '__roles__', pr)
                if aliased:
                    # Set the unaliased method name and its roles
                    # to avoid security holes.  XXX: All "legacy"
                    # methods need to be eliminated.
                    setattr(OM, method.__name__, method)
                    setattr(OM, method.__name__ + '__roles__', pr)

        if isinstance(initial, tuple):
            name, initial = initial
        else:
            name = initial.__name__

        fd = getattr(pack, '__FactoryDispatcher__', None)
        if fd is None:

            class __FactoryDispatcher__(FactoryDispatcher):
                "Factory Dispatcher for a Specific Product"

            fd = pack.__FactoryDispatcher__ = __FactoryDispatcher__

        if not hasattr(pack, '_m'):
            pack._m = AttrDict(fd)

        m = pack._m

        if interfaces is _marker:
            if instance_class is None:
                interfaces = ()
            else:
                interfaces = tuple(implementedBy(instance_class))

        Products.meta_types = Products.meta_types + (
            {
                'name': meta_type or instance_class.meta_type,
                # 'action': The action in the add drop down in the ZMI. This is
                #           currently also required by the _verifyObjectPaste
                #           method of CopyContainers like Folders.
                'action': ('manage_addProduct/%s/%s' % (pid, name)),
                # 'product': Used by ProductRegistry for TTW products and by
                #            OFS.Application for refreshing products.
                #            This key might not be available.
                'product': pid,
                # 'permission': Guards the add action.
                'permission': permission,
                # 'visibility': A silly name. Doesn't have much to do with
                #               visibility. Allowed values: 'Global', None
                'visibility': visibility,
                # 'interfaces': A tuple of oldstyle and/or newstyle interfaces.
                'interfaces': interfaces,
                'instance': instance_class,
                'container_filter': container_filter
            }, )

        m[name] = initial
        m[name + '__roles__'] = pr

        for method in constructors[1:]:
            if isinstance(method, tuple):
                name, method = method
            else:
                name = os.path.split(method.__name__)[-1]
            if name not in productObject.__dict__:
                m[name] = method
                m[name + '__roles__'] = pr

        if icon:
            name = os.path.split(icon)[1]
            icon = ImageFile(icon, self.__pack.__dict__)
            icon.__roles__ = None
            if not hasattr(misc_, pid):
                setattr(misc_, pid, Misc_(pid, {}))
            getattr(misc_, pid)[name] = icon
    def registerClass(self, instance_class=None, meta_type='',
                      permission=None, constructors=(),
                      icon=None, permissions=None, legacy=(),
                      visibility="Global", interfaces=_marker,
                      container_filter=None
        ):
        """Register a constructor

        Keyword arguments are used to provide meta data:

        instance_class -- The class of the object that will be created.

          This is not currently used, but may be used in the future to
          increase object mobility.

        meta_type -- The kind of object being created
           This appears in add lists.  If not specified, then the class
           meta_type will be used.

        permission -- The permission name for the constructors.
           If not specified, then a permission name based on the
           meta type will be used.

        constructors -- A list of constructor methods
          A method can me a callable object with a __name__
          attribute giving the name the method should have in the
          product, or the method may be a tuple consisting of a
          name and a callable object.  The method must be picklable.

          The first method will be used as the initial method called
          when creating an object.

        icon -- The name of an image file in the package to
                be used for instances. Note that the class icon
                attribute will be set automagically if an icon is
                provided.

        permissions -- Additional permissions to be registered
           If not provided, then permissions defined in the
           class will be registered.

        legacy -- A list of legacy methods to be added to ObjectManager
                  for backward compatibility

        visibility -- "Global" if the object is globally visible, None else

        interfaces -- a list of the interfaces the object supports

        container_filter -- function that is called with an ObjectManager
           object as the only parameter, which should return a true object
           if the object is happy to be created in that container. The
           filter is called before showing ObjectManager's Add list,
           and before pasting (after object copy or cut), but not
           before calling an object's constructor.

        """
        pack=self.__pack
        initial=constructors[0]
        productObject=self.__prod
        pid=productObject.id

        if icon and instance_class is not None:
            setattr(instance_class, 'icon', 'misc_/%s/%s' %
                    (pid, os.path.split(icon)[1]))

        if permissions:
            if isinstance(permissions, basestring): # You goofed it!
                raise TypeError, ('Product context permissions should be a '
                    'list of permissions not a string', permissions)
            for p in permissions:
                if isinstance(p, tuple):
                    p, default= p
                    registerPermissions(((p, (), default),))
                else:
                    registerPermissions(((p, ()),))

        ############################################################
        # Constructor permission setup
        if permission is None:
            permission="Add %ss" % (meta_type or instance_class.meta_type)

        if isinstance(permission, tuple):
            permission, default = permission
        else:
            default = ('Manager',)

        pr = PermissionRole(permission,default)
        registerPermissions(((permission, (), default),))
        ############################################################

        OM = ObjectManager

        for method in legacy:
            if isinstance(method, tuple):
                name, method = method
                aliased = 1
            else:
                name=method.__name__
                aliased = 0
            if name not in OM.__dict__:
                setattr(OM, name, method)
                setattr(OM, name+'__roles__', pr)
                if aliased:
                    # Set the unaliased method name and its roles
                    # to avoid security holes.  XXX: All "legacy"
                    # methods need to be eliminated.
                    setattr(OM, method.__name__, method)
                    setattr(OM, method.__name__+'__roles__', pr)

        if isinstance(initial, tuple):
            name, initial = initial
        else:
            name = initial.__name__

        fd = getattr(pack, '__FactoryDispatcher__', None)
        if fd is None:
            class __FactoryDispatcher__(FactoryDispatcher):
                "Factory Dispatcher for a Specific Product"

            fd = pack.__FactoryDispatcher__ = __FactoryDispatcher__

        if not hasattr(pack, '_m'):
            pack._m = AttrDict(fd)

        m = pack._m

        if interfaces is _marker:
            if instance_class is None:
                interfaces = ()
            else:
                interfaces = tuple(implementedBy(instance_class))

        Products.meta_types = Products.meta_types + (
            { 'name': meta_type or instance_class.meta_type,
              # 'action': The action in the add drop down in the ZMI. This is
              #           currently also required by the _verifyObjectPaste
              #           method of CopyContainers like Folders.
              'action': ('manage_addProduct/%s/%s' % (pid, name)),
              # 'product': Used by ProductRegistry for TTW products and by
              #            OFS.Application for refreshing products.
              #            This key might not be available.
              'product': pid,
              # 'permission': Guards the add action.
              'permission': permission,
              # 'visibility': A silly name. Doesn't have much to do with
              #               visibility. Allowed values: 'Global', None
              'visibility': visibility,
              # 'interfaces': A tuple of oldstyle and/or newstyle interfaces.
              'interfaces': interfaces,
              'instance': instance_class,
              'container_filter': container_filter
              },)

        m[name]=initial
        m[name+'__roles__']=pr

        for method in constructors[1:]:
            if isinstance(method, tuple):
                name, method = method
            else:
                name=os.path.split(method.__name__)[-1]
            if name not in productObject.__dict__:
                m[name]=method
                m[name+'__roles__']=pr

        if icon:
            name = os.path.split(icon)[1]
            icon = ImageFile(icon, self.__pack.__dict__)
            icon.__roles__=None
            if not hasattr(misc_, pid):
                setattr(misc_, pid, Misc_(pid, {}))
            getattr(misc_, pid)[name]=icon