kivy/kivy — pull request #1937 by matham (2014-03-06 06:34:50+00:00)
Title: Adds a ConfigParserProperty class

This adds a ConfigParserProperty class to allow binding and controlling a ConfigParser values from other properties. See the class doc for details.

An example that goes with it is below. You'll notice that after typing stuff and closing and restarting kivy, the textinputs will be auto fileed with the config values.::

from kivy.lang import Builder
from kivy.app import runTouchApp
from kivy.uix.label import Label
from kivy.properties import ConfigParserProperty
from kivy.config import ConfigParser
import os

class UserInfo(Label):

name = ConfigParserProperty('', 'info', 'name')
address = ConfigParserProperty('', 'info', 'address')

def __init__(self, **kw):
super(UserInfo, self).__init__(**kw)
if not os.path.exists('info.ini'):
with open('info.ini', 'w'):
pass
config = ConfigParser()
config.read('info.ini')
self.name = config
self.address = config

kv = '''
BoxLayout:
orientation: 'vertical'
GridLayout:
cols: 2
TextInput:
on_text: info.name = self.text
text: info.name
TextInput:
on_text: info.address = self.text
text: info.address
UserInfo:
id: info
text: 'Name: {}\\nAddress: {}'.format(self.name, self.address)
'''

runTouchApp(Builder.load_string(kv))