disabled the buttons that can break each other when another coroutine is running

This commit is contained in:
UpstreamData
2022-02-18 10:59:10 -07:00
parent 36ff5e96a4
commit 908594970e
5 changed files with 89 additions and 11 deletions

View File

@@ -9,6 +9,7 @@ from tools.cfg_util.cfg_util_sg.func.ui import update_ui_with_data, update_prog_
from tools.cfg_util.cfg_util_sg.layout import window
from tools.cfg_util.cfg_util_sg.miner_factory import miner_factory
from config.bos import bos_config_convert
from tools.cfg_util.cfg_util_sg.func.ui import enable_buttons, disable_buttons
from settings import CFG_UTIL_CONFIG_THREADS as CONFIG_THREADS, CFG_UTIL_REBOOT_THREADS as REBOOT_THREADS
@@ -22,6 +23,7 @@ async def import_config(idx):
async def scan_network(network):
disable_buttons()
await update_ui_with_data("status", "Scanning")
await update_ui_with_data("ip_count", "")
await update_ui_with_data("hr_total", "")
@@ -53,10 +55,13 @@ async def scan_network(network):
asyncio.create_task(update_prog_bar(progress_bar_len))
await update_ui_with_data("ip_count", str(len(all_miners)))
await update_ui_with_data("status", "")
enable_buttons()
async def miner_light(ips: list):
disable_buttons()
await asyncio.gather(*[flip_light(ip) for ip in ips])
enable_buttons
async def flip_light(ip):
@@ -91,6 +96,7 @@ async def reboot_generator(miners: list):
async def reboot_miners(ips: list):
disable_buttons()
await update_ui_with_data("status", "Rebooting")
await set_progress_bar_len(2 * len(ips))
progress_bar_len = 0
@@ -106,6 +112,7 @@ async def reboot_miners(ips: list):
progress_bar_len += 1
asyncio.create_task(update_prog_bar(progress_bar_len))
await update_ui_with_data("status", "")
enable_buttons()
async def restart_backend_generator(miners: list):
@@ -124,6 +131,7 @@ async def restart_backend_generator(miners: list):
async def restart_miners_backend(ips: list):
disable_buttons()
await update_ui_with_data("status", "Restarting Backends")
await set_progress_bar_len(2 * len(ips))
progress_bar_len = 0
@@ -139,6 +147,7 @@ async def restart_miners_backend(ips: list):
progress_bar_len += 1
asyncio.create_task(update_prog_bar(progress_bar_len))
await update_ui_with_data("status", "")
enable_buttons()
async def send_config_generator(miners: list, config):
@@ -157,6 +166,7 @@ async def send_config_generator(miners: list, config):
async def send_config(ips: list, config):
disable_buttons()
await update_ui_with_data("status", "Configuring")
await set_progress_bar_len(2 * len(ips))
progress_bar_len = 0
@@ -175,9 +185,11 @@ async def send_config(ips: list, config):
await update_ui_with_data("status", "Getting Data")
await asyncio.sleep(3)
await refresh_data(ips)
enable_buttons()
async def refresh_data(ip_list: list):
disable_buttons()
await update_ui_with_data("status", "Getting Data")
await update_ui_with_data("hr_total", "")
ips = [ipaddress.ip_address(ip) for ip in ip_list]
@@ -225,9 +237,11 @@ async def refresh_data(ip_list: list):
window["hr_total"].update(f"{total_hr} TH/s")
await update_ui_with_data("status", "")
enable_buttons()
async def scan_and_get_data(network):
disable_buttons()
await update_ui_with_data("status", "Scanning")
await update_ui_with_data("hr_total", "")
await update_ui_with_data("ip_count", "")
@@ -279,6 +293,7 @@ async def scan_and_get_data(network):
total_hr = round(sum(hashrate_list), 2)
await update_ui_with_data("hr_total", f"{total_hr} TH/s")
await update_ui_with_data("status", "")
enable_buttons()
async def get_formatted_data(ip: ipaddress.ip_address):

View File

@@ -6,6 +6,48 @@ from tools.cfg_util.cfg_util_sg.layout import window
import pyperclip
def disable_buttons():
button_list = ["scan",
"import_file_config",
"export_file_config",
"import_iplist",
"export_iplist",
"export_csv",
"select_all_ips",
"refresh_data",
"open_in_web",
"reboot_miners",
"restart_miner_backend",
"import_config",
"send_config",
"light",
"generate_config",
]
for button in button_list:
window[button].Update(disabled=True)
def enable_buttons():
button_list = ["scan",
"import_file_config",
"export_file_config",
"import_iplist",
"export_iplist",
"export_csv",
"select_all_ips",
"refresh_data",
"open_in_web",
"reboot_miners",
"restart_miner_backend",
"import_config",
"send_config",
"light",
"generate_config",
]
for button in button_list:
window[button].Update(disabled=False)
def copy_from_table(table):
selection = table.selection()
copy_values = []
@@ -40,6 +82,9 @@ async def set_progress_bar_len(amount):
async def sort_data(index: int or str):
if window["scan"].disabled:
print("disabled")
return
await update_ui_with_data("status", "Sorting Data")
data_list = window['ip_table'].Values

View File

@@ -47,7 +47,13 @@ layout = [
[sg.Table(
values=[],
headings=["IP", "Model", "Hostname", "Hashrate", "Temperature", "Current User", "Wattage"],
headings=["IP",
"Model",
"Hostname",
"Hashrate",
"Temperature",
"Current User",
"Wattage"],
auto_size_columns=False,
max_col_width=15,
justification="center",

View File

@@ -46,11 +46,14 @@ async def ui():
if 2 > len(value['ip_table']) > 0:
asyncio.create_task(import_config(value['ip_table']))
if event == "restart_miner_backend":
asyncio.create_task(restart_miners_backend([window['ip_table'].Values[item][0] for item in value['ip_table']]))
if len(window["ip_table"].Values) > 0:
asyncio.create_task(restart_miners_backend([window['ip_table'].Values[item][0] for item in value['ip_table']]))
if event == "reboot_miners":
asyncio.create_task(reboot_miners([window['ip_table'].Values[item][0] for item in value['ip_table']]))
if len(window["ip_table"].Values) > 0:
asyncio.create_task(reboot_miners([window['ip_table'].Values[item][0] for item in value['ip_table']]))
if event == 'light':
asyncio.create_task(miner_light([window['ip_table'].Values[item][0] for item in value['ip_table']]))
if len(window["ip_table"].Values) > 0:
asyncio.create_task(miner_light([window['ip_table'].Values[item][0] for item in value['ip_table']]))
if event == "import_iplist":
asyncio.create_task(import_iplist(value["file_iplist"]))
if event == "export_iplist":
@@ -58,13 +61,15 @@ async def ui():
if event == "export_csv":
asyncio.create_task(export_csv(value["file_iplist"], [window['ip_table'].Values[item] for item in value['ip_table']]))
if event == "send_config":
asyncio.create_task(send_config([window['ip_table'].Values[item][0] for item in value['ip_table']], value['config']))
if len(window["ip_table"].Values) > 0:
asyncio.create_task(send_config([window['ip_table'].Values[item][0] for item in value['ip_table']], value['config']))
if event == "import_file_config":
asyncio.create_task(import_config_file(value['file_config']))
if event == "export_file_config":
asyncio.create_task(export_config_file(value['file_config'], value["config"]))
if event == "refresh_data":
asyncio.create_task(refresh_data([window["ip_table"].Values[item][0] for item in value["ip_table"]]))
if len(window["ip_table"].Values) > 0:
asyncio.create_task(refresh_data([window["ip_table"].Values[item][0] for item in value["ip_table"]]))
if event == "generate_config":
await generate_config_ui()
if event == "__TIMEOUT__":