-
Notifications
You must be signed in to change notification settings - Fork 23
/
settingsview.py
145 lines (110 loc) · 4.26 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import kivy
from valuefield import ValueField
kivy.require('1.9.1')
from kivy.uix.label import Label
from kivy.uix.relativelayout import RelativeLayout
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 autosportlabs.uix.textwidget import TextWidget
from helplabel import HelpLabel
from kivy.app import Builder
from utils import *
from mappedspinner import MappedSpinner
from autosportlabs.racecapture.views.popup.centeredbubble import CenteredBubble, WarnLabel
from kivy.metrics import dp, sp
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(RelativeLayout):
help_text = StringProperty('')
label_text = StringProperty('')
control = None
rcid = StringProperty('')
WARN_SHORT_TIMEOUT = 0.25
WARN_LONG_TIMEOUT = 7.24
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')
self.warn_bubble = None
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)
def set_error(self, error):
if self.warn_bubble is None:
warn = CenteredBubble()
warn.add_widget(WarnLabel(text=str(error), font_size=sp(12)))
warn.background_color = (1, 0, 0, 1.0)
warn.auto_dismiss_timeout(self.WARN_LONG_TIMEOUT)
control = kvFind(self, 'rcid', 'control')
warn.size = (control.width, dp(50))
warn.size_hint = (None, None)
self.add_widget(warn)
warn.center_below(control)
self.warn_bubble = warn
def clear_error(self):
if self.warn_bubble is not None:
self.warn_bubble.auto_dismiss_timeout(self.WARN_SHORT_TIMEOUT)
self.warn_bubble = None