mirror of
https://codeberg.org/vanous/huafetcher.git
synced 2025-01-10 15:12:01 +01:00
make buttons enabled/disabled based on status
This commit is contained in:
parent
cefeaed754
commit
2d63e9a277
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,7 +4,8 @@
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
cep_alm_pak.zip
|
||||
cep_7days.zip
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
|
@ -28,7 +28,7 @@ source.include_exts = py,png,jpg,kv,atlas
|
||||
#source.exclude_patterns = license,images/*/*.jpg
|
||||
|
||||
# (str) Application versioning (method 1)
|
||||
version = 0.5
|
||||
version = 0.7
|
||||
|
||||
# (str) Application versioning (method 2)
|
||||
# version.regex = __version__ = ['"](.*)['"]
|
||||
|
151
main.py
151
main.py
@ -15,7 +15,7 @@ from kivy.core.clipboard import Clipboard
|
||||
from kivy.storage.jsonstore import JsonStore
|
||||
|
||||
DEBUG=False
|
||||
#DEBUG=True
|
||||
DEBUG=True
|
||||
|
||||
def debug_print(*xargs):
|
||||
if DEBUG:
|
||||
@ -91,8 +91,10 @@ class Main(App):
|
||||
buttons_layout = BoxLayout(orientation="horizontal", spacing=SPACING)
|
||||
rows_layout = BoxLayout(orientation="vertical", spacing=SPACING)
|
||||
|
||||
self.instructions_label=MyLeftLabel(text='Huafetcher', halign="left")
|
||||
rows_layout.add_widget(self.instructions_label)
|
||||
top_title_label=MyLeftLabel(text='Huafetcher', halign="left")
|
||||
self.instructions_label=MyLeftLabel(text='Press "Get token", sign in, copy URL and paste here', halign="left", valign="middle", padding_x="20")
|
||||
self.instructions_label.bind(size=self.instructions_label.setter('text_size'))
|
||||
rows_layout.add_widget(top_title_label)
|
||||
|
||||
dropdown = DropDown()
|
||||
|
||||
@ -114,37 +116,39 @@ class Main(App):
|
||||
get_token_button = MyButton(text='Get token')
|
||||
get_token_button.bind(on_press=self.on_press_button_gettoken)
|
||||
|
||||
fetch_key_button = MyButton(text='Fetch key')
|
||||
fetch_key_button.bind(on_press=self.on_press_button_fetch_key)
|
||||
self.fetch_key_button = MyButton(text='Fetch key')
|
||||
self.fetch_key_button.bind(on_press=self.on_press_button_fetch_key)
|
||||
self.fetch_key_button.disabled=True
|
||||
|
||||
fetch_agps_button = MyButton(text='Fetch aGPS')
|
||||
fetch_agps_button.bind(on_press=self.on_press_button_agps)
|
||||
self.fetch_agps_button = MyButton(text='Fetch aGPS')
|
||||
self.fetch_agps_button.bind(on_press=self.on_press_button_agps)
|
||||
self.fetch_agps_button.disabled=True
|
||||
|
||||
share_agps_button = MyButton(text='Share aGPS')
|
||||
share_agps_button.bind(on_press=self.on_press_button_share_agps)
|
||||
|
||||
buttons_layout.add_widget(get_token_button)
|
||||
#buttons_layout.add_widget(login_button)
|
||||
buttons_layout.add_widget(fetch_key_button)
|
||||
buttons_layout.add_widget(fetch_agps_button)
|
||||
buttons_layout.add_widget(self.fetch_key_button)
|
||||
buttons_layout.add_widget(self.fetch_agps_button)
|
||||
#sharing doesn't work
|
||||
#buttons_layout.add_widget(share_agps_button)
|
||||
|
||||
paste_token_input_layout = BoxLayout(orientation="horizontal", spacing=SPACING)
|
||||
self.paste_token_input_layout = BoxLayout(orientation="horizontal", spacing=SPACING)
|
||||
paste_token_input_label=MyLabel(text='URL result')
|
||||
|
||||
self.paste_token_input_layout.disabled=True
|
||||
self.paste_token_input = MyInput(text='',
|
||||
multiline=False,
|
||||
)
|
||||
self.paste_token_input.bind(text=self.set_token)
|
||||
|
||||
|
||||
paste_button1=MyButton(text='Paste', size_hint=(.3, 1))
|
||||
paste_button1.bind(on_press=lambda instance: self.on_press_paste(self.paste_token_input) )
|
||||
paste_token_url_button=MyButton(text='Paste', size_hint=(.3, 1))
|
||||
paste_token_url_button.bind(on_press=lambda instance: self.on_press_paste(self.paste_token_input) )
|
||||
|
||||
paste_token_input_layout.add_widget(paste_token_input_label)
|
||||
paste_token_input_layout.add_widget(paste_button1)
|
||||
paste_token_input_layout.add_widget(self.paste_token_input)
|
||||
self.paste_token_input_layout.add_widget(paste_token_input_label)
|
||||
self.paste_token_input_layout.add_widget(paste_token_url_button)
|
||||
self.paste_token_input_layout.add_widget(self.paste_token_input)
|
||||
credentials_email_label=MyButton(text='Email' , size_hint=(.7, 1))
|
||||
|
||||
self.credentials_email_input = MyInput(text='',
|
||||
@ -153,20 +157,20 @@ class Main(App):
|
||||
self.credentials_email_input.bind(text=lambda instance,x: setattr(self.huamidevice,'email',x))
|
||||
credentials_email_label.bind(on_press=self.on_press_paste_email)
|
||||
|
||||
paste_button2=MyButton(text='Paste', size_hint=(.3, 1))
|
||||
paste_button2.bind(on_press=lambda instance: self.on_press_paste(self.credentials_email_input) )
|
||||
email_paste_button=MyButton(text='Paste', size_hint=(.3, 1))
|
||||
email_paste_button.bind(on_press=lambda instance: self.on_press_paste(self.credentials_email_input) )
|
||||
|
||||
save_button1=MyButton(text='Save', size_hint=(.3, 1))
|
||||
email_save_button=MyButton(text='Save', size_hint=(.3, 1))
|
||||
#load_button1.bind(on_press=lambda instance: )
|
||||
save_button1.bind(on_press=lambda instance: self.on_press_save(self.credentials_email_input, 'email') )
|
||||
email_save_button.bind(on_press=lambda instance: self.on_press_save(self.credentials_email_input, 'email') )
|
||||
|
||||
|
||||
|
||||
self.credentials_email_layout = BoxLayout(orientation="horizontal", spacing=SPACING)
|
||||
self.credentials_email_layout.add_widget(credentials_email_label)
|
||||
#credentials_email_layout.add_widget(load_button1)
|
||||
self.credentials_email_layout.add_widget(save_button1)
|
||||
self.credentials_email_layout.add_widget(paste_button2)
|
||||
self.credentials_email_layout.add_widget(email_save_button)
|
||||
self.credentials_email_layout.add_widget(email_paste_button)
|
||||
self.credentials_email_layout.add_widget(self.credentials_email_input)
|
||||
|
||||
|
||||
@ -178,43 +182,45 @@ class Main(App):
|
||||
self.credentials_password_input.bind(text=lambda instance,x: setattr(self.huamidevice,'password',x))
|
||||
credentials_password_label.bind(on_press=self.on_press_paste_password)
|
||||
|
||||
paste_button3=MyButton(text='Paste', size_hint=(.3, 1))
|
||||
paste_button3.bind(on_press=lambda instance: self.on_press_paste(self.credentials_password_input) )
|
||||
password_paste_button=MyButton(text='Paste', size_hint=(.3, 1))
|
||||
password_paste_button.bind(on_press=lambda instance: self.on_press_paste(self.credentials_password_input) )
|
||||
|
||||
save_button2=MyButton(text='Save', size_hint=(.3, 1))
|
||||
save_button2.bind(on_press=lambda instance: self.on_press_save(self.credentials_password_input, 'password') )
|
||||
password_save_button=MyButton(text='Save', size_hint=(.3, 1))
|
||||
password_save_button.bind(on_press=lambda instance: self.on_press_save(self.credentials_password_input, 'password') )
|
||||
|
||||
self.credentials_password_layout = BoxLayout(orientation="horizontal", spacing=SPACING)
|
||||
self.credentials_password_layout.add_widget(credentials_password_label)
|
||||
self.credentials_password_layout.add_widget(save_button2)
|
||||
self.credentials_password_layout.add_widget(paste_button3)
|
||||
self.credentials_password_layout.add_widget(password_save_button)
|
||||
self.credentials_password_layout.add_widget(password_paste_button)
|
||||
self.credentials_password_layout.add_widget(self.credentials_password_input)
|
||||
|
||||
rows_layout.add_widget(dropdown_button)
|
||||
rows_layout.add_widget(self.credentials_email_layout)
|
||||
rows_layout.add_widget(self.credentials_password_layout)
|
||||
rows_layout.add_widget(paste_token_input_layout)
|
||||
rows_layout.add_widget(self.paste_token_input_layout)
|
||||
|
||||
result_value_label=MyButton(text='Found key')
|
||||
self.result_value_value=TextInput()
|
||||
|
||||
|
||||
copy_button4=MyButton(text='Copy', size_hint=(.3, 1))
|
||||
copy_button4.bind(on_press=lambda instance: self.on_press_copy(self.result_value_value) )
|
||||
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) )
|
||||
|
||||
|
||||
result_value_layout = BoxLayout(orientation="horizontal", spacing=SPACING)
|
||||
result_value_layout.add_widget(result_value_label)
|
||||
result_value_layout.add_widget(copy_button4)
|
||||
result_value_layout.add_widget(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)
|
||||
self.result_value_layout.disabled=True
|
||||
|
||||
|
||||
rows_layout.add_widget(result_value_layout)
|
||||
rows_layout.add_widget(self.result_value_layout)
|
||||
|
||||
|
||||
rows_layout.add_widget(buttons_layout)
|
||||
|
||||
rows_layout.add_widget(self.instructions_label)
|
||||
|
||||
screen_layout.add_widget(rows_layout)
|
||||
|
||||
@ -252,9 +258,24 @@ class Main(App):
|
||||
debug_print(self.huamidevice)
|
||||
self.huamidevice.parse_token(text)
|
||||
debug_print(self.huamidevice)
|
||||
if self.huamidevice.access_token is not None:
|
||||
self.fetch_agps_button.disabled=False
|
||||
self.fetch_key_button.disabled=False
|
||||
self.instructions_label.text='now press "Fetch key" or "Fetch aGPS"'
|
||||
else:
|
||||
if self.paste_token_input_layout.disabled==False:
|
||||
self.instructions_label.text='token not found in the url, repeat sign in a copy/paste url'
|
||||
|
||||
|
||||
|
||||
def on_press_button_gettoken(self, instance):
|
||||
debug_print('You pressed the button login!')
|
||||
self.result_value_value.text=''
|
||||
self.paste_token_input.text=''
|
||||
self.fetch_agps_button.disabled=True
|
||||
self.fetch_key_button.disabled=True
|
||||
self.result_value_layout.disabled=True
|
||||
self.instructions_label.text="log in and paste url here"
|
||||
debug_print(self.huamidevice)
|
||||
if self.huamidevice.method == 'xiaomi':
|
||||
self.instructions_label.text="log in and paste url here"
|
||||
@ -274,24 +295,35 @@ class Main(App):
|
||||
intent.setData(Uri.parse(login_url))
|
||||
currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
|
||||
currentActivity.startActivity(intent)
|
||||
self.paste_token_input_layout.disabled=False
|
||||
return
|
||||
else:
|
||||
#login methiod amazfit
|
||||
try:
|
||||
res=self.huamidevice.get_access_token()
|
||||
if res:
|
||||
if self.huamidevice.user_id is not None:
|
||||
self.instructions_label.text="Signed in as: {}, getting data".format(self.huamidevice.user_id)
|
||||
else:
|
||||
self.instructions_label.text="You must sign in first"
|
||||
|
||||
try:
|
||||
res=self.huamidevice.get_access_token()
|
||||
if res:
|
||||
if self.huamidevice.user_id is not None:
|
||||
self.instructions_label.text="Signed in as: {}, getting data".format(self.huamidevice.user_id)
|
||||
else:
|
||||
self.instructions_label.text="You must sign in first"
|
||||
|
||||
except Exception as e:
|
||||
debug_print(e)
|
||||
self.instructions_label.text=f"{e}"
|
||||
|
||||
except Exception as e:
|
||||
debug_print(e)
|
||||
self.instructions_label.text=f"{e}"
|
||||
|
||||
def on_press_button_fetch_key(self, instance):
|
||||
debug_print('You pressed the button fetch!')
|
||||
self.result_value_value.text=''
|
||||
self.paste_token_input.text=''
|
||||
self.result_value_layout.disabled=True
|
||||
self.paste_token_input_layout.disabled=True
|
||||
self.fetch_key_button.disabled=True
|
||||
self.fetch_agps_button.disabled=True
|
||||
debug_print(self.huamidevice)
|
||||
self.instructions_label.text="signing in"
|
||||
self.instructions_label.text="signing in and getting keys"
|
||||
Clock.schedule_once(self.fetch_keys, 1)
|
||||
|
||||
def fetch_keys(self, *xargs):
|
||||
try:
|
||||
res=self.huamidevice.login()
|
||||
if res:
|
||||
@ -303,7 +335,8 @@ class Main(App):
|
||||
|
||||
|
||||
device_keys = self.huamidevice.get_wearable_auth_keys()
|
||||
self.instructions_label.text="Done"
|
||||
self.result_value_layout.disabled=False
|
||||
self.instructions_label.text="Got the key, use the Copy button"
|
||||
self.result_value_value.text=""
|
||||
for device_key in device_keys:
|
||||
debug_print(f"{device_key} {device_keys[device_key]}")
|
||||
@ -323,12 +356,13 @@ class Main(App):
|
||||
|
||||
def on_press_copy_result(self, instance):
|
||||
Clipboard.copy(self.result_value_value.text)
|
||||
|
||||
|
||||
def on_press_paste(self, instance):
|
||||
instance.text=Clipboard.paste()
|
||||
|
||||
def on_press_copy(self, instance):
|
||||
Clipboard.copy(instance.text)
|
||||
self.instructions_label.text='value copied to clipboard'
|
||||
|
||||
def on_press_load(self, instance, key):
|
||||
if self.store.exists(key):
|
||||
@ -338,10 +372,19 @@ class Main(App):
|
||||
self.store.put(key, value=instance.text)
|
||||
|
||||
def on_press_button_agps(self, instance):
|
||||
import zipfile
|
||||
debug_print('You pressed the button agps!')
|
||||
self.result_value_value.text=''
|
||||
self.paste_token_input.text=''
|
||||
self.result_value_layout.disabled=True
|
||||
self.paste_token_input_layout.disabled=True
|
||||
self.fetch_key_button.disabled=True
|
||||
self.fetch_agps_button.disabled=True
|
||||
debug_print(self.huamidevice)
|
||||
self.instructions_label.text="signing in"
|
||||
self.instructions_label.text="signing in and getting files"
|
||||
Clock.schedule_once (self.get_agps_files, 1)
|
||||
|
||||
def get_agps_files(self, *xargs):
|
||||
import zipfile
|
||||
try:
|
||||
res=self.huamidevice.login()
|
||||
if res:
|
||||
@ -369,7 +412,7 @@ class Main(App):
|
||||
#zip_f.extractall()
|
||||
zip_f.extractall(data_dir)
|
||||
|
||||
self.instructions_label.text="Done"
|
||||
self.instructions_label.text="Files downloaded and extracted"
|
||||
#Clock.schedule_once(partial(self.doit), 1)
|
||||
|
||||
def on_press_button_share_agps(self, instance):
|
||||
|
Loading…
Reference in New Issue
Block a user