Added mac-address labels to dropdown buttons

Signed-off-by: Ivan Lebedev <lisgml@gmail.com>
This commit is contained in:
Ivan Lebedev 2022-05-19 21:17:23 +03:00
parent 69d195a9d1
commit 395b976cf9
No known key found for this signature in database
GPG Key ID: CFCF525BA4CD4E2C

37
main.py
View File

@ -14,8 +14,8 @@ import urls as urls
from kivy.core.clipboard import Clipboard
from kivy.storage.jsonstore import JsonStore
DEBUG=False
#DEBUG=True
# DEBUG=False
DEBUG=True
def debug_print(*xargs):
if DEBUG:
@ -93,8 +93,16 @@ class MyInput(TextInput):
pass
class MyDDKeyButton(Button):
pass
def __init__(self, mac_, ak_, *args, **kwargs):
super().__init__(*args, **kwargs)
self.mac = mac_
self.ak = ak_
self.text = f'[{self.mac}]: {self.ak}'
def cpy(self, button):
self.text = button.text
self.ak = button.ak
self.mac = button.mac
class Main(App):
def build(self):
@ -213,21 +221,21 @@ class Main(App):
rows_layout.add_widget(self.paste_token_input_layout)
result_value_label=MyButton(text='Found key')
self.result_value_value = MyDDKeyButton(text="No keys yet")
self.result_value_value = MyDDKeyButton("No keys yet", "")
self.ddown=DropDown()
self.result_value_value.bind(on_release=self.ddown.open)
self.ddown.bind(on_select=lambda instance, x: setattr(self.result_value_value, 'text', x))
self.ddown.bind(on_select=lambda instance, x: self.result_value_value.cpy(x))
copy_key_button=MyButton(text='Copy', size_hint=(.3, 1))
copy_key_button.bind(on_press=lambda instance: self.on_press_copy(self.result_value_value) )
copy_key_button.bind(on_press=lambda instance: self.on_press_copy_result(self.result_value_value) )
self.result_value_layout = BoxLayout(orientation="horizontal", spacing=SPACING)
self.result_value_layout.add_widget(result_value_label)
self.result_value_layout.add_widget(copy_key_button)
self.result_value_layout.add_widget(self.result_value_value)
result_value_label.bind(on_press=self.on_press_copy_result)
result_value_label.bind(on_press=lambda instance: self.on_press_copy_result(self.result_value_value))
self.result_value_layout.disabled=True
@ -381,20 +389,20 @@ class Main(App):
device_keys = self.huamidevice.get_wearable_auth_keys()
self.result_value_layout.disabled=False
self.result_value_value.text="No keys yet"
key=""
key_button = None
for device_key in device_keys:
debug_print(f"{device_key} {device_keys[device_key]}")
key_button = MyDDKeyButton(text=f"{device_keys[device_key]}", size_hint_y=None, height=44)
key_button.bind(on_release=lambda btn: self.ddown.select(btn.text))
key=f"{device_keys[device_key]}"
key_button = MyDDKeyButton(device_key, device_keys[device_key], size_hint_y=None, height=44)
key_button.bind(on_release=lambda btn: self.ddown.select(btn))
self.ddown.add_widget(key_button)
if key=="":
if key_button is None or key_button.text == "":
self.instructions_label.text="No keys on the server"
else:
self.instructions_label.text="Got the keys, select one and use the Copy button"
self.result_value_value.text=f"{key}"
self.ddown.select(key_button) # last genereated key button, yes
#Clock.schedule_once(partial(self.doit), 1)
@ -408,7 +416,8 @@ class Main(App):
self.credentials_password_input.text=Clipboard.paste()
def on_press_copy_result(self, instance):
Clipboard.copy(self.result_value_value.text)
Clipboard.copy(self.result_value_value.ak)
self.instructions_label.text='value copied to clipboard'
def on_press_paste(self, instance):
instance.text=Clipboard.paste()