xbmc/xbmc — pull request #2875 by Montellese (2013-06-14 08:15:22+00:00)
Title: [codegenerator] python: add support for class variables

Call me crazy but I thought I'd look a bit into our codegenerator to get to know it a bit better.

I already noticed last year that the current python code/binding generator does not support class variables even though the python C API supports it through tp_getset. So I adjusted the swig template used to generate the python code/bindings to handle public class variables. There are read-write and read-only class variables where read-only class variables are defined using "const" in the C++ class definition.

Currently we don't use class variables anywhere (well we do but they aren't meant to be exposed to python so I had to hide them from swig) but I wrote a very simple example at 7d7ac06df55306a185f6df70adec282163eb7c87 so you can see how it would work. With that change to the InfoTagVideo class and this PR it is possible to e.g. execute the following script (yes my python skills suck)
```python
import xbmc

video = xbmc.InfoTagVideo()
print 'video.testInt = ' + str(video.testInt)
print 'video.testFloat = ' + str(video.testFloat)
print 'video.testDouble = ' + str(video.testDouble)
print 'video.testString = ' + video.testString
print 'video.pi = ' + str(video.pi)
video.testInt = 1
video.testFloat = 1.1
video.testDouble = 1.2
video.testString = 'goodbye world'
print 'video.testInt = ' + str(video.testInt)
print 'video.testFloat = ' + str(video.testFloat)
print 'video.testDouble = ' + str(video.testDouble)
print 'video.testString = ' + video.testString
video.pi = 200
```
which will result in the following output when executed
```
video.testInt = 42
video.testFloat = 42.0999984741
video.testDouble = 42.2000007629
video.testString = hello world
video.pi = 3.142
video.testInt = 1
video.testFloat = 1.10000002384
video.testDouble = 1.2
video.testString = goodbye world

EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type:
Error Contents: attribute 'pi' of 'xbmc.InfoTagVideo' objects is not writable
Traceback (most recent call last):
File "D:\Projects\Custom\xbmc\portable_data\userdata\python_properties.py", line 17, in
video.pi = 200
AttributeError: attribute 'pi' of 'xbmc.InfoTagVideo' objects is not writable
-->End of Python script error report<--
```

With this we can make use of direct getters and setters without any extra method but obviously there's no way to error-check the stored value in the setter etc. If we'd want that someday we'll have to think of some "workaround".