Skip to content

Commit

Permalink
Merge remote-tracking branch 'stocd/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraust committed May 27, 2024
2 parents c05b9bc + 933c0a8 commit b6e49db
Show file tree
Hide file tree
Showing 45 changed files with 493 additions and 233 deletions.
317 changes: 171 additions & 146 deletions OSCRUI/app.py

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions OSCRUI/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ def save_combat(self, combat_num: int):
Parameters:
- :param combat_num: number of combat in self.combats
"""
if not self.parser1.active_combat:
combat = self.parser1.active_combat
if not combat:
return
base_dir = os.path.dirname(self.entry.text())
filename = combat.map
if combat.difficulty is not None and combat.difficulty != '':
filename += ' ' + combat.difficulty
filename += f' {combat.start_time.strftime('%Y-%m-%d %H.%M')}.log'
base_dir = f'{os.path.dirname(self.entry.text())}/{filename}'
if not base_dir:
base_dir = self.app_dir
path = self.browse_path(base_dir, 'Logfile (*.log);;Any File (*.*)', save=True)
Expand Down Expand Up @@ -191,6 +196,18 @@ def set_ui_scale_setting(self, new_value: int):
return setting_value


def set_live_scale_setting(self, new_value: int):
"""
Calculates new_value / 50 and stores it to settings.
Parameters:
- :param new_value: 50 times the live scale percentage
"""
setting_value = f'{new_value / 50:.2f}'
self.settings.setValue('live_scale', setting_value)
return setting_value


def set_sto_logpath_setting(self, entry: QLineEdit):
"""
Formats and stores new logpath to settings.
Expand Down
13 changes: 5 additions & 8 deletions OSCRUI/displayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def create_overview(self):
table_layout.addWidget(table)
self.widgets.overview_table_frame.setLayout(table_layout)
table.resizeColumnsToContents()
horizontal_header = table.horizontalHeader()
for col in range(len(TABLE_HEADER)):
horizontal_header.resizeSection(col, horizontal_header.sectionSize(col) + 5)


@setup_plot
Expand Down Expand Up @@ -300,8 +297,8 @@ def create_live_graph(self) -> tuple[QFrame, list]:
:return: Frame containing the graph and list of curves that will be used to plot the data
"""
plot_widget = PlotWidget()
plot_widget.setAxisItems({'left': CustomPlotAxis('left')})
plot_widget.setAxisItems({'bottom': CustomPlotAxis('bottom', unit='s')})
plot_widget.setAxisItems({'left': CustomPlotAxis('left', compressed=True)})
plot_widget.setAxisItems({'bottom': CustomPlotAxis('bottom', unit='s', no_labels=True)})
plot_widget.setStyleSheet(get_style(self, 'plot_widget_nullifier'))
plot_widget.setBackground(None)
plot_widget.setMouseEnabled(False, False)
Expand All @@ -310,9 +307,9 @@ def create_live_graph(self) -> tuple[QFrame, list]:
plot_widget.setDefaultPadding(padding=0)
plot_widget.setXRange(-14, 0, padding=0)
left_axis = plot_widget.getAxis('left')
left_axis.setTickFont(theme_font(self, 'plot_widget'))
left_axis.setTickFont(theme_font(self, 'live_plot_widget'))
left_axis.setTextPen(color=self.theme['defaults']['fg'])
left_axis.setTickDensity(3)
# left_axis.setTickDensity(0.1)
bottom_axis = plot_widget.getAxis('bottom')
bottom_axis.setTickFont(theme_font(self, 'plot_widget'))
bottom_axis.setTextPen(color=self.theme['defaults']['fg'])
Expand All @@ -323,7 +320,7 @@ def create_live_graph(self) -> tuple[QFrame, list]:
curves.append(plot_widget.plot([0], [0], pen=mkPen(color, width=1)))

frame = create_frame(self, None, 'plot_widget', size_policy=SMIXMAX, style_override={
'margin-left': '@margin', 'margin-right': '@margin', 'margin-bottom': 0})
'margin': 4, 'padding': 2})
frame.setMinimumWidth(self.sidebar_item_width * 0.25)
frame.setMinimumHeight(self.sidebar_item_width * 0.25)
layout = QHBoxLayout()
Expand Down
2 changes: 1 addition & 1 deletion OSCRUI/iofunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def browse_path(self, default_path: str = None, types: str = 'Any File (*.*)', s
if default_path is None or default_path == '':
default_path = self.app_dir
default_path = os.path.abspath(default_path)
if not os.path.exists(default_path):
if not os.path.exists(os.path.dirname(default_path)):
default_path = self.app_dir
if save:
f = QFileDialog.getSaveFileName(self.window, 'Save Log', default_path, types)[0]
Expand Down
6 changes: 3 additions & 3 deletions OSCRUI/leagueconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def slot_ladder(self, selected_map):
table = self.widgets.ladder_table
table.setModel(sorting_proxy)
table.resizeColumnsToContents()
table_header = table.horizontalHeader()
for col in range(len(model._header)):
table_header.resizeSection(col, table_header.sectionSize(col) + 5)
# table_header = table.horizontalHeader()
# for col in range(len(model._header)):
# table_header.resizeSection(col, table_header.sectionSize(col) + 5)


def extend_ladder(self):
Expand Down
2 changes: 1 addition & 1 deletion OSCRUI/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_css(self, style: dict) -> str:
css = str()
ui_scale = self.config['ui_scale']
for key, val in style.items():
if isinstance(val, str) and val[0] == '@':
if isinstance(val, str) and val.startswith('@'):
v = self.theme['defaults'][val[1:]]
else:
v = val
Expand Down
116 changes: 101 additions & 15 deletions OSCRUI/subwindows.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os

from PySide6.QtCore import QPoint, Qt
from PySide6.QtCore import QPoint, QSize, Qt
from PySide6.QtGui import QIntValidator, QMouseEvent
from PySide6.QtWidgets import QAbstractItemView, QDialog
from PySide6.QtWidgets import QGridLayout, QHBoxLayout, QLineEdit
from PySide6.QtWidgets import QMessageBox, QSpacerItem, QTableView
from PySide6.QtWidgets import QMessageBox, QSpacerItem, QSplitter, QTableView
from PySide6.QtWidgets import QVBoxLayout

from OSCR import LiveParser, LIVE_TABLE_HEADER
Expand All @@ -15,8 +15,8 @@
from .style import get_style, get_style_class, theme_font
from .textedit import format_path
from .widgetbuilder import create_button, create_frame, create_icon_button, create_label
from .widgetbuilder import ABOTTOM, ALEFT, ARIGHT, AVCENTER, RFIXED
from .widgetbuilder import SEXPAND, SMAX, SMAXMAX, SMINMIN
from .widgetbuilder import ABOTTOM, AHCENTER, ALEFT, ARIGHT, AVCENTER, RFIXED
from .widgetbuilder import SEXPAND, SMAX, SMAXMAX, SMINMAX, SMINMIN
from .widgets import FlipButton, LiveParserWindow, SizeGrip


Expand Down Expand Up @@ -192,6 +192,65 @@ def split_dialog(self):
dialog.exec()


def uploadresult_dialog(self, result):
"""
Shows a dialog that informs about the result of the triggered upload.
Paramters:
- :param result: dict containing result
"""
dialog = QDialog(self.window)
main_layout = QVBoxLayout()
thick = self.theme['app']['frame_thickness']
main_layout.setContentsMargins(thick, thick, thick, thick)
content_frame = create_frame(self)
main_layout.addWidget(content_frame)
content_layout = QGridLayout()
content_layout.setContentsMargins(thick, thick, thick, thick)
content_layout.setSpacing(0)
margin = {'margin-bottom': self.theme['defaults']['isp']}
title_label = create_label(self, 'Upload Results:', 'label_heading', style_override=margin)
content_layout.addWidget(title_label, 0, 0, 1, 4, alignment=ALEFT)
icon_size = QSize(self.config['icon_size'] / 1.5, self.config['icon_size'] / 1.5)
for row, line in enumerate(result, 1):
if row % 2 == 1:
table_style = {'background-color': '@mbg', 'padding': (5, 3, 3, 3), 'margin': 0}
icon_table_style = {'background-color': '@mbg', 'padding': (3, 3, 3, 3), 'margin': 0}
else:
table_style = {'background-color': '@bg', 'padding': (5, 3, 3, 3), 'margin': 0}
icon_table_style = {'background-color': '@bg', 'padding': (3, 3, 3, 3), 'margin': 0}
if line['updated']:
icon = self.icons['check'].pixmap(icon_size)
else:
icon = self.icons['dash'].pixmap(icon_size)
status_label = create_label(self, '', style_override=icon_table_style)
status_label.setPixmap(icon)
status_label.setSizePolicy(SMINMIN)
content_layout.addWidget(status_label, row, 0)
name_label = create_label(self, line['name'], style_override=table_style)
name_label.setSizePolicy(SMINMAX)
content_layout.addWidget(name_label, row, 1)
value_label = create_label(self, str(line['value']), style_override=table_style)
value_label.setSizePolicy(SMINMAX)
value_label.setAlignment(ARIGHT)
content_layout.addWidget(value_label, row, 2)
detail_label = create_label(self, line['detail'], style_override=table_style)
detail_label.setSizePolicy(SMINMAX)
content_layout.addWidget(detail_label, row, 3)
top_margin = {'margin-top': self.theme['defaults']['isp']}
close_button = create_button(self, 'Close', style_override=top_margin)
close_button.clicked.connect(dialog.close)
content_layout.addWidget(close_button, row + 1, 0, 1, 4, alignment=AHCENTER)
content_frame.setLayout(content_layout)

dialog.setLayout(main_layout)
dialog.setWindowTitle('OSCR - Upload Results')
dialog.setStyleSheet(get_style(self, 'dialog_window'))
dialog.setSizePolicy(SMAXMAX)
dialog.setFixedSize(dialog.sizeHint())
dialog.exec()


def live_parser_toggle(self, activate):
"""
Activates / Deactivates LiveParser.
Expand Down Expand Up @@ -230,10 +289,17 @@ def live_parser_toggle(self, activate):
self.live_parser_window = None
self.live_parser = None
self.widgets.live_parser_table = None
self.widgets.live_parser_splitter = None
self.widgets.live_parser_button.setChecked(False)


def create_live_parser_window(self):
"""
Creates the LiveParser window.
"""
ui_scale = self.config['ui_scale']
self.config['ui_scale'] = self.config['live_scale']

live_window = LiveParserWindow()
live_window.setStyleSheet(get_style(self, 'live_parser'))
live_window.setWindowFlags(
Expand All @@ -256,13 +322,23 @@ def create_live_parser_window(self):

graph_colors = None
graph_column = None
if self.settings.value('live_graph_active', type=bool):
graph_active = self.settings.value('live_graph_active', type=bool)
if graph_active:
splitter = QSplitter(Qt.Orientation.Vertical)
splitter.setStyleSheet(get_style_class(self, 'QSplitter', 'splitter'))
splitter.setChildrenCollapsible(False)
self.widgets.live_parser_splitter = splitter
graph_frame, curves = create_live_graph(self)
layout.addWidget(graph_frame, stretch=1)
graph_frame.setMinimumHeight(self.sidebar_item_width * 0.1)
splitter.addWidget(graph_frame)
self.widgets.live_parser_curves = curves
FIELD_INDEX_CONVERSION = {0: 0, 1: 2, 2: 3, 3: 4}
graph_column = FIELD_INDEX_CONVERSION[self.settings.value('live_graph_field', type=int)]
graph_colors = self.theme['plot']['color_cycler'][:5]
table_layout = splitter
layout.addWidget(splitter, stretch=1)
else:
table_layout = layout

table = QTableView()
table.setAlternatingRowColors(self.theme['s.c']['table_alternate'])
Expand All @@ -273,12 +349,16 @@ def create_live_parser_window(self):
table.horizontalHeader().setStyleSheet(
get_style_class(self, 'QHeaderView', 'live_table_header'))
table.verticalHeader().setStyleSheet(get_style_class(self, 'QHeaderView', 'live_table_index'))
table.verticalHeader().setMinimumHeight(1)
table.verticalHeader().setDefaultSectionSize(1)
table.horizontalHeader().setMinimumWidth(1)
table.horizontalHeader().setDefaultSectionSize(1)
table.horizontalHeader().setSectionResizeMode(RFIXED)
table.verticalHeader().setSectionResizeMode(RFIXED)
table.setSizePolicy(SMINMIN)
table.setSelectionMode(QAbstractItemView.SelectionMode.NoSelection)
table.setMinimumWidth(self.sidebar_item_width * 0.25)
table.setMinimumHeight(self.sidebar_item_width * 0.25)
table.setMinimumWidth(self.sidebar_item_width * 0.1)
table.setMinimumHeight(self.sidebar_item_width * 0.1)
model = LiveParserTableModel(
[[0] * len(LIVE_TABLE_HEADER)], LIVE_TABLE_HEADER, [''],
theme_font(self, 'live_table_header'), theme_font(self, 'live_table'),
Expand All @@ -290,30 +370,31 @@ def create_live_parser_window(self):
if not self.settings.value(f'live_columns|{index}', type=bool):
table.hideColumn(index)
self.widgets.live_parser_table = table
layout.addWidget(table, stretch=1)
table_layout.addWidget(table)

if graph_active and self.settings.value('live_splitter'):
table_layout.restoreState(self.settings.value('live_splitter'))

bottom_layout = QGridLayout()
bottom_layout.setContentsMargins(self.theme['defaults']['isp'], 0, 0, 0)
bottom_layout.setSpacing(0)
bottom_layout.setColumnStretch(0, 1)
bottom_layout.setColumnStretch(2, 1)

icon_size = [self.theme['s.c']['button_icon_size'] * self.config['live_scale'] * 0.8] * 2
copy_button = copy_button = create_icon_button(
self, self.icons['copy'], 'Copy Result', style_override={'margin-bottom': '@margin'},
icon_size=[self.theme['s.c']['button_icon_size'] * 0.8] * 2)
self, self.icons['copy'], 'Copy Result', icon_size=icon_size)
copy_button.clicked.connect(lambda: copy_live_data_callback(self))
bottom_layout.addWidget(copy_button, 0, 0, alignment=ARIGHT | AVCENTER)
activate_button = FlipButton('Activate', 'Deactivate', live_window, checkable=True)
activate_button.setStyleSheet(self.get_style_class(
'QPushButton', 'toggle_button', {'margin': (1, 8, 10, 8)}))
'QPushButton', 'toggle_button', {'margin': (0, 8, 0, 8)}))
activate_button.setFont(self.theme_font('app', '@subhead'))
activate_button.r_function = lambda: self.live_parser.start()
activate_button.l_function = lambda: self.live_parser.stop()
bottom_layout.addWidget(activate_button, 0, 1, alignment=AVCENTER)
close_button = create_icon_button(
self, self.icons['close'], 'Close Live Parser',
style_override={'margin-bottom': '@margin'},
icon_size=[self.theme['s.c']['button_icon_size'] * 0.8] * 2)
self, self.icons['close'], 'Close Live Parser', icon_size=icon_size)
close_button.clicked.connect(lambda: live_parser_toggle(self, False))
bottom_layout.addWidget(close_button, 0, 2, alignment=ALEFT | AVCENTER)

Expand All @@ -326,6 +407,7 @@ def create_live_parser_window(self):
live_window.update_table.connect(lambda data: update_live_table(self, data))
live_window.update_graph.connect(update_live_graph)
self.live_parser_window = live_window
self.config['ui_scale'] = ui_scale
live_window.show()


Expand All @@ -335,6 +417,10 @@ def live_parser_close_callback(self, event):
"""
window_geometry = self.live_parser_window.saveGeometry()
self.settings.setValue('live_geometry', window_geometry)
try:
self.settings.setValue('live_splitter', self.widgets.live_parser_splitter.saveState())
except AttributeError:
pass
event.accept()


Expand Down
8 changes: 6 additions & 2 deletions OSCRUI/widgetbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@

RFIXED = QHeaderView.ResizeMode.Fixed


SMPIXEL = QAbstractItemView.ScrollMode.ScrollPerPixel

SCROLLOFF = Qt.ScrollBarPolicy.ScrollBarAlwaysOff
SCROLLON = Qt.ScrollBarPolicy.ScrollBarAlwaysOn


def create_button(self, text, style: str = 'button', parent=None, style_override={}, toggle=None):
"""
Expand Down Expand Up @@ -86,7 +88,7 @@ def create_icon_button(
button.setToolTip(tooltip)
button.setStyleSheet(get_style_class(self, 'QPushButton', style, style_override))
if len(icon_size) != 2:
icon_size = [self.theme['s.c']['button_icon_size']] * 2
icon_size = [self.config['icon_size']] * 2
button.setIconSize(QSize(*icon_size))
button.setCursor(Qt.CursorShape.PointingHandCursor)
button.setSizePolicy(SMAXMAX)
Expand Down Expand Up @@ -361,6 +363,8 @@ def style_table(self, table: QTableView, style_override: dict = {}, single_row_s
table.setVerticalScrollMode(SMPIXEL)
table.horizontalHeader().setStyleSheet(get_style_class(self, 'QHeaderView', 'table_header'))
table.verticalHeader().setStyleSheet(get_style_class(self, 'QHeaderView', 'table_index'))
table.verticalHeader().setMinimumHeight(1)
table.verticalHeader().setDefaultSectionSize(1)
table.resizeColumnsToContents()
table.resizeRowsToContents()
table.horizontalHeader().setSortIndicatorShown(False)
Expand Down
Loading

0 comments on commit b6e49db

Please sign in to comment.