up with PyGUI!

Carlos Ribeiro carribeiro at gmail.com
Sat Sep 25 01:32:19 EDT 2004


On Fri, 24 Sep 2004 22:12:46 -0700 (Pacific Standard Time), Brendan
Barnwell <brenbarn at brenbarn.net> wrote:
>         My implementation essentially does this as well.  However, I
> have devised a metaclass (called ClassObj) that does not actually
> replace the class with an instance.  Instead, each class keeps a reference
> to singleton instance.  All attributes are stored on the class object, but
> methods are forwarded to the instance (since Python won't allow you
> to call methods on a class).  The advantage of this is that the classes
> can even be subclassed.  This metaclass largely eliminates the
> distinction between classes and objects; a ClassObj can effectively
> function as either.

Well, it took me sometime to figure out if I should leave inner
classes as classes or instantiate them. It's funny because my approach
ends up being similar to yours -- the class is instantiated by the
metaclass, and in the process the original class declaration is lost,
which means that it turns into a singleton for all practical purposes.

The reasons why I decided to instantiate inner classes were:

1) It's easier to process the resultin class declaration, because all
attributes are instances. Before doing it I had to put some "isclass"
checks to take different actions depending on the type of the
attribute. It's not needed anymore (not to the same extent, at least).

2) The original class is not needed really for subclassing. It's not
convenient anyway, because you'ld need dot notation to find the inner
class declaration. My suggestion is that all classes that are supposed
to be subclassed can be safely declared at the top level, as in:

class i_am_a_baseclass(Container):
    attr0 = "zzz"

class outer_class(Container):
    class inner_class_1(Container):
        attr1 = "a"
        attr2 = "b"
    class inner_class_1(i_am_a_baseclass):
        attr3 = "r"
        attr4 = "s"

As of now, I really don't know for sure which approach is better. More
experimentation is needed to check what makes more sense in the long
run not only for me (and you), but for other users having a first try
at this concept.
 
>         I'm definitely interested.  I have put my work-in-progress code up
> if you want to look at it.  It is at http://www.brenbarn.net/misc/gui/
> (You may have to change the import statements in the files slightly; I
> haven't bothered to make sure the directory structure there is the same
> as on my local system.)  This is obviously incomplete, but it gives an
> idea of the kind of thing I am doing.  Let me know what you think!

Thanks for the code -- now it's really late (2:30am), and I need to
sleep... I'll try to check it tomorrow with a fresh mind.

As for my code, I've changed heavily the code that I've posted
yesterday. I've tested some alternatives and dropped parts of the
code. It's simpler and easier to reuse now. I'm debuggin some advanced
stuff now -- weird bugs pop up sometimes :-P

-- 
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