the misc_ dictionary
Hi all, I'm a little bit confused on how to use the misc_ dictionary to define product resources. I've looked into other products such as ZCatalog ZGadflyDA and SiteAccess but it's use is not so clear for me especially because most products only need to associate an icon with a python class. Someone can explain a bit more how to use it? There is an usege policy? thanks in advance Alberto
On Wed, 14 Feb 2001 15:31:02 +0100 aZaZel <azazel@planningsrl.it> wrote:
Hi all,
I'm a little bit confused on how to use the misc_ dictionary to define product resources. I've looked into other products such as ZCatalog ZGadflyDA and SiteAccess but it's use is not so clear for me especially because most products only need to associate an icon with a python class.
Someone can explain a bit more how to use it?
There is an usege policy?
thanks in advance
Ok... i still don't know if there is a policy for the use of misc_ but i have resolved my problems
[azazel@planningsrl.it] | Ok... i still don't know if there is a policy for the use of misc_ but | i have resolved my problems This is how I use it in my __init__.py file in the product directory (ie. lib/python/Products/ProductX): __init__.py file: ##################################################################### __doc__ = 'Initialize the rs product.' __version__='$Revision: 1.1 $'[11:-2] from ImageFile import ImageFile misc_ = { 'Folder_icon.gif': ImageFile('img/Folder_icon.gif', globals()), 'dtmldoc.gif': ImageFile('img/dtmldoc.gif', globals()), } import rs def initialize(context): "Initialize the product." try: context.registerClass( rs.rs, constructors = (rs.manage_addrsForm, rs.manage_addrs) ) context.registerHelp() context.registerHelpTitle('Zope/rs 2000 Help') except: import sys, traceback, string type, val, tb = sys.exc_info() sys.stderr.write(string.join(traceback.format_exception(type, val, tb), '')) del type, val, tb ##################################################################### This then allows me to do http://myhost/misc_/rs/Folder_icon.gif Hope this helps :)
On Thu, Feb 15, 2001 at 11:59:58AM +0100, Erik Enge wrote:
[azazel@planningsrl.it]
| Ok... i still don't know if there is a policy for the use of misc_ but | i have resolved my problems
This is how I use it in my __init__.py file in the product directory (ie. lib/python/Products/ProductX):
__init__.py file:
#####################################################################
__doc__ = 'Initialize the rs product.' __version__='$Revision: 1.1 $'[11:-2]
from ImageFile import ImageFile
misc_ = { 'Folder_icon.gif': ImageFile('img/Folder_icon.gif', globals()), 'dtmldoc.gif': ImageFile('img/dtmldoc.gif', globals()), }
import rs
def initialize(context): "Initialize the product." try: context.registerClass( rs.rs, constructors = (rs.manage_addrsForm, rs.manage_addrs) ) context.registerHelp() context.registerHelpTitle('Zope/rs 2000 Help') except: import sys, traceback, string type, val, tb = sys.exc_info() sys.stderr.write(string.join(traceback.format_exception(type, val, tb), '')) del type, val, tb
#####################################################################
This then allows me to do http://myhost/misc_/rs/Folder_icon.gif
Hope this helps :)
The use of misc_ in the __init__.py of a Product is deprecated for Product icons though; it is still useful for registering extra icons. As for your try/except construct, this one of the first things that Shane Hathaway made unnecessary by hardening the registration process. Exceptions in the initialize method are now logged or printed to stdout. Your code could be simplified to: from ImageFile import ImageFile misc_ = { 'Folder_icon.gif': ImageFile('img/Folder_icon.gif', globals()) } import rs def initialize(context): "Initialize the product." context.registerClass( rs.rs, icon='img/dtmldoc.gif', constructors=(rs.manage_addrsForm, rs.manage_addrs)) context.registerHelp() context.registerHelpTitle('Zope/rs 2000 Help') The rs.rs class can the also omit the icon property. -- Martijn Pieters | Software Engineer mailto:mj@digicool.com | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ ---------------------------------------------
[Martijn Pieters] | As for your try/except construct, this one of the first things that Shane | Hathaway made unnecessary by hardening the registration process. Ok, for which version? This __init__.py was initally written back in September :) | The rs.rs class can the also omit the icon property. Yeah, but what about all the other classes in the rs Product? They still have to have the icon property, and then it starts drift a bit: some classes their icon definition «in themselves», while this one (rs) doesn't. Correct? If so, I don't like that, and don't think I'll use it. Can't really see why it would be benefitial actually, I'm probably missing something here.
On Thu, Feb 15, 2001 at 02:17:00PM +0100, Erik Enge wrote:
[Martijn Pieters]
| As for your try/except construct, this one of the first things that Shane | Hathaway made unnecessary by hardening the registration process.
Ok, for which version? This __init__.py was initally written back in September :)
I believe that the last bug preventing logging of Product import and initialization exceptions was squashed in the 2.2.1 release; output of tracebacks was fixed.
| The rs.rs class can the also omit the icon property.
Yeah, but what about all the other classes in the rs Product? They still have to have the icon property, and then it starts drift a bit: some classes their icon definition ?in themselves?, while this one (rs) doesn't. Correct? If so, I don't like that, and don't think I'll use it. Can't really see why it would be benefitial actually, I'm probably missing something here.
It is a simplification of the most common case; usually only registered classes appear in the ZMI and therefor need an icon. Indeed, if you have a Product that has classes that will also appear in the ZMI, but have no need to be registered (because they aren't user-addable?) then the old method may be easier to maintain for you. -- Martijn Pieters | Software Engineer mailto:mj@digicool.com | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ ---------------------------------------------
On Thu, 15 Feb 2001 17:33:45 +0100 Martijn Pieters <mj@digicool.com> wrote:
It is a simplification of the most common case; usually only registered classes appear in the ZMI and therefor need an icon.
This also my case.. i need some extra little gifs in the management screens of my products
Indeed, if you have a Product that has classes that will also appear in the ZMI, but have no need to be registered (because they aren't user-addable?) then the old method may be easier to maintain for you.
some classes will be added only into the main's product class thanks for your explanation! alberto
participants (3)
-
aZaZel -
Erik Enge -
Martijn Pieters