Cleaned up main.kv and removed SerialPortDropdown from main.py
This commit is contained in:
parent
eb565fe797
commit
41d1e07749
17
main.kv
17
main.kv
|
@ -1,13 +1,3 @@
|
|||
#<MyLabel@Label>:
|
||||
# text: 'Current Temperature: n/a'
|
||||
|
||||
#<PlotWidget@Image>:
|
||||
# allow_stretch: True
|
||||
|
||||
#<SerialPortDropdown@DropDown>:
|
||||
|
||||
#<SerialPortButton@Button>:
|
||||
|
||||
<StatusWidget@BoxLayout>:
|
||||
orientation: 'horizontal'
|
||||
|
||||
|
@ -81,13 +71,6 @@
|
|||
SerialPortButton:
|
||||
id: serial_chooser_button
|
||||
on_serial_port_changed: root.serial_port_changed(self.text)
|
||||
#dropdown: serial_chooser_dropdown.__self__
|
||||
#on_release: serial_chooser_dropdown.open(self)
|
||||
#SerialPortDropdown:
|
||||
# id: serial_chooser_dropdown
|
||||
# data:
|
||||
# on_serial_port_changed: serial_chooser_button.serial_port_selected(self.data)
|
||||
# on_serial_port_changed: root.serial_port_changed(self.data)
|
||||
PlotWidget:
|
||||
id: mainplot
|
||||
size_hint_y: 0.8
|
||||
|
|
50
main.py
50
main.py
|
@ -194,56 +194,6 @@ class SerialPortButton(Spinner):
|
|||
pass
|
||||
|
||||
|
||||
class SerialPortDropdown(DropDown):
|
||||
|
||||
__events__ = ('on_serial_port_changed',)
|
||||
defaultSerialPort = '/dev/ttyACM0'
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(SerialPortDropdown, self).__init__(**kwargs)
|
||||
self.register_event_type('on_serial_port_changed')
|
||||
self.size_hint = (None, None)
|
||||
#Logger.debug(str(self.get_root_window()))
|
||||
self.on_dataSources(temp_log.list_serial_ports())
|
||||
|
||||
|
||||
def on_dataSources(self, values):
|
||||
children = self.children[:]
|
||||
values_used = []
|
||||
current_value = getattr(self.parent, 'text', None)
|
||||
while children:
|
||||
child = children.pop()
|
||||
children.extend(child.children)
|
||||
text = getattr(child, 'text', None)
|
||||
if text and text in values:
|
||||
values_used.append(text)
|
||||
#Logger.debug('Child ' + str(child) + ' is used')
|
||||
continue
|
||||
if text and text not in values:
|
||||
#Logger.debug('Child ' + str(child) + ' is now unused, to be removed')
|
||||
self.remove_widget(child)
|
||||
self.data = ''
|
||||
self.dispatch('on_serial_port_changed', '')
|
||||
# add in new children
|
||||
new_values = set(values) - set(values_used)
|
||||
for new_value in new_values:
|
||||
btn = Button(text = new_value, size_hint_y = None, height = 20)
|
||||
#Logger.debug('Child ' + str(btn) + ' added to dropdown with value ' + new_value)
|
||||
btn.bind(on_release=lambda btn: self.select(btn.text))
|
||||
self.add_widget(btn)
|
||||
|
||||
|
||||
def select(self, value):
|
||||
super(SerialPortDropdown, self).select(value)
|
||||
Logger.debug('SerialPortDropdown: ' + 'selected with args ' + str(value))
|
||||
self.data = value
|
||||
self.dispatch('on_serial_port_changed', value)
|
||||
|
||||
|
||||
def on_serial_port_changed(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
class MyLabel(Label):
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue