[PyCrust] __setattr__ no longer strict
Brought to you by:
pobrien
|
From: Kevin A. <al...@se...> - 2001-08-14 07:42:06
|
The attribute checks used to be strict, but now they're not.
>>> comp.button1.bob = "hello"
shouldn't be possible, since there is no 'bob' attribute. I found this while
trying to decide how I was going to deal with attributes that can only be
set at initialization. What I came up with was to go ahead and define a _get
and _set but have the _set method raise an exception. As an example, I
changed StaticLine and checked in widget.py.
class StaticLine( Widget ) :
...
def _setLayout( self, aString ) :
raise NotImplementedError
def _getLayout( self ) :
return self._layout
So, then I tried:
>>> comp.staticlineH.layout
'horizontal'
>>> comp.staticlineH.layout = 'bob'
The layout = 'bob' should throw an exception, but it doesn't for some
reason?! I tried this standalone in proof.py and in the shell and got the
same results. I added a _setName to the Widget class that does the same
NotImplementedError.
Maybe your original was better before we were trying to get the
self._magicGetPrefix to work?!
On a lighter note, it is sort of fun to define toolTips on the fly.
comp.button1.toolTip = 'Hello World'
And I sure do like not have _ and __ show up anymore.
ka
|