[Zope] object icons

Loren Stafford lstaffor@dynalogic.com
Wed, 23 Feb 2000 08:14:55 -0800


Thanks, Michel and Martijn,

But the original question was how to set the icon without registering the
class. The product makes some objects itself, but doesn't want to register
the class for users to make those objects. I have a similar situation for
the global schedule structure for event scheduling. It these cases there is
no other way but the old interface, right? If so, I would hope that old
interface never disappears.

-- Loren

From: Michel Pelletier <michel@digicool.com>


> Loren Stafford wrote:
> >
> > I'm not sure; but I inherited some code that works like this:
> >
> > # Set the icon for the MyClass, because it doesn't act
> > # like a regular object, so I can't use registerClass
> > misc_ = { 'MyClassIcon': ImageFile('www/MyIcon.gif', globals()) }
> >
> > Apparently, in this case, the ID is constructed as <MyClassID>+'Icon';
> > because there is no corresponding icon=... statement anywhere. But, I
can't
> > find the Zope code that does this; so, I might be deceived.
>
> This is the old, but still backward compatable way to assign an icon to
> a class.  You can also assign the icon as a class attribute of a class,
> or you can use the new, udocumented Product registration interface.  I'm
> taking notes on undocumented interfaces, you just found one.
>
> Zope now looks for a method in your Product's __init__.py file.  These
> methods are passed a registration context with which they register
> themselves with Zope.  Here I have heavily commented ZCatalog's
> registration methods.  The key of it is a function you define called
> 'initialize'.  Zope will call this and pass a registration context which
> defines the interface for Products to register themselves with Zope's
> various services (like the managment interface, security,
> subclassability, the help system, and yes, icons).
>
>
> ## import your various classes and thingies:
>
> import ZCatalog, Catalog, CatalogAwareness, Vocabulary
>
> def initialize(context):
>
>     ## to register a new Zope managable object, call this method on
>     ## the context, passing it the class, permission to protect the
>     ## 'constructors', the two constructors (form and action tuple) the
>     ## permission protects, and lastly, the icon.
>
>     context.registerClass(
>         ZCatalog.ZCatalog,
>         permission='Add ZCatalogs',
>         constructors=(ZCatalog.manage_addZCatalogForm,
>                       ZCatalog.manage_addZCatalog),
>         icon='www/ZCatalog.gif',
>         )
>
>     ## registerClass can be called as many times as there are objects
>     ## that your Product provides.  In this case, we also register
>     ## Vocabularies.
>
>     context.registerClass(
>         Vocabulary.Vocabulary,
>         permission='Add Vocabularies',
>         constructors=(Vocabulary.manage_addVocabularyForm,
>                       Vocabulary.manage_addVocabulary),
>         icon='www/Vocabulary.gif',
>         )
>
>     ## If you want your classes to be subclassable as ZClasses, call
>     ## 'registerBaseClass' on the context, passing it the class.
>
>     context.registerBaseClass(ZCatalog.ZCatalog)
>     context.registerBaseClass(CatalogAwareness.CatalogAware)
>
>     ## finally, register the Help system for your Product (if any)
>     context.registerHelp()
>
>
> This is the new, 'supported' product registration, and we encourage
> everyone to evolve their product to it.
>
> -Michel
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>