[Pyobjc-dev] How to do it? Possible or not..
Brought to you by:
ronaldoussoren
|
From: <dzi...@al...> - 2008-01-12 18:35:57
|
Hi!
Could somebody help me to solve this problem or explain why it's =20
impossible in Cocoa/pyObjC?
Please....
Here is a pure python:
class SimpleValue:
def __init__(self):
self.type =3D 0
self.value =3D 0
self.source =3D None
=09
def __call__(self):
if self.type =3D=3D 0:
return self.value
elif self.type =3D=3D 1:
return self.source() #here is a trick: if =
type of my variable =20
is 1, __call__ will return source method result :-)
else: print "Type %s is not supported, ERROR"
=09
a =3D SimpleValue()
a.value =3D 777
b =3D SimpleValue()
b.type =3D 1
b.source =3D a
tab =3D [a, b]
print "a.type =3D %s, b.type =3D %s" % (tab[0].type, tab[1].type)
print "a.value =3D %s, b.value =3D %s" % (tab[0].value, tab[1].value)
print "a.source =3D %s, b.source =3D %s"% (tab[0].source, tab[1].source)
print "a() =3D %s, b() =3D %s" % (tab[0](), tab[1]())
The result is nice:
a.type =3D 0, b.type =3D 1
a.value =3D 777, b.value =3D 0
a.source =3D None, b.source =3D <__main__.Value instance at 0x16ed9af8>
a() =3D 777, b() =3D 777
I'm trying to do the same thing in XCode Cocoa application. So I made =20=
two classes:
First one is almost same as above:
class SimpleValue (NSObject):
type =3D ivar(u'type')
value =3D ivar(u'value')
source =3D ivar(u'source')
def __call__(self):
if self.type =3D=3D 0:
return self.value
elif self.type =3D=3D 1:
return self.source()
else: print "Type %s is not supported, ERROR"
Second just class to preview results in window...
class TestView(NibClassBuilder.AutoBaseClass):
elements =3D ivar(u'elements')
def awakeFromNib(self):
a =3D SimpleValue.alloc().init()
a.value =3D 777
a.type =3D 0
b =3D SimpleValue.alloc().init()
b.type =3D 1
b.source =3D a
# !!!!!! here application exploding....Why!!! !!!!!!!!!!!!#
self.elements =3D [a, b]
#elementsController is defined in NIB
self.elementsController.setContent_(self.elements)
# if b.source is changed to "tralala" or 6, nice tab shows a =
and b
Python 2.4 MacOSX 10.4..
best 4 all
=C5=81ukasz
=09
|