An attempt to use a python-based mini declarative language for form definition

Mike C. Fletcher mcfletch at
Wed Sep 22 20:00:53 CEST 2004

This is just a sketch, you should do the code properly...

class BaseWidget:
    counter = 0
    def __init__( self ):
       BaseWidget.counter += 1
       self.__id = BaseWidget.counter
    def __cmp__( self, other ):
       return cmp( , )

class  TextBox( BaseWidget ):

Make it thread safe, elegant, fully-comparable, etceteras, then just 
sort the list of widgets you get for any given instance of Form.  Isn't 
precisely defined as the order they appear in the definition (they could 
be created elsewhere and included), but short of just putting them in a 
list-attribute and injecting them in the class with the metaclass (which 
is what I'd do), looks like a pretty good bet.


Carlos Ribeiro wrote:

>-- I've tried using metaclasses or other similar magic; I've read the
>tutorials, tried some code, and read sqlobject own implementation.
>This is not a problem for sqlobject, because the order of the columns
>in the database is totally isolated from the object representation.
>But in my case, it is a problem, because I need the fields to be in
>the correct order in the display.
>My question is, there is any way to retrieve the class attributes in
>the order they were declared? I could not find any; __setattr__ won't
>work because the dict is constructed using the native dict type before
>__new__ has a chance at it. Is there anything that I'm overlooking?
  Mike C. Fletcher
  Designer, VR Plumber, Coder

More information about the Python-list mailing list