Skip to content

Commit

Permalink
Improved map selector for league tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinga13 committed Mar 3, 2024
1 parent d7f70b3 commit 69a6977
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 52 deletions.
135 changes: 101 additions & 34 deletions OSCRUI/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def main_window_resize_callback(self, event):
"""
self.entry.setFixedWidth(self.sidebar_item_width)
self.current_combats.setFixedWidth(self.sidebar_item_width)
self.widgets.ladder_map.setFixedWidth(self.sidebar_item_width)
event.accept()

# -------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -192,7 +193,7 @@ def setup_main_layout(self):
content_layout.setContentsMargins(0, 0, 0, 0)
content_layout.setSpacing(0)

left = self.create_frame(main_frame, 'medium_frame')
left = self.create_frame(main_frame)
left.setSizePolicy(SMAXMIN)
content_layout.addWidget(left, 0, 0)

Expand Down Expand Up @@ -224,23 +225,53 @@ def setup_main_layout(self):
content_layout.addWidget(center, 0, 2)

main_frame.setLayout(content_layout)
self.setup_left_sidebar(left)
self.setup_left_sidebar_tabber(left)
self.setup_main_tabber(center)
self.setup_overview_frame()
self.setup_analysis_frame()
self.setup_league_standings_frame()
self.setup_settings_frame()

def setup_left_sidebar(self, frame:QFrame):
def setup_left_sidebar_league(self):
"""
Sets up the sidebar used to select parses and combats
Sets up the league table management tab of the left sidebar
"""
frame = self.widgets.sidebar_tab_frames[1]
m = self.theme['defaults']['margin']
left_layout = QVBoxLayout()
left_layout.setContentsMargins(m, m, 0.5 * m, m)
left_layout.setSpacing(0)
left_layout.setAlignment(ATOP)

Parameters:
- :param frame: QFrame -> parent frame of the sidebar
map_label = self.create_label('Available Maps:', 'label_heading', frame)
left_layout.addWidget(map_label)

background_frame = self.create_frame(frame, 'light_frame',
{'border-radius': self.theme['listbox']['border-radius'], 'margin-top': '@csp'}, SMAXMIN)
background_layout = QVBoxLayout()
background_layout.setContentsMargins(0, 0, 0, 0)
background_frame.setLayout(background_layout)
map_selector = QListWidget(background_frame)
map_selector.setStyleSheet(self.get_style_class('QListWidget', 'listbox'))
map_selector.setFont(self.theme_font('listbox'))
map_selector.setSizePolicy(SMAXMIN)
self.widgets.ladder_map = map_selector
map_selector.currentTextChanged.connect(lambda new_text: self.update_ladder_index(new_text))
map_selector.setFixedWidth(self.sidebar_item_width)
background_layout.addWidget(map_selector)
left_layout.addWidget(background_frame, stretch=1)

frame.setLayout(left_layout)


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

Expand Down Expand Up @@ -331,37 +362,64 @@ def setup_left_sidebar(self, frame:QFrame):

frame.setLayout(left_layout)

def setup_left_sidebar_tabber(self, frame: QFrame):
"""
Sets up the sidebar used to select parses and combats
Parameters:
- :param frame: QFrame -> parent frame of the sidebar
"""
log_frame = self.create_frame(style='medium_frame')
league_frame = self.create_frame(style='medium_frame')
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')
self.widgets.sidebar_tabber = sidebar_tabber
self.widgets.sidebar_tab_frames.append(log_frame)
self.widgets.sidebar_tab_frames.append(league_frame)
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
layout.addWidget(sidebar_tabber)
frame.setLayout(layout)

self.setup_left_sidebar_log()
self.setup_left_sidebar_league()

def setup_main_tabber(self, frame:QFrame):
"""
Sets up the tabber switching between Overview, Analysis, League and Settings.
Parameters:
- :param frame: QFrame -> parent frame of the sidebar
"""
o_frame = self.create_frame(None, 'frame')
a_frame = self.create_frame(None, 'frame')
l_frame = self.create_frame(None, 'frame')
s_frame = self.create_frame(None, 'frame')
o_frame = self.create_frame()
a_frame = self.create_frame()
l_frame = self.create_frame()
s_frame = self.create_frame()

main_tabber = QTabWidget(frame)
main_tabber.setStyleSheet(self.get_style_class('QTabWidget', 'tabber'))
main_tabber.tabBar().setStyleSheet(self.get_style_class( 'QTabBar', 'tabber_tab'))
main_tabber.setSizePolicy(SMINMIN)
main_tabber.addTab(o_frame, 'O')
main_tabber.addTab(a_frame, 'A')
main_tabber.addTab(l_frame, 'L')
main_tabber.addTab(s_frame, 'S')
main_tabber.addTab(o_frame, '&O')
main_tabber.addTab(a_frame, '&A')
main_tabber.addTab(l_frame, '&L')
main_tabber.addTab(s_frame, '&S')

layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(main_tabber)
frame.setLayout(layout)

self.widgets.main_menu_buttons[0].clicked.connect(lambda: main_tabber.setCurrentIndex(0))
self.widgets.main_menu_buttons[1].clicked.connect(lambda: main_tabber.setCurrentIndex(1))
self.widgets.main_menu_buttons[2].clicked.connect(lambda: main_tabber.setCurrentIndex(2))
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[3].clicked.connect(lambda: main_tabber.setCurrentIndex(3))
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)
self.widgets.main_tab_frames.append(l_frame)
Expand Down Expand Up @@ -563,27 +621,20 @@ def setup_league_standings_frame(self):
l_frame = self.widgets.main_tab_frames[2]
layout = QVBoxLayout()
margin = self.theme['defaults']['margin']
layout.setContentsMargins(0, 0, 0, margin)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)

spacing = self.theme['defaults']['isp']
control_frame = self.create_frame(l_frame)
control_frame_layout = QHBoxLayout()
control_frame_layout.setContentsMargins(margin, margin, margin, margin)
control_frame_layout.setSpacing(spacing)

map_selector = self.create_combo_box(control_frame)
map_selector.addItem("Select a League")
self.widgets.ladder_map = map_selector
map_selector.currentIndexChanged.connect(lambda new_index: self.update_ladder_index(new_index))
control_frame_layout.addWidget(map_selector)
control_frame.setLayout(control_frame_layout)
# spacing = self.theme['defaults']['isp']
# control_frame = self.create_frame(l_frame)
# control_frame_layout = QHBoxLayout()
# control_frame_layout.setContentsMargins(margin, margin, margin, margin)
# control_frame_layout.setSpacing(spacing)

ladder_table = QTableView(l_frame)
self.style_table(ladder_table)
self.style_table(ladder_table, {'margin': '@margin'})
self.widgets.ladder_table = ladder_table

layout.addWidget(control_frame, alignment=AHCENTER)
# layout.addWidget(control_frame, alignment=AHCENTER)
layout.addWidget(ladder_table)
l_frame.setLayout(layout)

Expand Down Expand Up @@ -831,6 +882,22 @@ def switch_overview_tab(self, tab_index: int):
else:
button.setChecked(True)

def switch_main_tab(self, tab_index: int):
"""
Callback for main tab switch buttons. Switches main and sidebar tabs.
Parameters:
- :param tab_index: index of the tab to switch to
"""
SIDEBAR_TAB_CONVERSION = {
0: 0,
1: 0,
2: 1,
3: 0
}
self.widgets.main_tabber.setCurrentIndex(tab_index)
self.widgets.sidebar_tabber.setCurrentIndex(SIDEBAR_TAB_CONVERSION[tab_index])

def set_variable(self, var_to_be_set, index, value):
"""
Assigns value at index to variable
Expand Down
31 changes: 19 additions & 12 deletions OSCRUI/leagueconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .datamodels import LeagueTableModel, SortingProxy
from .textedit import format_datetime_str
from .style import theme_font
from .datafunctions import CustomThread

LADDER_HEADER = ('Name', 'Handle', 'DPS', 'Total Damage', 'Deaths', 'Combat Time', 'Date', 'Max One Hit',
'Debuff')
Expand All @@ -25,20 +26,26 @@ def establish_league_connection(self, fetch_maps: bool = False):
"""
if self.league_api is None:
self.league_api = OSCRClient()
if fetch_maps and isinstance(self.league_api, OSCRClient):
ladders = self.league_api.ladders()
if ladders is not None:
self.widgets.ladder_map.clear()
for ladder in ladders.results:
solo = '[Solo] ' if ladder.is_solo else ''
key = f'{solo}{ladder.metric} - {ladder.name} ({ladder.difficulty})'
self.league_api.ladder_dict[key] = ladder
self.widgets.ladder_map.addItem(key)

def update_ladder_index(self, index):
if fetch_maps:
map_fetch_thread = CustomThread(self.window, lambda: fetch_and_insert_maps(self))
map_fetch_thread.start()

def fetch_and_insert_maps(self):
"""
Retrieves maps from API and inserts them into the list.
"""
ladders = self.league_api.ladders()
if ladders is not None:
self.widgets.ladder_map.clear()
for ladder in ladders.results:
solo = '' # '[Solo] ' if ladder.is_solo else ''
key = f'{solo}{ladder.metric} - {ladder.name} ({ladder.difficulty})'
self.league_api.ladder_dict[key] = ladder
self.widgets.ladder_map.addItem(key)

def update_ladder_index(self, selected_map):
"""Open Combat Log Dialog Box"""

selected_map = self.widgets.ladder_map.currentText()
if not selected_map in self.league_api.ladder_dict:
return

Expand Down
6 changes: 3 additions & 3 deletions OSCRUI/widgetbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .style import get_style_class, get_style, merge_style, theme_font
from .textedit import format_path
from .iofunctions import browse_path
from .datamodels import TreeSelectionModel

CALLABLE = (FunctionType, BuiltinFunctionType, MethodType)

Expand Down Expand Up @@ -276,17 +275,18 @@ def create_analysis_table(self, parent, widget) -> QTreeView:
table.collapsed.connect(lambda: resize_tree_table(table))
return table

def style_table(self, table: QTableView):
def style_table(self, table: QTableView, style_override: dict = {}):
"""
Styles the given table.
Parameters:
- :param table: table to be styled
- :param style_override: style override for table
"""
table.setAlternatingRowColors(self.theme['s.c']['table_alternate'])
table.setShowGrid(self.theme['s.c']['table_gridline'])
table.setSortingEnabled(True)
table.setStyleSheet(get_style_class(self, 'QTableView', 'table'))
table.setStyleSheet(get_style_class(self, 'QTableView', 'table', style_override))
table.setHorizontalScrollMode(SMPIXEL)
table.setVerticalScrollMode(SMPIXEL)
table.horizontalHeader().setStyleSheet(get_style_class(self, 'QHeaderView', 'table_header'))
Expand Down
2 changes: 2 additions & 0 deletions OSCRUI/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def __init__(self):
self.main_menu_buttons: list[QPushButton] = list()
self.main_tabber: QTabWidget
self.main_tab_frames: list[QFrame] = list()
self.sidebar_tabber: QTabWidget
self.sidebar_tab_frames: list[QFrame] = list()

self.navigate_up_button: QPushButton
self.navigate_down_button: QPushButton
Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Launcher():

version = '2024.3a31'
version = '2024.3a32'

# holds the style of the app
theme = {
Expand Down Expand Up @@ -269,7 +269,7 @@ class Launcher():
'margin': 0,
'padding': 0,
'::pane': {
'border': 'none'
'border': 'none',
}
},
# default tabber buttons (hidden)
Expand Down Expand Up @@ -542,7 +542,7 @@ def base_path() -> str:
def app_config() -> dict:
config = {
'minimum_window_width': 1280,
'minimum_window_height': 720,
'minimum_window_height': 1016,
'settings_path': r'/.OSCR_settings.ini',
'templog_folder_path': r'/~temp_log_files',
'default_settings': {
Expand Down

0 comments on commit 69a6977

Please sign in to comment.