changed the disabling buttons to use a decorator as it looks much cleaner
This commit is contained in:
35
tools/cfg_util/cfg_util_sg/func/decorators.py
Normal file
35
tools/cfg_util/cfg_util_sg/func/decorators.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
from tools.cfg_util.cfg_util_sg.layout import window
|
||||||
|
|
||||||
|
|
||||||
|
def disable_buttons(func):
|
||||||
|
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",
|
||||||
|
]
|
||||||
|
|
||||||
|
# handle the inner function that the decorator is wrapping
|
||||||
|
async def inner(*args, **kwargs):
|
||||||
|
# disable the buttons
|
||||||
|
for button in button_list:
|
||||||
|
window[button].Update(disabled=True)
|
||||||
|
|
||||||
|
# call the original wrapped function
|
||||||
|
await func(*args, **kwargs)
|
||||||
|
|
||||||
|
# re-enable the buttons after the wrapped function completes
|
||||||
|
for button in button_list:
|
||||||
|
window[button].Update(disabled=False)
|
||||||
|
|
||||||
|
return inner
|
||||||
@@ -9,7 +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.layout import window
|
||||||
from tools.cfg_util.cfg_util_sg.miner_factory import miner_factory
|
from tools.cfg_util.cfg_util_sg.miner_factory import miner_factory
|
||||||
from config.bos import bos_config_convert
|
from config.bos import bos_config_convert
|
||||||
from tools.cfg_util.cfg_util_sg.func.ui import enable_buttons, disable_buttons
|
from tools.cfg_util.cfg_util_sg.func.decorators import disable_buttons
|
||||||
from settings import CFG_UTIL_CONFIG_THREADS as CONFIG_THREADS, CFG_UTIL_REBOOT_THREADS as REBOOT_THREADS
|
from settings import CFG_UTIL_CONFIG_THREADS as CONFIG_THREADS, CFG_UTIL_REBOOT_THREADS as REBOOT_THREADS
|
||||||
|
|
||||||
|
|
||||||
@@ -22,8 +22,8 @@ async def import_config(idx):
|
|||||||
await update_ui_with_data("status", "")
|
await update_ui_with_data("status", "")
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
async def scan_network(network):
|
async def scan_network(network):
|
||||||
disable_buttons()
|
|
||||||
await update_ui_with_data("status", "Scanning")
|
await update_ui_with_data("status", "Scanning")
|
||||||
await update_ui_with_data("ip_count", "")
|
await update_ui_with_data("ip_count", "")
|
||||||
await update_ui_with_data("hr_total", "")
|
await update_ui_with_data("hr_total", "")
|
||||||
@@ -55,13 +55,11 @@ async def scan_network(network):
|
|||||||
asyncio.create_task(update_prog_bar(progress_bar_len))
|
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("ip_count", str(len(all_miners)))
|
||||||
await update_ui_with_data("status", "")
|
await update_ui_with_data("status", "")
|
||||||
enable_buttons()
|
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
async def miner_light(ips: list):
|
async def miner_light(ips: list):
|
||||||
disable_buttons()
|
|
||||||
await asyncio.gather(*[flip_light(ip) for ip in ips])
|
await asyncio.gather(*[flip_light(ip) for ip in ips])
|
||||||
enable_buttons
|
|
||||||
|
|
||||||
|
|
||||||
async def flip_light(ip):
|
async def flip_light(ip):
|
||||||
@@ -95,8 +93,8 @@ async def reboot_generator(miners: list):
|
|||||||
yield await done
|
yield await done
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
async def reboot_miners(ips: list):
|
async def reboot_miners(ips: list):
|
||||||
disable_buttons()
|
|
||||||
await update_ui_with_data("status", "Rebooting")
|
await update_ui_with_data("status", "Rebooting")
|
||||||
await set_progress_bar_len(2 * len(ips))
|
await set_progress_bar_len(2 * len(ips))
|
||||||
progress_bar_len = 0
|
progress_bar_len = 0
|
||||||
@@ -112,7 +110,6 @@ async def reboot_miners(ips: list):
|
|||||||
progress_bar_len += 1
|
progress_bar_len += 1
|
||||||
asyncio.create_task(update_prog_bar(progress_bar_len))
|
asyncio.create_task(update_prog_bar(progress_bar_len))
|
||||||
await update_ui_with_data("status", "")
|
await update_ui_with_data("status", "")
|
||||||
enable_buttons()
|
|
||||||
|
|
||||||
|
|
||||||
async def restart_backend_generator(miners: list):
|
async def restart_backend_generator(miners: list):
|
||||||
@@ -130,8 +127,8 @@ async def restart_backend_generator(miners: list):
|
|||||||
yield await done
|
yield await done
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
async def restart_miners_backend(ips: list):
|
async def restart_miners_backend(ips: list):
|
||||||
disable_buttons()
|
|
||||||
await update_ui_with_data("status", "Restarting Backends")
|
await update_ui_with_data("status", "Restarting Backends")
|
||||||
await set_progress_bar_len(2 * len(ips))
|
await set_progress_bar_len(2 * len(ips))
|
||||||
progress_bar_len = 0
|
progress_bar_len = 0
|
||||||
@@ -147,7 +144,6 @@ async def restart_miners_backend(ips: list):
|
|||||||
progress_bar_len += 1
|
progress_bar_len += 1
|
||||||
asyncio.create_task(update_prog_bar(progress_bar_len))
|
asyncio.create_task(update_prog_bar(progress_bar_len))
|
||||||
await update_ui_with_data("status", "")
|
await update_ui_with_data("status", "")
|
||||||
enable_buttons()
|
|
||||||
|
|
||||||
|
|
||||||
async def send_config_generator(miners: list, config):
|
async def send_config_generator(miners: list, config):
|
||||||
@@ -165,8 +161,8 @@ async def send_config_generator(miners: list, config):
|
|||||||
yield await sent_config
|
yield await sent_config
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
async def send_config(ips: list, config):
|
async def send_config(ips: list, config):
|
||||||
disable_buttons()
|
|
||||||
await update_ui_with_data("status", "Configuring")
|
await update_ui_with_data("status", "Configuring")
|
||||||
await set_progress_bar_len(2 * len(ips))
|
await set_progress_bar_len(2 * len(ips))
|
||||||
progress_bar_len = 0
|
progress_bar_len = 0
|
||||||
@@ -185,11 +181,10 @@ async def send_config(ips: list, config):
|
|||||||
await update_ui_with_data("status", "Getting Data")
|
await update_ui_with_data("status", "Getting Data")
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
await refresh_data(ips)
|
await refresh_data(ips)
|
||||||
enable_buttons()
|
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
async def refresh_data(ip_list: list):
|
async def refresh_data(ip_list: list):
|
||||||
disable_buttons()
|
|
||||||
await update_ui_with_data("status", "Getting Data")
|
await update_ui_with_data("status", "Getting Data")
|
||||||
await update_ui_with_data("hr_total", "")
|
await update_ui_with_data("hr_total", "")
|
||||||
ips = [ipaddress.ip_address(ip) for ip in ip_list]
|
ips = [ipaddress.ip_address(ip) for ip in ip_list]
|
||||||
@@ -237,11 +232,10 @@ async def refresh_data(ip_list: list):
|
|||||||
window["hr_total"].update(f"{total_hr} TH/s")
|
window["hr_total"].update(f"{total_hr} TH/s")
|
||||||
|
|
||||||
await update_ui_with_data("status", "")
|
await update_ui_with_data("status", "")
|
||||||
enable_buttons()
|
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
async def scan_and_get_data(network):
|
async def scan_and_get_data(network):
|
||||||
disable_buttons()
|
|
||||||
await update_ui_with_data("status", "Scanning")
|
await update_ui_with_data("status", "Scanning")
|
||||||
await update_ui_with_data("hr_total", "")
|
await update_ui_with_data("hr_total", "")
|
||||||
await update_ui_with_data("ip_count", "")
|
await update_ui_with_data("ip_count", "")
|
||||||
@@ -293,7 +287,6 @@ async def scan_and_get_data(network):
|
|||||||
total_hr = round(sum(hashrate_list), 2)
|
total_hr = round(sum(hashrate_list), 2)
|
||||||
await update_ui_with_data("hr_total", f"{total_hr} TH/s")
|
await update_ui_with_data("hr_total", f"{total_hr} TH/s")
|
||||||
await update_ui_with_data("status", "")
|
await update_ui_with_data("status", "")
|
||||||
enable_buttons()
|
|
||||||
|
|
||||||
|
|
||||||
async def get_formatted_data(ip: ipaddress.ip_address):
|
async def get_formatted_data(ip: ipaddress.ip_address):
|
||||||
|
|||||||
@@ -6,48 +6,6 @@ from tools.cfg_util.cfg_util_sg.layout import window
|
|||||||
import pyperclip
|
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):
|
def copy_from_table(table):
|
||||||
selection = table.selection()
|
selection = table.selection()
|
||||||
copy_values = []
|
copy_values = []
|
||||||
|
|||||||
Reference in New Issue
Block a user