added listener function to cfg util
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
from miners.miner_factory import MinerFactory
|
||||
from tools.cfg_util.layout import window, update_prog_bar
|
||||
from miners.miner_listener import MinerListener
|
||||
from tools.cfg_util.layout import window, update_prog_bar, WINDOW_ICON
|
||||
from tools.cfg_util.tables import TableManager
|
||||
from tools.cfg_util.decorators import disable_buttons
|
||||
from settings import CFG_UTIL_CONFIG_THREADS as COMMAND_THREADS
|
||||
from typing import Tuple
|
||||
|
||||
import PySimpleGUI as sg
|
||||
|
||||
import asyncio
|
||||
|
||||
|
||||
@@ -118,3 +121,33 @@ async def send_command_generator(miners: list, command: str):
|
||||
async def _send_ssh_command(miner, command: str):
|
||||
proc = await miner.send_ssh_command(command)
|
||||
return {"IP": miner.ip, "Status": proc}
|
||||
|
||||
|
||||
CANCEL_LISTEN_BTNS = [
|
||||
"cmd_cancel_listen",
|
||||
"pools_cancel_listen",
|
||||
"boards_cancel_listen",
|
||||
"scan_cancel_listen",
|
||||
"cfg_cancel_listen",
|
||||
]
|
||||
|
||||
|
||||
@disable_buttons("Listening for Miner")
|
||||
async def btn_listen():
|
||||
window["cmd_listen"].update(visible=False)
|
||||
for btn in CANCEL_LISTEN_BTNS:
|
||||
window[btn].update(visible=True)
|
||||
async for miner in MinerListener().listen():
|
||||
sg.popup(
|
||||
f"IP: {miner['IP']}, MAC: {miner['MAC']}",
|
||||
title="Found Miner",
|
||||
keep_on_top=True,
|
||||
icon=WINDOW_ICON,
|
||||
)
|
||||
|
||||
|
||||
async def btn_cancel_listen():
|
||||
await MinerListener().cancel()
|
||||
window["cmd_listen"].update(visible=True)
|
||||
for btn in CANCEL_LISTEN_BTNS:
|
||||
window[btn].update(visible=False)
|
||||
|
||||
@@ -150,6 +150,10 @@ BUTTON_KEYS = [
|
||||
"scan_all",
|
||||
"scan_refresh",
|
||||
"scan_web",
|
||||
"boards_report",
|
||||
"boards_all",
|
||||
"boards_refresh",
|
||||
"boards_web",
|
||||
"cmd_all",
|
||||
"cmd_light",
|
||||
"cmd_reboot",
|
||||
@@ -162,6 +166,7 @@ BUTTON_KEYS = [
|
||||
"cfg_generate",
|
||||
"cfg_all",
|
||||
"cfg_web",
|
||||
"cmd_listen",
|
||||
]
|
||||
|
||||
TABLE_HEIGHT = 27
|
||||
@@ -217,7 +222,6 @@ def get_scan_layout():
|
||||
"Scan",
|
||||
key="btn_scan",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
mouseover_colors=BTN_DISABLED,
|
||||
bind_return_key=True,
|
||||
),
|
||||
@@ -227,20 +231,23 @@ def get_scan_layout():
|
||||
"ALL",
|
||||
key="scan_all",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
pad=((0, 5), (1, 1)),
|
||||
),
|
||||
sg.Button(
|
||||
"REFRESH DATA",
|
||||
key="scan_refresh",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
),
|
||||
sg.Button(
|
||||
"OPEN IN WEB",
|
||||
key="scan_web",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
),
|
||||
sg.Button(
|
||||
"STOP LISTENING",
|
||||
key="scan_cancel_listen",
|
||||
border_width=BTN_BORDER,
|
||||
visible=False,
|
||||
),
|
||||
],
|
||||
[
|
||||
@@ -302,20 +309,23 @@ def get_boards_layout():
|
||||
"ALL",
|
||||
key="boards_all",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
pad=((0, 5), (1, 1)),
|
||||
),
|
||||
sg.Button(
|
||||
"REFRESH DATA",
|
||||
key="boards_refresh",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
),
|
||||
sg.Button(
|
||||
"OPEN IN WEB",
|
||||
key="boards_web",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
),
|
||||
sg.Button(
|
||||
"STOP LISTENING",
|
||||
key="boards_cancel_listen",
|
||||
border_width=BTN_BORDER,
|
||||
visible=False,
|
||||
),
|
||||
],
|
||||
[
|
||||
@@ -370,7 +380,6 @@ def get_command_layout():
|
||||
"Send Command",
|
||||
key="btn_cmd",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
),
|
||||
],
|
||||
[
|
||||
@@ -378,26 +387,33 @@ def get_command_layout():
|
||||
"ALL",
|
||||
key="cmd_all",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
pad=((0, 5), (1, 1)),
|
||||
),
|
||||
sg.Button(
|
||||
"LIGHT",
|
||||
key="cmd_light",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
),
|
||||
sg.Button(
|
||||
"REBOOT",
|
||||
key="cmd_reboot",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
),
|
||||
sg.Button(
|
||||
"RESTART BACKEND",
|
||||
key="cmd_backend",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
),
|
||||
sg.Button(
|
||||
"LISTEN",
|
||||
key="cmd_listen",
|
||||
border_width=BTN_BORDER,
|
||||
),
|
||||
sg.Button(
|
||||
"STOP LISTENING",
|
||||
key="cmd_cancel_listen",
|
||||
border_width=BTN_BORDER,
|
||||
visible=False,
|
||||
),
|
||||
],
|
||||
[
|
||||
@@ -447,20 +463,23 @@ def get_pools_layout():
|
||||
"ALL",
|
||||
key="pools_all",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
pad=((0, 5), (6, 7)),
|
||||
),
|
||||
sg.Button(
|
||||
"REFRESH DATA",
|
||||
key="pools_refresh",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
),
|
||||
sg.Button(
|
||||
"OPEN IN WEB",
|
||||
key="pools_web",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
),
|
||||
sg.Button(
|
||||
"STOP LISTENING",
|
||||
key="pools_cancel_listen",
|
||||
border_width=BTN_BORDER,
|
||||
visible=False,
|
||||
),
|
||||
],
|
||||
[
|
||||
@@ -614,37 +633,39 @@ def get_config_layout():
|
||||
"IMPORT",
|
||||
key="cfg_import",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
pad=((0, 5), (6, 0)),
|
||||
),
|
||||
sg.Button(
|
||||
"CONFIG",
|
||||
key="cfg_config",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
pad=((0, 5), (6, 0)),
|
||||
),
|
||||
sg.Button(
|
||||
"GENERATE",
|
||||
key="cfg_generate",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
pad=((0, 5), (6, 0)),
|
||||
),
|
||||
sg.Button(
|
||||
"STOP LISTENING",
|
||||
key="cfg_cancel_listen",
|
||||
border_width=BTN_BORDER,
|
||||
pad=((0, 5), (6, 0)),
|
||||
visible=False,
|
||||
),
|
||||
],
|
||||
[
|
||||
sg.Button(
|
||||
"ALL",
|
||||
key="cfg_all",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
pad=((0, 5), (1, 0)),
|
||||
),
|
||||
sg.Button(
|
||||
"OPEN IN WEB",
|
||||
key="cfg_web",
|
||||
border_width=BTN_BORDER,
|
||||
disabled_button_color=BTN_DISABLED,
|
||||
pad=((5, 5), (3, 2)),
|
||||
),
|
||||
sg.Push(background_color=MAIN_TABS_BG),
|
||||
|
||||
@@ -9,6 +9,8 @@ from tools.cfg_util.commands import (
|
||||
btn_reboot,
|
||||
btn_backend,
|
||||
btn_command,
|
||||
btn_cancel_listen,
|
||||
btn_listen,
|
||||
)
|
||||
from tools.cfg_util.configure import (
|
||||
generate_config_ui,
|
||||
@@ -193,6 +195,10 @@ async def ui():
|
||||
_table = "cmd_table"
|
||||
_ips = value[_table]
|
||||
asyncio.create_task(btn_command(_ips, value["cmd_txt"]))
|
||||
if event == "cmd_listen":
|
||||
asyncio.create_task(btn_listen())
|
||||
if event.endswith("cancel_listen"):
|
||||
asyncio.create_task(btn_cancel_listen())
|
||||
|
||||
if event == "__TIMEOUT__":
|
||||
await asyncio.sleep(0)
|
||||
|
||||
Reference in New Issue
Block a user