from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.settings import SettingsWithSidebar
import json
settings_json = json.dumps([
{'type': 'title', 'title': 'example title'},
{'type': 'bool', 'title': 'A boolean setting',
'desc': 'Boolean description text', 'section': 'example',
'key': 'boolexample'},
{'type': 'numeric', 'title': 'A numeric setting',
'desc': 'Numeric description text', 'section': 'example',
'key': 'numericexample'},
{'type': 'options', 'title': 'A options setting',
'desc': 'Options description text', 'section': 'example',
'key': 'optionsexample', 'options': ['option1', 'option2', 'option3']},
{'type': 'string', 'title': 'A string setting',
'desc': 'String description text', 'section': 'example',
'key': 'stringexample'},
{'type': 'path', 'title': 'A path setting',
'desc': 'Path description text', 'section': 'example',
'key': 'pathexample'},
])
Builder.load_string('''
<Interface>:
orientation: 'vertical'
Button:
text: 'open the settings!'
font_size: 150
on_release: app.open_settings()
''')
class Interface(BoxLayout):
pass
class SettingsApp(App):
def build(self):
self.settings_cls = SettingsWithSidebar
return Interface()
def build_config(self, config):
config.setdefaults('example',{
'boolexample': True,
'numericexample': 10,
'optionsexample': 'option2',
'stringexample': 'some_string',
'pathexample': '/some/path'
})
def build_settings(self, settings):
settings.add_json_panel('Panel Name', self.config, data=settings_json)
SettingsApp().run()
reference:
No comments:
Post a Comment