fixed some bugs with sorting when refreshing data and added refreshing data
This commit is contained in:
@@ -5,7 +5,7 @@ from tools.cfg_util.cfg_util_qt.imgs import FAULT_LIGHT, TkImages
|
|||||||
from tools.cfg_util.cfg_util_qt.scan import btn_scan
|
from tools.cfg_util.cfg_util_qt.scan import btn_scan
|
||||||
from tools.cfg_util.cfg_util_qt.commands import btn_light
|
from tools.cfg_util.cfg_util_qt.commands import btn_light
|
||||||
from tools.cfg_util.cfg_util_qt.layout import window
|
from tools.cfg_util.cfg_util_qt.layout import window
|
||||||
from tools.cfg_util.cfg_util_qt.general import btn_all
|
from tools.cfg_util.cfg_util_qt.general import btn_all, btn_web, btn_refresh
|
||||||
from tools.cfg_util.cfg_util_qt.tables import TableManager
|
from tools.cfg_util.cfg_util_qt.tables import TableManager
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
|
||||||
@@ -42,6 +42,12 @@ async def main():
|
|||||||
if event == "scan_all":
|
if event == "scan_all":
|
||||||
_table = "scan_table"
|
_table = "scan_table"
|
||||||
btn_all(_table, value[_table])
|
btn_all(_table, value[_table])
|
||||||
|
if event == "scan_web":
|
||||||
|
_table = "scan_table"
|
||||||
|
btn_web(_table, value[_table])
|
||||||
|
if event == "scan_refresh":
|
||||||
|
_table = "scan_table"
|
||||||
|
asyncio.create_task(btn_refresh(_table, value[_table]))
|
||||||
if event == "btn_scan":
|
if event == "btn_scan":
|
||||||
await btn_scan(value["scan_ip"])
|
await btn_scan(value["scan_ip"])
|
||||||
|
|
||||||
@@ -49,16 +55,26 @@ async def main():
|
|||||||
if event == "pools_all":
|
if event == "pools_all":
|
||||||
_table = "pools_table"
|
_table = "pools_table"
|
||||||
btn_all(_table, value[_table])
|
btn_all(_table, value[_table])
|
||||||
|
if event == "pools_web":
|
||||||
|
_table = "pools_table"
|
||||||
|
btn_web(_table, value[_table])
|
||||||
|
if event == "pools_refresh":
|
||||||
|
_table = "pools_table"
|
||||||
|
asyncio.create_task(btn_refresh(_table, value[_table]))
|
||||||
|
|
||||||
# configure tab
|
# configure tab
|
||||||
if event == "cfg_all":
|
if event == "cfg_all":
|
||||||
_table = "cfg_table"
|
_table = "cfg_table"
|
||||||
btn_all(_table, value[_table])
|
btn_all(_table, value[_table])
|
||||||
|
if event == "cfg_web":
|
||||||
|
_table = "cfg_table"
|
||||||
|
btn_web(_table, value[_table])
|
||||||
|
|
||||||
# commands tab
|
# commands tab
|
||||||
if event == "cmd_all":
|
if event == "cmd_all":
|
||||||
_table = "cmd_table"
|
_table = "cmd_table"
|
||||||
btn_all(_table, value[_table])
|
btn_all(_table, value[_table])
|
||||||
|
|
||||||
if event == "cmd_light":
|
if event == "cmd_light":
|
||||||
_table = "cmd_table"
|
_table = "cmd_table"
|
||||||
_ips = value[_table]
|
_ips = value[_table]
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
from miners.miner_factory import MinerFactory
|
from miners.miner_factory import MinerFactory
|
||||||
from tools.cfg_util.cfg_util_qt.layout import window
|
from tools.cfg_util.cfg_util_qt.layout import window
|
||||||
from tools.cfg_util.cfg_util_qt.tables import TableManager
|
from tools.cfg_util.cfg_util_qt.tables import TableManager
|
||||||
|
from tools.cfg_util.cfg_util_qt.decorators import disable_buttons
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
async def btn_light(ips: list):
|
async def btn_light(ips: list):
|
||||||
table_manager = TableManager()
|
table_manager = TableManager()
|
||||||
_table = window["cmd_table"].Widget
|
_table = window["cmd_table"].Widget
|
||||||
|
|||||||
19
tools/cfg_util/cfg_util_qt/decorators.py
Normal file
19
tools/cfg_util/cfg_util_qt/decorators.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from tools.cfg_util.cfg_util_qt.layout import window
|
||||||
|
from tools.cfg_util.cfg_util_qt.layout import BUTTON_KEYS
|
||||||
|
|
||||||
|
|
||||||
|
def disable_buttons(func):
|
||||||
|
# handle the inner function that the decorator is wrapping
|
||||||
|
async def inner(*args, **kwargs):
|
||||||
|
# disable the buttons
|
||||||
|
for button in BUTTON_KEYS:
|
||||||
|
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_KEYS:
|
||||||
|
window[button].Update(disabled=False)
|
||||||
|
|
||||||
|
return inner
|
||||||
@@ -1,4 +1,27 @@
|
|||||||
from tools.cfg_util.cfg_util_qt.layout import window, TABLE_KEYS
|
import asyncio
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
|
from miners.miner_factory import MinerFactory
|
||||||
|
from tools.cfg_util.cfg_util_qt.decorators import disable_buttons
|
||||||
|
from tools.cfg_util.cfg_util_qt.layout import TABLE_KEYS
|
||||||
|
from tools.cfg_util.cfg_util_qt.layout import window, update_prog_bar
|
||||||
|
from tools.cfg_util.cfg_util_qt.tables import TableManager
|
||||||
|
|
||||||
|
progress_bar_len = 0
|
||||||
|
|
||||||
|
DEFAULT_DATA = [
|
||||||
|
"Model",
|
||||||
|
"Hostname",
|
||||||
|
"Hashrate",
|
||||||
|
"Temperature",
|
||||||
|
"Pool User",
|
||||||
|
"Pool 1",
|
||||||
|
"Pool 1 User",
|
||||||
|
"Pool 2",
|
||||||
|
"Pool 2 User",
|
||||||
|
"Wattage",
|
||||||
|
"Split",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def btn_all(table, selected):
|
def btn_all(table, selected):
|
||||||
@@ -18,3 +41,45 @@ def btn_all(table, selected):
|
|||||||
_tree = window[table]
|
_tree = window[table]
|
||||||
rows_to_select = [i for i in _tree.Widget.get_children()]
|
rows_to_select = [i for i in _tree.Widget.get_children()]
|
||||||
_tree.Widget.selection_set(rows_to_select)
|
_tree.Widget.selection_set(rows_to_select)
|
||||||
|
|
||||||
|
|
||||||
|
def btn_web(table, selected):
|
||||||
|
for row in selected:
|
||||||
|
webbrowser.open("http://" + window[table].Values[row][0])
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
|
async def btn_refresh(table, selected):
|
||||||
|
ips = [window[table].Values[row][0] for row in selected]
|
||||||
|
if not len(selected) > 0:
|
||||||
|
ips = [window[table].Values[row][0] for row in range(len(window[table].Values))]
|
||||||
|
|
||||||
|
await _get_miners_data(ips)
|
||||||
|
|
||||||
|
|
||||||
|
async def _get_miners_data(miners: list):
|
||||||
|
data = []
|
||||||
|
for miner in miners:
|
||||||
|
_data = {}
|
||||||
|
for key in DEFAULT_DATA:
|
||||||
|
_data[key] = ""
|
||||||
|
_data["IP"] = str(miner)
|
||||||
|
data.append(_data)
|
||||||
|
|
||||||
|
TableManager().update_data(data)
|
||||||
|
|
||||||
|
global progress_bar_len
|
||||||
|
progress_bar_len = 0
|
||||||
|
await update_prog_bar(progress_bar_len, max=len(miners))
|
||||||
|
data_generator = asyncio.as_completed(
|
||||||
|
[_get_data(await MinerFactory().get_miner(miner)) for miner in miners]
|
||||||
|
)
|
||||||
|
for all_data in data_generator:
|
||||||
|
data = await all_data
|
||||||
|
TableManager().update_item(data)
|
||||||
|
progress_bar_len += 1
|
||||||
|
await update_prog_bar(progress_bar_len)
|
||||||
|
|
||||||
|
|
||||||
|
async def _get_data(miner):
|
||||||
|
return await miner.get_data()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
from .imgs import WINDOW_ICON, LIGHT, FAULT_LIGHT
|
|
||||||
|
from .imgs import WINDOW_ICON
|
||||||
|
|
||||||
TABLE_HEADERS = {
|
TABLE_HEADERS = {
|
||||||
"SCAN": [
|
"SCAN": [
|
||||||
@@ -84,6 +85,7 @@ async def update_prog_bar(count: int, max: int = None):
|
|||||||
if not hasattr(bar, "maxlen"):
|
if not hasattr(bar, "maxlen"):
|
||||||
if not max:
|
if not max:
|
||||||
max = 100
|
max = 100
|
||||||
|
if max:
|
||||||
bar.maxlen = max
|
bar.maxlen = max
|
||||||
percent_done = 100 * (count / bar.maxlen)
|
percent_done = 100 * (count / bar.maxlen)
|
||||||
window["progress_percent"].Update(f"{round(percent_done, 2)} %")
|
window["progress_percent"].Update(f"{round(percent_done, 2)} %")
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from tools.cfg_util.cfg_util_qt.tables import clear_tables, update_tables, TableManager
|
|
||||||
from tools.cfg_util.cfg_util_qt.layout import window, update_prog_bar
|
|
||||||
from network import MinerNetwork
|
|
||||||
from miners.miner_factory import MinerFactory
|
from miners.miner_factory import MinerFactory
|
||||||
from datetime import datetime
|
from network import MinerNetwork
|
||||||
from API import APIError
|
from tools.cfg_util.cfg_util_qt.decorators import disable_buttons
|
||||||
|
from tools.cfg_util.cfg_util_qt.layout import window, update_prog_bar
|
||||||
import warnings
|
from tools.cfg_util.cfg_util_qt.tables import clear_tables, TableManager
|
||||||
import logging
|
|
||||||
|
|
||||||
progress_bar_len = 0
|
progress_bar_len = 0
|
||||||
|
|
||||||
@@ -45,6 +41,7 @@ async def btn_scan(scan_ip: str):
|
|||||||
asyncio.create_task(_scan_miners(network))
|
asyncio.create_task(_scan_miners(network))
|
||||||
|
|
||||||
|
|
||||||
|
@disable_buttons
|
||||||
async def _scan_miners(network: MinerNetwork):
|
async def _scan_miners(network: MinerNetwork):
|
||||||
clear_tables()
|
clear_tables()
|
||||||
scan_generator = network.scan_network_generator()
|
scan_generator = network.scan_network_generator()
|
||||||
|
|||||||
@@ -129,6 +129,13 @@ class TableManager(metaclass=Singleton):
|
|||||||
self.data[data_key]["Hashrate"].replace(" ", "").replace("TH/s", "")
|
self.data[data_key]["Hashrate"].replace(" ", "").replace("TH/s", "")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.sort_key in ["Wattage", "Temperature"]:
|
||||||
|
if isinstance(self.data[data_key][self.sort_key], str):
|
||||||
|
if self.sort_reverse:
|
||||||
|
return -100000000 # large negative number to place it at the bottom
|
||||||
|
else:
|
||||||
|
return 1000000000 # large number to place it at the bottom
|
||||||
|
|
||||||
return self.data[data_key][self.sort_key]
|
return self.data[data_key][self.sort_key]
|
||||||
|
|
||||||
def clear_tables(self):
|
def clear_tables(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user