Skip to content

Commit

Permalink
Updates & Fixes
Browse files Browse the repository at this point in the history
- added about notes and links to the settings tab
- fixed column hider not hinding correct column on load
- maps now correctly load in everytime the league connection is established
- buttons and entries have appropriate cursors when hovering them
  • Loading branch information
Shinga13 committed Mar 18, 2024
1 parent 31a404e commit 40d83bf
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 34 deletions.
4 changes: 2 additions & 2 deletions OSCRUI/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .app import OSCRUI

__all__ = [
'app', 'datafunctions', 'datamodels', 'displayer', 'iofunctions', 'leagueconnector'
'style', 'textedit', 'widgetbuilder', 'widgets']
'app', 'callbacks', 'datafunctions', 'datamodels', 'displayer', 'iofunctions',
'leagueconnector', 'style', 'textedit', 'widgetbuilder', 'widgets']
92 changes: 76 additions & 16 deletions OSCRUI/app.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@

import os

from PySide6.QtWidgets import QApplication, QWidget, QLineEdit, QFrame, QListWidget, QTabWidget
from PySide6.QtWidgets import QTableView
from PySide6.QtWidgets import QApplication, QWidget, QLineEdit, QFrame, QListWidget
from PySide6.QtWidgets import QSpacerItem, QTabWidget, QTableView
from PySide6.QtWidgets import QVBoxLayout, QHBoxLayout, QGridLayout
from PySide6.QtCore import QSize, QSettings
from PySide6.QtGui import QIntValidator

from OSCR import HEAL_TREE_HEADER, TABLE_HEADER, TREE_HEADER

from .leagueconnector import OSCRClient
from .iofunctions import get_asset_path, load_icon_series, load_icon, reset_temp_folder
from .iofunctions import get_asset_path, load_icon_series, load_icon, open_link, reset_temp_folder
from .textedit import format_path
from .widgets import AnalysisPlot, BannerLabel, FlipButton, WidgetStorage
from .widgetbuilder import ABOTTOM, ACENTER, AHCENTER, ALEFT, ARIGHT, ATOP, AVCENTER
from .widgetbuilder import SMAXMAX, SMAXMIN, SMINMAX, SMINMIN, SMIXMAX, SMIXMIN
from .widgetbuilder import SEXPAND, SMAXMAX, SMAXMIN, SMIN, SMINMAX, SMINMIN, SMIXMAX, SMIXMIN

# only for developing; allows to terminate the qt event loop with keyboard interrupt
from signal import signal, SIGINT, SIG_DFL
Expand All @@ -39,6 +39,8 @@ class OSCRUI():

app_dir = None

versions = ('', '') # (release version, dev version)

config = {} # see main.py for contents

settings: QSettings # see main.py for defaults
Expand All @@ -48,7 +50,7 @@ class OSCRUI():

league_api: OSCRClient

def __init__(self, version, theme, args, path, config) -> None:
def __init__(self, theme, args, path, config, versions) -> None:
"""
Creates new Instance of OSCR.
Expand All @@ -59,7 +61,7 @@ def __init__(self, version, theme, args, path, config) -> None:
- :param path: absolute path to main.py file
- :param config: app configuration (!= settings these are not changed by the user)
"""
self.version = version
self.versions = versions
self.theme = theme
self.args = args
self.app_dir = path
Expand Down Expand Up @@ -102,7 +104,9 @@ def cache_assets(self):
'export-parse': 'export-parse.svg',
'copy': 'copy.svg',
'ladder': 'ladder.svg',
'star': 'star.svg'
'star': 'star.svg',
'stocd': 'section31badge.png',
'stobuilds': 'stobuildslogo.png'
}
self.icons = load_icon_series(icons, self.app_dir)

Expand Down Expand Up @@ -461,6 +465,59 @@ def setup_left_sidebar_log(self):

frame.setLayout(left_layout)

def setup_left_sidebar_about(self):
"""
Sets up the about tab of the left sidebar
"""
frame = self.widgets.sidebar_tab_frames[2]
m = self.theme['defaults']['margin']
left_layout = QVBoxLayout()
left_layout.setContentsMargins(m, m, m, m)
left_layout.setSpacing(0)
left_layout.setAlignment(ATOP)

head_label = self.create_label('About OSCR:', 'label_heading')
left_layout.addWidget(head_label)
about_label = self.create_label(
'Open Source Combatlog Reader (OSCR), developed by the STO Community '
'Developers in cooperation with the STO Builds Discord.')
about_label.setWordWrap(True)
left_layout.addWidget(about_label)
version_label = self.create_label(
f'Current Version: {self.versions[0]} ({self.versions[1]})', 'label_subhead',
style_override={'margin-bottom': '@isp'})
left_layout.addWidget(version_label)
link_button_style = {
'default': {},
'Website': {'callback': lambda: open_link(self.config['link_website'])},
'Github': {'callback': lambda: open_link(self.config['link_github'])},
'Downloads': {
'callback': lambda: open_link(self.config['link_downloads'])}
}
button_layout, buttons = self.create_button_series(
frame, link_button_style, 'button', seperator='•', ret=True)
buttons[0].setToolTip(self.config['link_website'])
buttons[1].setToolTip(self.config['link_github'])
buttons[2].setToolTip(self.config['link_downloads'])
left_layout.addLayout(button_layout)
left_layout.addSpacerItem(QSpacerItem(1, 1, hData=SMIN, vData=SEXPAND))
logo_layout = QGridLayout()
logo_layout.setContentsMargins(0, 0, 0, 0)
logo_layout.setColumnStretch(1, 1)
logo_size = [self.theme['s.c']['button_icon_size'] * 4] * 2
stocd_logo = self.create_icon_button(
self.icons['stocd'], self.config['link_stocd'],
style_override={'border-style': 'none'}, icon_size=logo_size)
stocd_logo.clicked.connect(lambda: open_link(self.config['link_stocd']))
logo_layout.addWidget(stocd_logo, 0, 0)
left_layout.addLayout(logo_layout)
stobuilds_logo = self.create_icon_button(
self.icons['stobuilds'], self.config['link_stobuilds'],
style_override={'border-style': 'none'}, icon_size=logo_size)
stobuilds_logo.clicked.connect(lambda: open_link(self.config['link_stobuilds']))
logo_layout.addWidget(stobuilds_logo, 0, 2)
frame.setLayout(left_layout)

def setup_left_sidebar_tabber(self, frame: QFrame):
"""
Sets up the sidebar used to select parses and combats
Expand All @@ -470,15 +527,18 @@ def setup_left_sidebar_tabber(self, frame: QFrame):
"""
log_frame = self.create_frame(style='medium_frame', size_policy=SMINMIN)
league_frame = self.create_frame(style='medium_frame', size_policy=SMINMIN)
about_frame = self.create_frame(style='medium_frame', size_policy=SMINMIN)
sidebar_tabber = QTabWidget(frame)
sidebar_tabber.setStyleSheet(self.get_style_class('QTabWidget', 'tabber'))
sidebar_tabber.tabBar().setStyleSheet(self.get_style_class('QTabBar', 'tabber_tab'))
sidebar_tabber.setSizePolicy(SMAXMIN)
sidebar_tabber.addTab(log_frame, 'Log')
sidebar_tabber.addTab(league_frame, 'League')
sidebar_tabber.addTab(about_frame, 'About')
self.widgets.sidebar_tabber = sidebar_tabber
self.widgets.sidebar_tab_frames.append(log_frame)
self.widgets.sidebar_tab_frames.append(league_frame)
self.widgets.sidebar_tab_frames.append(about_frame)
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
Expand All @@ -487,6 +547,7 @@ def setup_left_sidebar_tabber(self, frame: QFrame):

self.setup_left_sidebar_log()
self.setup_left_sidebar_league()
self.setup_left_sidebar_about()

def setup_main_tabber(self, frame: QFrame):
"""
Expand Down Expand Up @@ -517,8 +578,7 @@ def setup_main_tabber(self, frame: QFrame):
self.widgets.main_menu_buttons[0].clicked.connect(lambda: self.switch_main_tab(0))
self.widgets.main_menu_buttons[1].clicked.connect(lambda: self.switch_main_tab(1))
self.widgets.main_menu_buttons[2].clicked.connect(lambda: self.switch_main_tab(2))
self.widgets.main_menu_buttons[2].clicked.connect(
lambda: self.establish_league_connection(True))
self.widgets.main_menu_buttons[2].clicked.connect(self.establish_league_connection)
self.widgets.main_menu_buttons[3].clicked.connect(lambda: self.switch_main_tab(3))
self.widgets.main_tab_frames.append(o_frame)
self.widgets.main_tab_frames.append(a_frame)
Expand Down Expand Up @@ -750,13 +810,13 @@ def setup_league_standings_frame(self):
placeholder='name@handle', style_override={'margin-left': '@isp', 'margin-top': 0})
search_bar.textChanged.connect(lambda text: self.apply_league_table_filter(text))
control_layout.addWidget(search_bar, 0, 1, alignment=AVCENTER)
download_button = self.create_button('View Parse')
download_button.clicked.connect(self.download_and_view_combat)
control_layout.addWidget(download_button, 0, 3, alignment=AVCENTER)
next_button = self.create_button('More', style_override={'margin-right': 0})
next_button.clicked.connect(self.extend_ladder)
control_layout.addWidget(next_button, 0, 4, alignment=AVCENTER)

control_button_style = {
'View Parse': {'callback': self.download_and_view_combat},
'More': {'callback': self.extend_ladder, 'style': {'margin-right': 0}}
}
control_button_layout = self.create_button_series(
l_frame, control_button_style, 'button', seperator='•')
control_layout.addLayout(control_button_layout, 0, 3, alignment=AVCENTER)
layout.addLayout(control_layout)

l_frame.setLayout(layout)
Expand Down
2 changes: 1 addition & 1 deletion OSCRUI/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def switch_main_tab(self, tab_index: int):
0: 0,
1: 0,
2: 1,
3: 0
3: 2
}
self.widgets.main_tabber.setCurrentIndex(tab_index)
self.widgets.sidebar_tabber.setCurrentIndex(SIDEBAR_TAB_CONVERSION[tab_index])
Expand Down
4 changes: 2 additions & 2 deletions OSCRUI/datafunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def update_shown_columns_dmg(self):
dout_table = self.widgets.analysis_table_dout
dtaken_table = self.widgets.analysis_table_dtaken
for i in range(self.settings.value('dmg_columns_length', type=int)):
state = self.settings.value(f'dmg_columns|{i}')
state = self.settings.value(f'dmg_columns|{i}', type=bool)
if state:
dout_table.showColumn(i + 1)
dtaken_table.showColumn(i + 1)
Expand All @@ -231,7 +231,7 @@ def update_shown_columns_heal(self):
hout_table = self.widgets.analysis_table_hout
hin_table = self.widgets.analysis_table_hin
for i in range(self.settings.value('heal_columns_length', type=int)):
state = self.settings.value(f'heal_columns|{i}')
state = self.settings.value(f'heal_columns|{i}', type=bool)
if state:
hout_table.showColumn(i + 1)
hin_table.showColumn(i + 1)
Expand Down
9 changes: 9 additions & 0 deletions OSCRUI/iofunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import shutil
import sys
import webbrowser

from PySide6.QtWidgets import QFileDialog
from PySide6.QtGui import QIcon
Expand Down Expand Up @@ -84,6 +85,14 @@ def load_icon_series(icons: dict, app_directory: str) -> dict[str, QIcon]:
return icon_dict


def open_link(link: str = ''):
"""
Opens provided link
"""
if link:
webbrowser.open(link, new=2, autoraise=True)


def fetch_json(path: str) -> dict | list:
"""
Fetches json from path and returns dictionary.
Expand Down
14 changes: 7 additions & 7 deletions OSCRUI/leagueconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .datamodels import LeagueTableModel, SortingProxy
from .style import theme_font
from .textedit import format_datetime_str
from .widgetbuilder import show_warning

LADDER_HEADER = (
"Name",
Expand All @@ -28,7 +29,7 @@
)


def establish_league_connection(self, fetch_maps: bool = False):
def establish_league_connection(self):
"""
Connects to the league server if not already connected.
Expand All @@ -37,9 +38,8 @@ def establish_league_connection(self, fetch_maps: bool = False):
"""
if self.league_api is None:
self.league_api = OSCRClient()
if fetch_maps:
map_fetch_thread = CustomThread(self.window, lambda: fetch_and_insert_maps(self))
map_fetch_thread.start()
map_fetch_thread = CustomThread(self.window, lambda: fetch_and_insert_maps(self))
map_fetch_thread.start()


def fetch_and_insert_maps(self):
Expand Down Expand Up @@ -185,12 +185,12 @@ def upload_callback(self):
"""
Helper function to grab the current combat and upload it to the backend.
"""
if self.parser1.active_combat is None or self.parser1.active_combat.log_data is None:
show_warning(self, 'OSCR - Logfile Upload', 'No data to upload.')
return

establish_league_connection(self)

if self.parser1.active_combat is None or self.parser1.active_combat.log_data is None:
raise Exception("No data to upload")

with tempfile.NamedTemporaryFile(dir=self.config['templog_folder_path'], delete=False) as file:
data = gzip.compress(
"".join([logline_to_str(line) for line in self.parser1.active_combat.log_data]).encode()
Expand Down
11 changes: 8 additions & 3 deletions OSCRUI/widgetbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def create_button(self, text, style: str = 'button', parent=None, style_override
button.setFont(theme_font(self, style, style_override['font']))
else:
button.setFont(theme_font(self, style))
button.setCursor(Qt.CursorShape.PointingHandCursor)
button.setSizePolicy(SMAXMAX)
if isinstance(toggle, bool):
button.setCheckable(True)
Expand All @@ -68,7 +69,7 @@ def create_button(self, text, style: str = 'button', parent=None, style_override

def create_icon_button(
self, icon, tooltip: str = '', style: str = 'icon_button', parent=None,
style_override={}) -> QPushButton:
style_override={}, icon_size: tuple = ()) -> QPushButton:
"""
Creates a button showing an icon according to style with parent.
Expand All @@ -78,6 +79,7 @@ def create_icon_button(
- :param style: name of the style as in self.theme or style dict
- :param parent: parent of the button (optional)
- :param style_override: style dict to override default style (optional)
- :param icon_size: set icon size in case it should be different from the default
:return: configured QPushButton
"""
Expand All @@ -86,8 +88,10 @@ def create_icon_button(
if tooltip:
button.setToolTip(tooltip)
button.setStyleSheet(get_style_class(self, 'QPushButton', style, style_override))
icon_size = self.theme['s.c']['button_icon_size']
button.setIconSize(QSize(icon_size, icon_size))
if len(icon_size) != 2:
icon_size = [self.theme['s.c']['button_icon_size']] * 2
button.setIconSize(QSize(*icon_size))
button.setCursor(Qt.CursorShape.PointingHandCursor)
button.setSizePolicy(SMAXMAX)
return button

Expand Down Expand Up @@ -248,6 +252,7 @@ def create_entry(
entry.setFont(theme_font(self, style, style_override['font']))
else:
entry.setFont(theme_font(self, style))
entry.setCursor(Qt.CursorShape.IBeamCursor)
entry.setSizePolicy(SMAXMAX)
return entry

Expand Down
Binary file added assets/section31badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/stobuildslogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 20 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

class Launcher():

version = '2024.3b161'
version = '2024.3b180'
__version__ = '0.0'

# holds the style of the app
theme = {
Expand Down Expand Up @@ -136,6 +137,16 @@ class Launcher():
},
':disabled': {
'color': '@bc'
},
# Tooltip
'~QToolTip': {
'background-color': '@mbg',
'border-style': 'solid',
'border-color': '@lbg',
'border-width': '@bw',
'padding': (0, 0, 0, 0),
'color': '@fg',
'font': 'Overpass'
}
},
# button for tab switching
Expand Down Expand Up @@ -551,6 +562,11 @@ def app_config() -> dict:
'minimum_window_height': 1016,
'settings_path': r'/.OSCR_settings.ini',
'templog_folder_path': r'/~temp_log_files',
'link_website': '',
'link_github': 'https://github.com/STOCD/OSCR-UI',
'link_downloads': 'https://github.com/STOCD/OSCR-UI/releases',
'link_stobuilds': 'https://discord.gg/stobuilds',
'link_stocd': 'https://github.com/STOCD',
'default_settings': {
'log_path': '',
'geometry': None,
Expand Down Expand Up @@ -607,8 +623,9 @@ def app_config() -> dict:
def launch():
args = {}
exit_code = OSCRUI(
version=Launcher.version, theme=Launcher.theme, args=args,
path=Launcher.base_path(), config=Launcher.app_config()).run()
theme=Launcher.theme, args=args,
path=Launcher.base_path(), config=Launcher.app_config(),
versions=(Launcher.__version__, Launcher.version)).run()
sys.exit(exit_code)


Expand Down

0 comments on commit 40d83bf

Please sign in to comment.