from somewhere.cpia_templates import Menu, MenuItem

Menu("FileMenu", _('File'), [
    Menu("NewMenu", _('New...'), [
        MenuItem("NewMessageItem", _("Message"), ...),
        MenuItem("NewNoteItem",    _("Note"), ...),
    ])
]).install(parcel)

Wow. If you can explain a little more about how to do this, I'll throw away all of my XmlForCpia work - seriously :)

do you mean that "Menu" is just a template wrapper around the Menu class, or that we're somehow making the Menu class also implement this template class?

i.e. is this something like, in somewhere.cpia_templates:

from osaf.framework import Blocks
Menu = template(Blocks.Menu)?

Alec

where the translation is something like:

    class template(object):
        child_attrs = ()
        target_class = None

        def __init__(self, itsName, **attrs):
            self.attrs = attrs
            self.itsName = itsName

        def install(parent,name=None):
            if name is None: name=self.itsName
            me = target_class.update(parent,name)  # make parent exist
            attrs = self.attrs.copy()
            for attr in self.child_attrs:
                if attr in attrs:
                    attrs[attr] = [
                        t.install(me) for t in attrs[attr]
                    ]
            return target_class.update(parent,name,**attrs)

    class Menu(template):
        child_attrs = ('childrenBlocks',)
        target_class = blocks.Menu

        def __init__(self, itsName, title, ..., **attrs):
            super(Menu,self).__init__(itsName, title=title, ..., **attrs)

You'll notice that this relatively simple arrangement can takes care of all your requests except item #3, which I'd need to think about a little more before proposing a solution.

Also, although I've written this as a set of template classes, this could be hacked a little so there's only one template class, and everything else is a factory method on the target classes.


But this is basically xml-translated-into-lists-and-dicts and seemed a little silly - I mean when writing it its harder to figure out the correct syntax, brace balancing, and so forth.. furthermore you'd STILL have to write some sort of processor for this datastructure. Since there are tools to do this for you with XML (emacs, eclipse, you name it) it just makes more sense to me to do this in XML

If you have another specific suggestion for improving cpia's API to make this cleaner, I'm all ears.


_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Open Source Applications Foundation "Dev" mailing list
http://lists.osafoundation.org/mailman/listinfo/dev

Reply via email to