up with PyGUI!

Carlos Ribeiro carribeiro at gmail.com
Fri Sep 24 10:01:49 EDT 2004


On Fri, 24 Sep 2004 15:47:33 +1200, Greg Ewing
<greg at cosc.canterbury.ac.nz> wrote:
> For a while now I've been wondering whether Python could
> benefit from an "instance" statement that works similarly
> to a class statement but creates instances instead of
> classes.

I've done something like you want using metaclasses. I've posted it as
another thread, it was a "Call for suggestions". As you may see, I'm
still looking for more people to work with me on this solution :-)
Basically what it does is to process declarations like this:

class MainFrame(FrameDescription):

    class b1(ButtonDescription):
      size = (40, 40)
      text = "b1"

... where FrameDescription and ButtonDescription are both derived from
a base Container class. When constructed, the MainFrame will contain
an **instance** called b1 from the class b1 (that's right, the same
name; the temporary class definition is gone). The metaclass creation
engine also respects the order of the declaration. The orderd list is
stored as a _fields member; in the case above, _fields[0] is size, and
_fields[1] is text. Note that the hash used to store attributes that
is passed to the metaclass can't work this magic alone.



-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list