On Wed, 2005-06-22 at 14:38 +0200, Maik Hertha wrote:
> >  I'm sure many people have been wondering over the years why we have to
> >do this:
> >     label.set_property("text", "hello")
> >
> >instead of this:
> >     label.text = "hello"
> >  
> >
> I would suggest to look to gtkmm or libxml or gtk#.
> 
> gtkmm:
> They use property_... for accessing each available property. As property 
> is a reserved word of python beginners of pygtk might be muddled.
> 
> libxml2:
> They use properties (get_properties) for the whole list of properties a 
> node might have. To access a single property there are several 
> ..Prop-methods.
> 
> gtk#:
> In gtk# the properties are mixedcased words. So the label.text property 
> is accessable as label.Text, the use-markup property as label.UseMarkup.
> 
> conlusion:
> As there are different solutions in the opensource world we should look 
> for one that is closest to the language. I suggest to use label.text, 
> because a second level will be time consuming (?) in the python class 
> resolution. Not for one access but for many.
> Python has introduced not only the property keyword, also the __slot__ 
> list. This could be used to encapsulate all the public properties at 
> class-level. All the properties before this class (parent direction) are 
> available without changing everything in parents scope. If the situation 
> will come that a new property of gtk+  > 2.6 superseds a pygtk property 
> that could be handled at class level in the __getattribute__ method for 
> instance.

  No, but there aren't any "pygtk vs gtk properties".  PyGTK properties
would be == gtk properties: a direct mapping.  PyGTK would automagically
create python properties for each GObject property.  I don't see what
you mean by "that could be handled at class level in the
__getattribute__ method".

  Also please note that the use of __slot__ is bad as it impedes
defining new instance attributes in a subclass' __init__.

  The problem I'm describing is not specific to PyGTK properties.  All
python properties have this problem, if not see:

  This works:
------------------------------------
class Foo(object):
    def get_xxx(self):
        print "DO SOMETHING"
        return self.__xxx
    def set_xxx(self, val):
        print "DO SOMETHING ELSE"
        self.__xxx = val

    #xxx = property(get_xxx, set_xxx)

class Bar(Foo):
    def __init__(self):
        Foo.__init__(self)
        self.xxx = 123

Bar()
------------------------------------

  Now try uncommenting the xxx property definition.  Then you suddenly
get "DO SOMETHING ELSE" printed on the console.  For that reason,
label.text will not be supported; that is not even up for discussion.
Unless you know some trick that I don't to make this work.  But note
that custom workarounds in pygtk code for property X or Y don't count.
The code must remain absolutely generic.  If you upgrade gtk and not
pygtk, new properties may appear underneath you, and that is
intentional.

  So, it looks like now the only two candidates are label.props.text and
label.properties.text.  Regarding the use of 'properties', I'd like to
point out that it is difficult to write with correct spelling for
non-english native speakers, thus I prefer props.

  Regards.

-- 
Gustavo J. A. M. Carneiro
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
The universe is always one step beyond logic.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to