added disable button decorator to board util
This commit is contained in:
26
tools/bad_board_util/func/decorators.py
Normal file
26
tools/bad_board_util/func/decorators.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from tools.bad_board_util.layout import window
|
||||
|
||||
|
||||
def disable_buttons(func):
|
||||
button_list = ["scan",
|
||||
"import_iplist",
|
||||
"export_iplist",
|
||||
"select_all_ips",
|
||||
"refresh_data",
|
||||
"open_in_web"
|
||||
]
|
||||
|
||||
# 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
|
||||
@@ -5,8 +5,10 @@ import warnings
|
||||
from tools.bad_board_util.func.ui import update_ui_with_data, update_prog_bar, set_progress_bar_len
|
||||
from tools.bad_board_util.layout import window
|
||||
from miners.miner_factory import MinerFactory
|
||||
from tools.bad_board_util.func.decorators import disable_buttons
|
||||
|
||||
|
||||
@disable_buttons
|
||||
async def scan_network(network):
|
||||
await update_ui_with_data("status", "Scanning")
|
||||
await update_ui_with_data("ip_count", "")
|
||||
@@ -36,6 +38,7 @@ async def scan_network(network):
|
||||
await update_ui_with_data("status", "")
|
||||
|
||||
|
||||
@disable_buttons
|
||||
async def refresh_data(ip_list: list):
|
||||
await update_ui_with_data("status", "Getting Data")
|
||||
ips = [ipaddress.ip_address(ip) for ip in ip_list]
|
||||
@@ -98,6 +101,7 @@ async def refresh_data(ip_list: list):
|
||||
await update_ui_with_data("status", "")
|
||||
|
||||
|
||||
@disable_buttons
|
||||
async def scan_and_get_data(network):
|
||||
await update_ui_with_data("status", "Scanning")
|
||||
await update_ui_with_data("ip_count", "")
|
||||
|
||||
@@ -49,6 +49,8 @@ async def set_progress_bar_len(amount):
|
||||
|
||||
|
||||
async def sort_data(index: int or str):
|
||||
if window["scan"].Disabled:
|
||||
return
|
||||
await update_ui_with_data("status", "Sorting Data")
|
||||
data_list = window['ip_table'].Values
|
||||
table = window["ip_table"].Widget
|
||||
|
||||
@@ -25,7 +25,7 @@ async def ui():
|
||||
# left justify the hostnames
|
||||
table.column(2, anchor=tk.W)
|
||||
while True:
|
||||
event, value = window.read(timeout=10)
|
||||
event, value = window.read(timeout=0)
|
||||
if event in (None, 'Close', sg.WIN_CLOSED):
|
||||
sys.exit()
|
||||
if isinstance(event, tuple):
|
||||
|
||||
Reference in New Issue
Block a user