mirror of
https://codeberg.org/vanous/huafetcher.git
synced 2025-01-25 14:05:49 +01:00
Added mac-address labels to dropdown buttons
Signed-off-by: Ivan Lebedev <lisgml@gmail.com>
This commit is contained in:
parent
69d195a9d1
commit
395b976cf9
39
main.py
39
main.py
@ -14,8 +14,8 @@ import urls as urls
|
|||||||
from kivy.core.clipboard import Clipboard
|
from kivy.core.clipboard import Clipboard
|
||||||
from kivy.storage.jsonstore import JsonStore
|
from kivy.storage.jsonstore import JsonStore
|
||||||
|
|
||||||
DEBUG=False
|
# DEBUG=False
|
||||||
#DEBUG=True
|
DEBUG=True
|
||||||
|
|
||||||
def debug_print(*xargs):
|
def debug_print(*xargs):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
@ -93,8 +93,16 @@ class MyInput(TextInput):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class MyDDKeyButton(Button):
|
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):
|
class Main(App):
|
||||||
def build(self):
|
def build(self):
|
||||||
@ -213,21 +221,21 @@ class Main(App):
|
|||||||
rows_layout.add_widget(self.paste_token_input_layout)
|
rows_layout.add_widget(self.paste_token_input_layout)
|
||||||
|
|
||||||
result_value_label=MyButton(text='Found key')
|
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.ddown=DropDown()
|
||||||
self.result_value_value.bind(on_release=self.ddown.open)
|
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=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 = BoxLayout(orientation="horizontal", spacing=SPACING)
|
||||||
self.result_value_layout.add_widget(result_value_label)
|
self.result_value_layout.add_widget(result_value_label)
|
||||||
self.result_value_layout.add_widget(copy_key_button)
|
self.result_value_layout.add_widget(copy_key_button)
|
||||||
self.result_value_layout.add_widget(self.result_value_value)
|
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
|
self.result_value_layout.disabled=True
|
||||||
|
|
||||||
|
|
||||||
@ -381,20 +389,20 @@ class Main(App):
|
|||||||
device_keys = self.huamidevice.get_wearable_auth_keys()
|
device_keys = self.huamidevice.get_wearable_auth_keys()
|
||||||
self.result_value_layout.disabled=False
|
self.result_value_layout.disabled=False
|
||||||
self.result_value_value.text="No keys yet"
|
self.result_value_value.text="No keys yet"
|
||||||
key=""
|
key_button = None
|
||||||
for device_key in device_keys:
|
for device_key in device_keys:
|
||||||
debug_print(f"{device_key} {device_keys[device_key]}")
|
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 = MyDDKeyButton(device_key, device_keys[device_key], size_hint_y=None, height=44)
|
||||||
key_button.bind(on_release=lambda btn: self.ddown.select(btn.text))
|
key_button.bind(on_release=lambda btn: self.ddown.select(btn))
|
||||||
key=f"{device_keys[device_key]}"
|
|
||||||
self.ddown.add_widget(key_button)
|
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"
|
self.instructions_label.text="No keys on the server"
|
||||||
else:
|
else:
|
||||||
self.instructions_label.text="Got the keys, select one and use the Copy button"
|
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)
|
#Clock.schedule_once(partial(self.doit), 1)
|
||||||
|
|
||||||
@ -408,7 +416,8 @@ class Main(App):
|
|||||||
self.credentials_password_input.text=Clipboard.paste()
|
self.credentials_password_input.text=Clipboard.paste()
|
||||||
|
|
||||||
def on_press_copy_result(self, instance):
|
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):
|
def on_press_paste(self, instance):
|
||||||
instance.text=Clipboard.paste()
|
instance.text=Clipboard.paste()
|
||||||
|
Loading…
Reference in New Issue
Block a user