[Zope] ZClass Property Sheet Question

Tres Seaver tseaver@palladion.com
Tue, 18 Jan 2000 15:57:24 -0600


"James W. Howe" <jwh@allencreek.com> wrote:
> 
> I'm trying to define some properties for a ZClass that I'm writing.  I want
> to create a property which can be one of several values.  I click on my
> ZClass and select the Property Sheets tab.  I then select the item which
> contains the properties which I want to edit.  I'm then presented with the
> page which lets me add or delete properties.  I enter a new property name,
> select "selection" as the type and then I'm not sure what to do next.  The
> text of the page seems to indicate that I need a property or method which
> returns a list of strings, but I'm not entirely sure how to do this.  Can
> someone explain to a newbie how to initially populate a selection property?

You need to have a method accessible to the property sheet which returns a list
of strings.  This can be an ExternalMethod, a PythonMethod, or a DTMLMethod (but
watch out for the acquisition path on these!)

Here is one example:  in the Extensions subdirectory of FooProduct, I have a
file, Utilities.py::

  #
  #  Utility methods for FooProduct -- install with module name
FooProduct.Utilities.
  #
  def BarTypes():
      """ Return list of possible values for the barType property. """
      return [ 'baz', 'bam', qux' ]

Then, in Zope's Control Panel | Products | FooProduct, add an ExternalMethod,
BarTypes:

  Title               = <<empty -- put parameters here if you use 'em>>
  Function Name       = BarTypes
  Python Module File  = FooProduct.Utilities

Finally, in the property sheet of ZClass FooProduct.Bar, add a property barType,
selecting the 'selection' drop down and entering 'BarTypes' into the 'Value'
field -- the property sheet will
then use the BarTypes method to populate its dropdown.

NOTE:

I currently have to clone the ExternalMethod into the FooProduct.Bar class to
make it usable from the location in which a FooProduct.Bar instance lives!  The
property sheet can't see the method in the class when invoked within the
product, but can't see the method in the product when in the main tree!  Uggh!

Hope this helps!

Tres.
-- 
=========================================================
Tres Seaver         tseaver@palladion.com    713-523-6582
Palladion Software  http://www.palladion.com