Am 20.01.2009, 20:45 Uhr, schrieb Christopher Barker
<[email protected]>:
> Marcos Duarte wrote:
>> My idea is to provide a popup menu to change the properties of the
>> selected object and the shown menu items will depend of the type of
>> object.
>
> There really should be a better way to get a list of changeable
> properties, that doesn't depend on an external mapping of names to
> property types...
>
> This is the kind of think that enthought Traits are good for-- but they
> have other problems.
>
> Matt?
Here would our model interfaces come into play (defined in
floatcanvas/models/interfaces.py). Since we had that hassle with traits
and zope.interface I chose to implement them myself. This also means
there's no support for attributes now. Here's an example:
class IArc(object):
# radius prop
# startAngle, endAngle props
# clockwise prop
pass
As you can see the properties are only defined as comments. Better would be
class IArc(object):
radius = Attribute()
startAngle = Attribute()
endAngle = Attribute()
clockwise = Attribute()
or
class IArc(object):
properties = [ 'radius', 'startAngle', 'endAngle', 'clockwise' ]
Besides from fixing the interface stuff one could also do
"vars(node.model)" and then filter this. I think you'd only have to filter
out the observables stuff, the default model classes themselves have only
the attributes which are also declared in the interfaces, no more.
-Matthias
P.S.: If anybody is interested in adding attributes to the interfaces, it
would roughly go like this (working with approach #2 above; I wrote the
code here from scratch, it's not tested and the reference to
AdapterRegistry._getImplementedInterfaces is ugly):
from fc.patterns.adapter import AdapterRegistry
def getInterfaceAttributesOfObject(obj):
interfaces = AdapterRegistry._getImplementedInterfaces(obj)
attributes = {}
for interface in interfaces:
try:
thisAttributes = interface.properties
except AttributeError:
pass
else:
for name in thisAttributes:
attributes[ name ] = getattr(obj, name)
return attributes
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas