Esempio n. 1
0
    def initialize(self, context):
        # Add only one meta type to the folder add list.
        try:
            productObject = context._ProductContext__prod
        except AttributeError:
            productObject = context.product

        self.product_name = pid = productObject.id
        productGlobals = context._ProductContext__pack.__dict__
        context.registerClass(
            meta_type = self.meta_type,
            # This is a little sneaky: we add self to the
            # FactoryDispatcher under the name "toolinit".
            # manage_addTool() can then grab it.
            constructors = (manage_addToolForm,
                            manage_addTool,
                            self,),
            #icon = self.icon
            )
        # Lifted from ProductContext.registerClass, to avoid ImageFile
        if self.icon:
            icon_res = ImageResource(self.icon, productGlobals)
            icon_name = os_path.split(self.icon)[1]
            if not hasattr(misc_images, pid):
                setattr(misc_images, pid, MiscImage(pid, {}))
            getattr(misc_images, pid)[icon_name] = icon_res
            icon = os_path.split(self.icon)[1]

        for tool in self.tools:
            tool.__factory_meta_type__ = self.meta_type
            if self.icon:
                tool.icon = 'misc_/%s/%s' % (self.product_name, icon_name)
Esempio n. 2
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