-
Notifications
You must be signed in to change notification settings - Fork 23
/
channelnameselectorview.py
73 lines (57 loc) · 2.64 KB
/
channelnameselectorview.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
import kivy
kivy.require('1.9.1')
from kivy.app import Builder
from kivy.metrics import dp
from kivy.uix.popup import Popup
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty, ListProperty
from utils import *
from autosportlabs.racecapture.views.configuration.channels.channelsview import ChannelEditor
from autosportlabs.racecapture.data.channels import *
Builder.load_file('channelnameselectorview.kv')
class ChannelNameSelectorView(BoxLayout):
channel_type = NumericProperty(CHANNEL_TYPE_UNKNOWN)
filter_list = ListProperty([])
channel_config = None
runtime_channels = None
def __init__(self, **kwargs):
super(ChannelNameSelectorView, self).__init__(**kwargs)
self.register_event_type('on_channels_updated')
self.register_event_type('on_channel')
self.bind(channel_type = self.on_channel_type)
def on_filter_list(self, instance, value):
self.ids.channel_name.filterList = value
def on_channels_updated(self, runtime_channels):
self.runtime_channels = runtime_channels
self.ids.channel_name.dispatch('on_channels_updated', runtime_channels)
def on_channel_type(self, instance, value):
self.ids.channel_name.channelType = value
def setValue(self, value):
self.channel_config = value
self.set_channel_name(value.name)
def set_channel_name(self, name):
self.ids.channel_name.text = str(name)
def on_channel_selected(self, instance, value):
channel_meta = self.runtime_channels.findChannelMeta(value, None)
if channel_meta is not None:
self.channel_config.name = channel_meta.name
self.channel_config.units = channel_meta.units
self.channel_config.min = channel_meta.min
self.channel_config.max = channel_meta.max
self.channel_config.precision = channel_meta.precision
self.dispatch('on_channel')
def _dismiss_editor(self):
self._popup.dismiss()
def on_customize(self, *args):
content = ChannelEditor(channel = self.channel_config)
popup = Popup(title = 'Customize Channel',
content = content,
size_hint=(None, None), size = (dp(500), dp(220)))
popup.bind(on_dismiss=self.on_edited)
content.bind(on_channel_edited=lambda *args:popup.dismiss())
popup.open()
def on_edited(self, *args):
self.set_channel_name(self.channel_config.name)
self.dispatch('on_channel')
def on_channel(self):
pass