dafx / pyo

Automatically exported from code.google.com/p/pyo
GNU General Public License v3.0
0 stars 0 forks source link

Add properties to base classes to make classes more "pythonic" #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice to use the property() method of the class to make the
syntax more pythonic, example for a Since :

sine = Sine()
sine.freq = 400
sine.phase = 0.5

Nice thing about this is you can use both methods (s.freq = value or
s.setFreq and it will behave the same)

The code for the class would look like this :
{{{
class Sine(PyoObject):
    def __init__(self, freq=1000, phase=0, mul=1, add=0):
        freq, phase, mul, add, lmax = _convertArgsToLists(freq, phase, mul,
add)
        self._base_objs = [Sine_base(_wrap(freq,i), _wrap(phase,i),
_wrap(mul,i), _wrap(add,i)) for i in range(lmax)]

    def setFreq(self, x):
        x, lmax = _convertArgsToLists(x)
        [obj.setFreq(_wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setPhase(self, x):
        x, lmax = _convertArgsToLists(x)
        [obj.setPhase(_wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    @property 
    def freq(self):
        # return the freq value here

    @freq.setter
    def freq(self, x):
        self.setFreq(x)

}}}

Original issue reported on code.google.com by leca...@gmail.com on 17 Nov 2009 at 8:30

GoogleCodeExporter commented 9 years ago
Update: for this to work the base PyoObject would need to derive from object :
class PyoObject(object)

Original comment by leca...@gmail.com on 17 Nov 2009 at 8:41

GoogleCodeExporter commented 9 years ago
it's implemented...

Original comment by belan...@gmail.com on 25 Nov 2009 at 4:58