Skip to content

Commit

Permalink
Merge pull request #86 from Hpero4/main
Browse files Browse the repository at this point in the history
BUG 修复 优化 功能实现 等
  • Loading branch information
Zzaphkiel authored Sep 29, 2023
2 parents f9bf62e + 786646f commit f099706
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 128 deletions.
60 changes: 56 additions & 4 deletions app/components/search_line_edit.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
from PyQt5.QtCore import Qt, QEvent, QAbstractItemModel
from PyQt5.QtWidgets import QCompleter, QAction
from PyQt5.QtCore import Qt, QEvent, QAbstractItemModel, pyqtSignal, QSize
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QCompleter, QAction, QWidget, QHBoxLayout, QListWidgetItem, QPushButton
from PyQt5.uic.properties import QtCore, QtGui
from qfluentwidgets import SearchLineEdit as QSearchLineEdit
from qfluentwidgets.components.widgets.line_edit import CompleterMenu
from qfluentwidgets import SearchLineEdit as QSearchLineEdit, PushButton, Icon, FluentIcon, TransparentToolButton, Theme
from qfluentwidgets.components.widgets.line_edit import CompleterMenu, LineEditButton

from app.common.config import cfg


class MyItemWidget(QWidget):
clicked = pyqtSignal(str)

def __init__(self, text, parent=None):
super().__init__(parent)
self.text = text

def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.clicked.emit(self.text)
event.ignore()


class MyCompleterMenu(CompleterMenu):

def __onDelBtnClicked(self, action):
historyList = cfg.get(cfg.searchHistory).split(",")
historyList.remove(action.text())
self.close()
cfg.set(cfg.searchHistory, ",".join(historyList))
self.lineEdit.refreshCompleter()

def addAction(self, action: QAction):
""" add action to menu
Parameters
----------
action: QAction
menu action
"""
item: QListWidgetItem = self._createActionItem(action)

text = action.text()
hLayout = QHBoxLayout()
hLayout.setAlignment(Qt.AlignRight)
hLayout.setContentsMargins(0, 0, 0, 0)
delBtn = LineEditButton(FluentIcon.CLOSE, self)
delBtn.setFixedSize(self.itemHeight - 7, self.itemHeight - 7)
delBtn.setIconSize(QSize(self.itemHeight - 23, self.itemHeight - 23))
delBtn.clicked.connect(lambda _, x=action: self.__onDelBtnClicked(x))
hLayout.addWidget(delBtn)

w = MyItemWidget(text)
w.clicked.connect(self.__onItemSelected)
w.setLayout(hLayout)
self.view.addItem(item)
self.view.setItemWidget(item, w)
self.adjustSize()

def eventFilter(self, obj, e):
if e.type() != QEvent.KeyPress:
return super().eventFilter(obj, e)
Expand Down Expand Up @@ -49,6 +97,7 @@ def setCompletion(self, model: QAbstractItemModel):
def __onItemSelected(self, text):
self.lineEdit.setText(text)
self.activated.emit(text)
self.close()
self.lineEdit.searchButton.click()


Expand All @@ -63,6 +112,9 @@ def __init__(self, parent=None):
completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
self.setCompleter(completer)

def refreshCompleter(self):
self._showCompleterMenu()

def _showCompleterMenu(self):
if not self.completer():
return
Expand Down
44 changes: 39 additions & 5 deletions app/lol/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def wrapper(*args, **kwargs):
return decorator


def retry(count=5, retry_sep=0.5):
def retry(count=5, retry_sep=0):
def decorator(func):
def wrapper(*args, **kwargs):
exce = None
Expand All @@ -55,10 +55,12 @@ def wrapper(*args, **kwargs):
connector.ref_cnt -= 1
break
else:
# 有异常抛异常, 没异常抛 RetryMaximumAttempts
exce = exce if exce else RetryMaximumAttempts("Exceeded maximum retry attempts.")
connector.ref_cnt -= 1
connector.timeoutApi = func.__name__
connector.exceptApi = func.__name__
connector.exceptObj = exce
raise exce
# raise Exception("Exceeded maximum retry attempts.")

return res

Expand All @@ -79,7 +81,8 @@ def __init__(self):
self.tackleFlag = threading.Event()
self.manager = None

self.timeoutApi = None
self.exceptApi = None
self.exceptObj = None

def start(self, pid):
process = psutil.Process(pid)
Expand Down Expand Up @@ -227,6 +230,7 @@ def getChampionIcon(self, championId) -> str:

return icon

@retry()
def getSummonerByName(self, name):
params = {"name": name}
res = self.__get(f"/lol-summoner/v1/summoners", params).json()
Expand All @@ -246,8 +250,22 @@ def getSummonerByPuuid(self, puuid):
return res

@slowly()
@retry(10, 1)
@retry(5, 1)
def getSummonerGamesByPuuidSlowly(self, puuid, begIndex=0, endIndex=4):
"""
Retrieves a list of summoner games by puuid using a slow and retry mechanism.
Parameters:
puuid (str): The puuid of the summoner.
begIndex (int): The beginning index of the games to retrieve. Default is 0.
endIndex (int): The ending index of the games to retrieve. Default is 4.
Returns:
list: A list of summoner games.
Raises:
SummonerGamesNotFound: If the summoner games are not found.
"""
params = {"begIndex": begIndex, "endIndex": endIndex}
res = self.__get(
f"/lol-match-history/v1/products/lol/{puuid}/matches", params
Expand All @@ -261,6 +279,20 @@ def getSummonerGamesByPuuidSlowly(self, puuid, begIndex=0, endIndex=4):
@tackle()
@retry()
def getSummonerGamesByPuuid(self, puuid, begIndex=0, endIndex=4):
"""
Retrieves a list of summoner games by PUUID.
Args:
puuid (str): The PUUID of the summoner.
begIndex (int, optional): The starting index of the games to retrieve. Defaults to 0.
endIndex (int, optional): The ending index of the games to retrieve. Defaults to 4.
Returns:
list: A list of summoner games.
Raises:
SummonerGamesNotFound: If the summoner games are not found.
"""
params = {"begIndex": begIndex, "endIndex": endIndex}
res = self.__get(
f"/lol-match-history/v1/products/lol/{puuid}/matches", params
Expand All @@ -271,12 +303,14 @@ def getSummonerGamesByPuuid(self, puuid, begIndex=0, endIndex=4):

return res["games"]

@tackle()
@retry()
def getGameDetailByGameId(self, gameId):
res = self.__get(f"/lol-match-history/v1/games/{gameId}").json()

return res

@tackle()
@retry()
def getRankedStatsByPuuid(self, puuid):
res = self.__get(f"/lol-ranked/v1/ranked-stats/{puuid}").json()
Expand Down
4 changes: 4 additions & 0 deletions app/lol/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ class SummonerGamesNotFound(BaseException):

class SummonerNotInGame(BaseException):
pass


class RetryMaximumAttempts(BaseException):
pass
42 changes: 21 additions & 21 deletions app/lol/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,33 +288,33 @@ def processGameDetailData(puuid, game):

getRankInfo = cfg.get(cfg.showTierInGameInfo)

tier, division, lp, rankIcon = None, None, None, None
if getRankInfo:
rank = connector.getRankedStatsByPuuid(
summonerPuuid)['queueMap']
summonerPuuid).get('queueMap')

if queueId != 1700:
rankInfo = rank[
'RANKED_FLEX_SR'] if queueId == 440 else rank[
'RANKED_SOLO_5x5']
try:
if queueId != 1700 and rank:
rankInfo = rank[
'RANKED_FLEX_SR'] if queueId == 440 else rank['RANKED_SOLO_5x5']

tier: str = rankInfo['tier']
division = rankInfo['division']
lp = rankInfo['leaguePoints']
tier = rankInfo['tier']
division = rankInfo['division']
lp = rankInfo['leaguePoints']

if tier == '':
rankIcon = 'app/resource/images/unranked.png'
if tier == '':
rankIcon = 'app/resource/images/unranked.png'
else:
rankIcon = f'app/resource/images/{tier.lower()}.png'
tier = translateTier(tier, True)

if division == 'NA':
division = ''
else:
rankIcon = f'app/resource/images/{tier.lower()}.png'
tier = translateTier(tier, True)

if division == 'NA':
division = ''
else:
rankInfo = rank["CHERRY"]
lp = rankInfo['ratedRating']
tier, division, rankIcon = None, None, None
else:
tier, division, lp, rankIcon = None, None, None, None
rankInfo = rank["CHERRY"]
lp = rankInfo['ratedRating']
except KeyError:
...

item = {
'summonerName': summonerName,
Expand Down
1 change: 1 addition & 0 deletions app/view/game_info_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __onGameEnd(self):
self.allySummonerGamesView.clear()
self.enemySummonerGamesView.clear()

self.summonersView.allyButton.click()
self.summonersView.allyButton.setVisible(False)
self.summonersView.enemyButton.setVisible(False)

Expand Down
Loading

0 comments on commit f099706

Please sign in to comment.