-
Notifications
You must be signed in to change notification settings - Fork 23
/
mappedspinner.py
36 lines (27 loc) · 1.01 KB
/
mappedspinner.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
import kivy
kivy.require('1.9.1')
from kivy.uix.spinner import Spinner
class MappedSpinner(Spinner):
def __init__(self, **kwargs):
self.valueMappings = {}
self.keyMappings = {}
self.values = []
self.defaultValue = ''
super(MappedSpinner, self).__init__(**kwargs)
def setValueMap(self, valueMap, defaultValue):
keyMappings = {}
values = []
sortedValues = sorted(valueMap)
for item in sortedValues:
values.append(valueMap[item])
keyMappings[valueMap[item]] = item
self.defaultValue = defaultValue
self.valueMappings = valueMap
self.keyMappings = keyMappings
self.values = values
def setFromValue(self, value):
self.text = str(self.valueMappings.get(value, self.defaultValue))
def getValueFromKey(self, key):
return self.keyMappings.get(key, None)
def getSelectedValue(self):
return self.getValueFromKey(self.text)