Skip to content

Commit

Permalink
Added copy table data via ctrl+C shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinga13 committed Aug 16, 2024
1 parent bb6aafc commit aec0e65
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
16 changes: 10 additions & 6 deletions OSCRUI/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from PySide6.QtWidgets import QSpacerItem, QTabWidget, QTableView
from PySide6.QtWidgets import QVBoxLayout, QHBoxLayout, QGridLayout
from PySide6.QtCore import QSize, QSettings, QTimer
from PySide6.QtGui import QFontDatabase, QIntValidator
from PySide6.QtGui import QFontDatabase, QIntValidator, QKeySequence, QShortcut

from .headers import init_header_trans, get_table_headers, get_tree_headers, get_heal_tree_headers, get_live_table_headers
from .headers import (
init_header_trans, get_table_headers, get_tree_headers, get_heal_tree_headers,
get_live_table_headers)
from .translation import init_translation

from .leagueconnector import OSCRClient
Expand All @@ -30,9 +32,10 @@ class OSCRUI():
set_parser_opacity_setting, set_graph_resolution_setting, set_sto_logpath_setting,
set_ui_scale_setting, switch_analysis_tab, switch_main_tab, switch_map_tab,
switch_overview_tab)
from .datafunctions import analyze_log_callback, copy_analysis_callback
from .datafunctions import copy_summary_callback, init_parser, update_shown_columns_dmg
from .datafunctions import update_shown_columns_heal
from .datafunctions import (
analyze_log_callback, copy_analysis_callback, copy_analysis_table_callback,
copy_summary_callback, init_parser, update_shown_columns_dmg,
update_shown_columns_heal)
from .displayer import create_legend_item
from .iofunctions import browse_path
from .style import get_style_class, create_style_sheet, theme_font, get_style
Expand All @@ -59,7 +62,6 @@ class OSCRUI():

league_api: OSCRClient


def __init__(self, theme, args, path, config, versions) -> None:
"""
Creates new Instance of OSCR.
Expand Down Expand Up @@ -87,6 +89,8 @@ def __init__(self, theme, args, path, config, versions) -> None:

reset_temp_folder(self.config['templog_folder_path'])
self.app, self.window = self.create_main_window()
self.copy_shortcut = QShortcut(
QKeySequence.StandardKey.Copy, self.window, self.copy_analysis_table_callback)
self.init_parser()
self.cache_assets()
self.setup_main_layout()
Expand Down
44 changes: 39 additions & 5 deletions OSCRUI/datafunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def init_parser(self):
# self.parser2 = OSCR()


def analyze_log_callback(self, translate, combat_id=None, path=None, parser_num: int = 1, hidden_path=False):
def analyze_log_callback(
self, translate, combat_id=None, path=None, parser_num: int = 1, hidden_path=False):
"""
Wrapper function for retrieving and showing data. Callback of "Analyse" and "Refresh" button.
Expand All @@ -51,7 +52,7 @@ def analyze_log_callback(self, translate, combat_id=None, path=None, parser_num:
return
if parser_num == 1:
parser: OSCR = self.parser1
elif parser_num == 2:
elif parser_num == 2:
parser: OSCR = self.parser2
else:
return
Expand All @@ -63,7 +64,8 @@ def analyze_log_callback(self, translate, combat_id=None, path=None, parser_num:
if combat_id is None:
if not path or not os.path.isfile(path):
show_warning(
self, self._('Invalid Logfile'), self._('The Logfile you are trying to open does not exist.'))
self, self._('Invalid Logfile'),
self._('The Logfile you are trying to open does not exist.'))
return
if not hidden_path and path != self.settings.value('log_path'):
self.settings.setValue('log_path', path)
Expand Down Expand Up @@ -218,7 +220,8 @@ def populate_analysis(self, root_items: tuple):
heal_out_table = self.widgets.analysis_table_hout
heal_out_model = HealTreeModel(
heal_out_item, self.theme_font('tree_table_header'), self.theme_font('tree_table'),
self.theme_font('', self.theme['tree_table']['::item']['font']), get_heal_tree_headers())
self.theme_font('', self.theme['tree_table']['::item']['font']),
get_heal_tree_headers())
heal_out_table.setModel(heal_out_model)
heal_out_root_index = damage_in_model.createIndex(0, 0, heal_out_model._root)
heal_out_table.expand(heal_out_model.index(0, 0, heal_out_root_index))
Expand All @@ -228,7 +231,8 @@ def populate_analysis(self, root_items: tuple):
heal_in_table = self.widgets.analysis_table_hin
heal_in_model = HealTreeModel(
heal_in_item, self.theme_font('tree_table_header'), self.theme_font('tree_table'),
self.theme_font('', self.theme['tree_table']['::item']['font']), get_heal_tree_headers())
self.theme_font('', self.theme['tree_table']['::item']['font']),
get_heal_tree_headers())
heal_in_table.setModel(heal_in_model)
heal_in_root_index = damage_in_model.createIndex(0, 0, heal_in_model._root)
heal_in_table.expand(heal_in_model.index(0, 0, heal_in_root_index))
Expand Down Expand Up @@ -283,6 +287,36 @@ def resize_tree_table(tree):
tree.header().resizeSection(col, width)


def copy_analysis_table_callback(self):
"""
Copies the current selection of analysis table as tab-delimited table
"""
print('Table COPY')
if self.widgets.main_tabber.currentIndex() != 1:
return
current_tab = self.widgets.analysis_tabber.currentIndex()
current_table = self.widgets.analysis_table[current_tab]
if current_tab <= 1:
format_function = format_damage_tree_data
else:
format_function = format_heal_tree_data
selection: list = current_table.selectedIndexes()
if selection:
selection.sort(key=lambda index: (index.row(), index.column()))
output = list()
last_row = -1
for cell_index in selection:
col = cell_index.column()
if cell_index.row() != last_row:
output.append(list())
output[-1].append(cell_index.internalPointer().get_data(col))
last_row = cell_index.row()
print(output)
output_text = '\n'.join(map(lambda row: '\t'.join(map(str, row)), output))
print(output_text)
self.app.clipboard().setText(output_text)


def copy_analysis_callback(self):
"""
Callback for copy button on analysis tab
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Launcher():

version = '2024.08b030'
version = '2024.08b160'
__version__ = '0.2'

# holds the style of the app
Expand Down

0 comments on commit aec0e65

Please sign in to comment.