changed sorting to show up on the table headers

This commit is contained in:
UpstreamData
2022-05-10 11:51:26 -06:00
parent 6fa74613b4
commit 0dacd3d294
3 changed files with 41 additions and 47 deletions

View File

@@ -114,13 +114,6 @@ MINER_COUNT_BUTTONS = [
"pools_miner_count",
]
SORT_KEY_BUTTONS = [
"scan_sort_key",
"cmd_sort_key",
"cfg_sort_key",
"pools_sort_key",
]
HASHRATE_TOTAL_BUTTONS = [
"scan_total_hashrate",
"cfg_total_hashrate",
@@ -149,15 +142,15 @@ BUTTON_KEYS = [
TABLE_HEIGHT = 27
IMAGE_COL_WIDTH = 6
IMAGE_COL_WIDTH = 8
IP_COL_WIDTH = 17
MODEL_COL_WIDTH = 15
HOST_COL_WIDTH = 15
HASHRATE_COL_WIDTH = 12
TEMP_COL_WIDTH = 12
USER_COL_WIDTH = 31
WATTAGE_COL_WIDTH = 8
SPLIT_COL_WIDTH = 6
TEMP_COL_WIDTH = 14
USER_COL_WIDTH = 27
WATTAGE_COL_WIDTH = 10
SPLIT_COL_WIDTH = 8
SCAN_COL_WIDTHS = [
IP_COL_WIDTH,
MODEL_COL_WIDTH,
@@ -199,13 +192,6 @@ def get_scan_layout():
mouseover_colors=BTN_DISABLED,
),
sg.Push(background_color=MAIN_TABS_BG),
sg.Button(
"Sort: IP",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="scan_sort_key",
),
sg.Button(
"Hashrate: 0 TH/s",
disabled=True,
@@ -284,13 +270,6 @@ def get_command_layout():
disabled_button_color=BTN_DISABLED,
),
sg.Push(background_color=MAIN_TABS_BG),
sg.Button(
"Sort: IP",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="cmd_sort_key",
),
sg.Button(
"Miners: 0",
disabled=True,
@@ -380,13 +359,6 @@ def get_pools_layout():
disabled_button_color=BTN_DISABLED,
),
sg.Push(background_color=MAIN_TABS_BG),
sg.Button(
"Sort: IP",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="pools_sort_key",
),
sg.Button(
"Hashrate: 0 TH/s",
disabled=True,
@@ -534,13 +506,6 @@ def get_config_layout():
disabled_button_color=BTN_DISABLED,
),
sg.Push(background_color=MAIN_TABS_BG),
sg.Button(
"Sort: IP",
disabled=True,
button_color=("black", "white smoke"),
disabled_button_color=("black", "white smoke"),
key="cfg_sort_key",
),
sg.Button(
"Hashrate: 0 TH/s",
disabled=True,

View File

@@ -1,7 +1,6 @@
from tools.cfg_util.layout import (
MINER_COUNT_BUTTONS,
HASHRATE_TOTAL_BUTTONS,
SORT_KEY_BUTTONS,
TABLE_KEYS,
TABLE_HEADERS,
window,
@@ -25,11 +24,6 @@ def update_total_hr(hashrate: float):
window[button].update(f"Hashrate: {hashrate}")
def update_sort_key_btns():
for button in SORT_KEY_BUTTONS:
window[button].update(f"Sort: {TableManager().sort_key}")
def update_tables(data: list or None = None):
TableManager().update_data(data)
@@ -64,10 +58,11 @@ class TableManager(metaclass=Singleton):
self.update_item(line)
def update_sort_key(self, sort_key):
if "" in sort_key or "" in sort_key:
sort_key = sort_key[:-1]
if self.sort_key == sort_key:
self.sort_reverse = not self.sort_reverse
self.sort_key = sort_key
update_sort_key_btns()
self.update_tables()
def update_item(self, data: dict):
@@ -100,6 +95,39 @@ class TableManager(metaclass=Singleton):
ip_sorted_keys, reverse=self.sort_reverse, key=lambda x: self._get_sort(x)
)
table_names = {
"SCAN": "scan_table",
"POOLS_ALL": "pools_table",
"POOLS_1": "pools_1_table",
"POOLS_2": "pools_2_table",
"CONFIG": "cfg_table",
"CMD": "cmd_table",
}
for table in TABLE_HEADERS.keys():
widget = window[table_names[table]].Widget
for idx, header in enumerate(TABLE_HEADERS[table]):
_header = header
if header == self.sort_key:
if self.sort_reverse:
_header = f"{header}"
else:
_header = f"{header}"
widget.heading(idx, text=_header)
# reset light
window["cmd_table"].Widget.heading("#0", text="Light")
# handle light sort key
if self.sort_key == "Light":
widget = window["cmd_table"].Widget
idx = "#0"
if self.sort_reverse:
_header = f"Light▼"
else:
_header = f"Light▲"
widget.heading(idx, text=_header)
for data_idx, key in enumerate(sorted_keys):
item = self.data[key]
keys = item.keys()

View File

@@ -37,6 +37,7 @@ def _tree_header_click_handler(event, table):
async def ui():
window.read(0)
TableManager().update_tables()
# create images used in the table, they will not show if not saved here
tk_imgs = TkImages()