added ctrl c and ctrl a functionality to the tables

This commit is contained in:
UpstreamData
2022-05-11 08:37:17 -06:00
parent 8677eff491
commit 564cd42eae
3 changed files with 57 additions and 3 deletions

View File

@@ -113,7 +113,13 @@ TABLE_HEADERS = {
} }
TABLE_KEYS = { TABLE_KEYS = {
"table": ["scan_table", "pools_table", "cfg_table"], "table": [
"scan_table",
"pools_table",
"pools_1_table",
"pools_2_table",
"cfg_table",
],
"tree": ["cmd_table"], "tree": ["cmd_table"],
} }
@@ -195,6 +201,7 @@ def get_scan_layout():
border_width=BTN_BORDER, border_width=BTN_BORDER,
disabled_button_color=BTN_DISABLED, disabled_button_color=BTN_DISABLED,
mouseover_colors=BTN_DISABLED, mouseover_colors=BTN_DISABLED,
bind_return_key=True,
), ),
], ],
[ [

View File

@@ -51,7 +51,7 @@ async def _scan_miners(network: MinerNetwork):
progress_bar_len = 0 progress_bar_len = 0
network_size = len(network) network_size = len(network)
await update_prog_bar(progress_bar_len, max=(3 * network_size)) await update_prog_bar(progress_bar_len, _max=(3 * network_size))
scanned_miners = [] scanned_miners = []
async for miner in scan_generator: async for miner in scan_generator:

View File

@@ -14,10 +14,11 @@ from tools.cfg_util.configure import (
btn_import, btn_import,
btn_config, btn_config,
) )
from tools.cfg_util.layout import window from tools.cfg_util.layout import window, TABLE_KEYS
from tools.cfg_util.general import btn_all, btn_web, btn_refresh from tools.cfg_util.general import btn_all, btn_web, btn_refresh
from tools.cfg_util.tables import TableManager from tools.cfg_util.tables import TableManager
import tkinter as tk import tkinter as tk
import pyperclip
def _tree_header_click_handler(event, table): def _tree_header_click_handler(event, table):
@@ -35,10 +36,56 @@ def _tree_header_click_handler(event, table):
mgr.update_sort_key(heading) mgr.update_sort_key(heading)
def _table_copy(table):
selection = window[table].Widget.selection()
_copy_values = []
for each in selection:
try:
value = window[table].Widget.item(each)["values"]
values = []
for item in value:
values.append(str(item).strip())
_copy_values.append(values)
except Exception as E:
pass
copy_values = []
for item in _copy_values:
copy_values.append(", ".join(item))
copy_string = "\n".join(copy_values)
pyperclip.copy(copy_string)
def _table_select_all(table):
if table in TABLE_KEYS["table"]:
window[table].update(
select_rows=([row for row in range(len(window[table].Values))])
)
if table in TABLE_KEYS["tree"]:
_tree = window[table]
rows_to_select = [i for i in _tree.Widget.get_children()]
_tree.Widget.selection_set(rows_to_select)
def bind_copy(key):
widget = window[key].Widget
widget.bind("<Control-Key-c>", lambda x: _table_copy(key))
def bind_ctrl_a(key):
widget = window[key].Widget
widget.bind("<Control-Key-a>", lambda x: _table_select_all(key))
async def ui(): async def ui():
window.read(0) window.read(0)
TableManager().update_tables() TableManager().update_tables()
for key in [*TABLE_KEYS["table"], *TABLE_KEYS["tree"]]:
bind_copy(key)
bind_ctrl_a(key)
# create images used in the table, they will not show if not saved here # create images used in the table, they will not show if not saved here
tk_imgs = TkImages() tk_imgs = TkImages()