forked from ryandoherty/RaceCapture_App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settingsview.py
122 lines (88 loc) · 3.28 KB
/
settingsview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import kivy
from valuefield import ValueField
kivy.require('1.9.0')
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.switch import Switch
from kivy.uix.button import Button
from kivy.uix.spinner import Spinner
from fieldlabel import FieldLabel
from helplabel import HelpLabel
from kivy.app import Builder
from utils import *
from mappedspinner import MappedSpinner
from kivy.properties import StringProperty
Builder.load_file('settingsview.kv')
class SettingsButton(Button):
def __init__(self, **kwargs):
super(SettingsButton, self).__init__(**kwargs)
self.register_event_type('on_control')
def on_control(self, value):
pass
def setValue(self, value):
self.active = value
def on_button_active(self, value):
self.dispatch('on_control', value)
class SettingsSwitch(Switch):
def __init__(self, **kwargs):
super(SettingsSwitch, self).__init__(**kwargs)
self.register_event_type('on_control')
def on_control(self, value):
pass
def setValue(self, value):
self.active = value
def on_switch_active(self, value):
self.dispatch('on_control', value)
class SettingsMappedSpinner(MappedSpinner):
lastValue = None
def __init__(self, **kwargs):
super(SettingsMappedSpinner, self).__init__(**kwargs)
self.register_event_type('on_control')
def on_control(self, value):
pass
def setValue(self, value):
self.setFromValue(value)
def on_text(self, instance, value):
if not value == self.lastValue: #eh.. prevent double firing of event. is there a better way?
self.dispatch('on_control', instance.getValueFromKey(value))
self.lastValue = value
class SettingsTextField(ValueField):
def __init__(self, **kwargs):
super(SettingsTextField, self).__init__(**kwargs)
self.register_event_type('on_control')
def on_control(self, value):
pass
def setValue(self, value):
self.text = value
def on_text(self, instance, value):
self.dispatch('on_control', value)
class SettingsView(BoxLayout):
help_text = StringProperty('')
label_text = StringProperty('')
control = None
rcid = StringProperty('')
def __init__(self, **kwargs):
super(SettingsView, self).__init__(**kwargs)
self.bind(help_text = self.on_help_text)
self.bind(label_text = self.on_label_text)
self.register_event_type('on_setting')
def on_setting(self, *args):
pass
def on_control(self, instance, value):
self.dispatch('on_setting', value)
pass
def on_help_text(self, instance, value):
help = kvFind(self, 'rcid', 'helpLabel')
help.text = value
def on_label_text(self, instance, value):
label = kvFind(self, 'rcid', 'fieldLabel')
label.text = value
def setControl(self, widget):
widget.size_hint_y=1.0
kvFind(self, 'rcid', 'control').add_widget(widget)
widget.bind(on_control=self.on_control)
self.control = widget
def setValue(self, value):
if self.control:
self.control.setValue(value)