Skip to content

Commit

Permalink
Merge pull request #76 from Hpero4/main
Browse files Browse the repository at this point in the history
BUG修复
  • Loading branch information
Zzaphkiel authored Sep 24, 2023
2 parents 4aa1e10 + 5c482cd commit aa31537
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 100 deletions.
1 change: 1 addition & 0 deletions app/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ def checkUpdate(self):
return info
return None


github = Github()
4 changes: 3 additions & 1 deletion app/components/search_line_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ def eventFilter(self, obj, e):
if e.key() == Qt.Key_Escape:
self.close()
if e.key() in [Qt.Key_Enter, Qt.Key_Return]:
if self.isVisible():
self.close()

self.lineEdit.searchButton.click()
self.close()

return True

Expand Down
10 changes: 1 addition & 9 deletions app/lol/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def wrapper(*args, **kwargs):
while connector.tackleFlag.is_set():
time.sleep(.2)

connector.slowlyFlag.set()
res = func(*args, **kwargs)
connector.slowlyFlag.clear()
return res
return wrapper
return decorator
Expand All @@ -42,13 +40,8 @@ def decorator(func):
def wrapper(*args, **kwargs):
for _ in range(count):
try:
# 低优先级请求未结束时, 避免server队列过长
# 若负载过高导致请求失败, 则在触发 retry 间隙为高优先级请求让行
while connector.slowlyFlag.is_set():
time.sleep(.2)

res = func(*args, **kwargs)
except:
except Exception as e:
time.sleep(retry_sep)
continue
else:
Expand All @@ -72,7 +65,6 @@ def __init__(self):
self.url = None

self.tackleFlag = threading.Event()
self.slowlyFlag = threading.Event()
self.manager = None

self.timeoutApi = None
Expand Down
4 changes: 3 additions & 1 deletion app/view/career_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,9 @@ def __onCareerInfoChanged(self, info: dict):
self.backToMeButton.setEnabled(not self.isCurrentSummoner())

self.teammatesFlyout.updatePuuid(puuid)
self.updateRecentTeammates()

if self.games:
self.updateRecentTeammates()

if 'champions' in info:
self.championsCard.updateChampions(info['champions'])
Expand Down
171 changes: 94 additions & 77 deletions app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from ..common.config import cfg, VERSION
from ..components.update_message_box import UpdateMessageBox
from ..lol.entries import Summoner
from ..lol.exceptions import SummonerGamesNotFound
from ..lol.listener import (LolProcessExistenceListener, LolClientEventListener,
getLolProcessPid)
from ..lol.connector import connector
Expand Down Expand Up @@ -311,49 +312,57 @@ def __changeCareerToCurrentSummoner(self):

rankInfo = connector.getRankedStatsByPuuid(
self.currentSummoner.puuid)
gamesInfo = connector.getSummonerGamesByPuuid(
self.currentSummoner.puuid, 0, cfg.get(cfg.careerGamesNumber) - 1)

games = {
"gameCount": gamesInfo["gameCount"],
"wins": 0,
"losses": 0,
"kills": 0,
"deaths": 0,
"assists": 0,
"games": [],
}

for game in gamesInfo["games"]:
info = processGameData(game)
if not info["remake"] and info["queueId"] != 0:
games["kills"] += info["kills"]
games["deaths"] += info["deaths"]
games["assists"] += info["assists"]
try:
gamesInfo = connector.getSummonerGamesByPuuid(
self.currentSummoner.puuid, 0, cfg.get(cfg.careerGamesNumber) - 1)
except SummonerGamesNotFound:
champions = []
games = {}
else:
games = {
"gameCount": gamesInfo["gameCount"],
"wins": 0,
"losses": 0,
"kills": 0,
"deaths": 0,
"assists": 0,
"games": [],
}

for game in gamesInfo["games"]:
info = processGameData(game)
if not info["remake"] and info["queueId"] != 0:
games["kills"] += info["kills"]
games["deaths"] += info["deaths"]
games["assists"] += info["assists"]

if info["win"]:
games["wins"] += 1
else:
games["losses"] += 1

if info["win"]:
games["wins"] += 1
else:
games["losses"] += 1
games["games"].append(info)

games["games"].append(info)
champions = getRecentChampions(games['games'])

self.nameOrIconChanged.emit(icon, name)
emitInfo = {
'name': name,
'icon': icon,
'level': level,
'xpSinceLastLevel': xpSinceLastLevel,
'xpUntilNextLevel': xpUntilNextLevel,
'puuid': self.currentSummoner.puuid,
'rankInfo': rankInfo,
'games': games,
'champions': champions,
'triggerByUser': True,
}
if champions:
emitInfo["champions"] = champions

champions = getRecentChampions(games['games'])

self.careerInterface.careerInfoChanged.emit(
{'name': name,
'icon': icon,
'level': level,
'xpSinceLastLevel': xpSinceLastLevel,
'xpUntilNextLevel': xpUntilNextLevel,
'puuid': self.currentSummoner.puuid,
'rankInfo': rankInfo,
'games': games,
'champions': champions,
'triggerByUser': True, }
)
self.careerInterface.careerInfoChanged.emit(emitInfo)
self.careerInterface.hideLoadingPage.emit()

def __onLolClientStarted(self, pid):
Expand Down Expand Up @@ -575,48 +584,56 @@ def _():
xpUntilNextLevel = summoner.xpUntilNextLevel

rankInfo = connector.getRankedStatsByPuuid(summoner.puuid)
gamesInfo = connector.getSummonerGamesByPuuid(
summoner.puuid, 0, cfg.get(cfg.careerGamesNumber) - 1)

games = {
"gameCount": gamesInfo["gameCount"],
"wins": 0,
"losses": 0,
"kills": 0,
"deaths": 0,
"assists": 0,
"games": [],
}

for game in gamesInfo["games"]:
info = processGameData(game)

if not info["remake"] and info["queueId"] != 0:
games["kills"] += info["kills"]
games["deaths"] += info["deaths"]
games["assists"] += info["assists"]

if info["win"]:
games["wins"] += 1
else:
games["losses"] += 1

games["games"].append(info)
try:
gamesInfo = connector.getSummonerGamesByPuuid(
summoner.puuid, 0, cfg.get(cfg.careerGamesNumber) - 1)
except SummonerGamesNotFound:
champions = []
games = {}
else:
games = {
"gameCount": gamesInfo["gameCount"],
"wins": 0,
"losses": 0,
"kills": 0,
"deaths": 0,
"assists": 0,
"games": [],
}

champions = getRecentChampions(games['games'])
for game in gamesInfo["games"]:
info = processGameData(game)

if not info["remake"] and info["queueId"] != 0:
games["kills"] += info["kills"]
games["deaths"] += info["deaths"]
games["assists"] += info["assists"]

if info["win"]:
games["wins"] += 1
else:
games["losses"] += 1

games["games"].append(info)

champions = getRecentChampions(games['games'])

emitInfo = {
'name': name,
'icon': icon,
'level': level,
'xpSinceLastLevel': xpSinceLastLevel,
'xpUntilNextLevel': xpUntilNextLevel,
'puuid': summoner.puuid,
'rankInfo': rankInfo,
'games': games,
'triggerByUser': True,
}
if champions:
emitInfo["champions"] = champions

self.careerInterface.careerInfoChanged.emit(
{'name': name,
'icon': icon,
'level': level,
'xpSinceLastLevel': xpSinceLastLevel,
'xpUntilNextLevel': xpUntilNextLevel,
'puuid': summoner.puuid,
'rankInfo': rankInfo,
'games': games,
'champions': champions,
'triggerByUser': True, }
)
self.careerInterface.careerInfoChanged.emit(emitInfo)
self.careerInterface.hideLoadingPage.emit()

threading.Thread(target=_).start()
Expand Down Expand Up @@ -957,7 +974,7 @@ def _(callback=None):
queueId = data['queue']['id']
# 特判一下斗魂竞技场

if queueId == 1700:
if queueId in (1700, 1090, 1100): # 斗魂 云顶匹配(排位)
return

team1 = data['teamOne']
Expand Down
38 changes: 26 additions & 12 deletions app/view/search_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ..components.search_line_edit import SearchLineEdit
from ..components.summoner_name_button import SummonerName
from ..lol.connector import LolClientConnector, connector
from ..lol.exceptions import SummonerGamesNotFound
from ..lol.tools import processGameData, processGameDetailData


Expand Down Expand Up @@ -95,8 +96,10 @@ def __onLoadFinish(self):
self.tr('Data loading completed!') + ' 😆')
self.stateTooltip.setState(True)
self.stateTooltip = None
self.nextButton.setEnabled(True)
self.__onNextButtonClicked()

if self.window().searchInterface.games: # 避免召唤师一年都没打游戏, 查了个空
self.nextButton.setEnabled(True)
self.__onNextButtonClicked()

def __onTabClicked(self, gameId):

Expand Down Expand Up @@ -987,6 +990,7 @@ def mouseReleaseEvent(self, a0) -> None:

class SearchInterface(SmoothScrollArea):
summonerPuuidGetted = pyqtSignal(str)
gamesNotFound = pyqtSignal()

def __init__(self, parent=None):
super().__init__(parent)
Expand All @@ -1000,9 +1004,7 @@ def __init__(self, parent=None):
self.vBoxLayout = QVBoxLayout(self)

self.searchLayout = QHBoxLayout()
# self.searchLineEdit = LineEdit()
self.searchLineEdit = SearchLineEdit()
# self.searchButton = PushButton(self.tr("Search 🔍"))
self.careerButton = PushButton(self.tr("Career"))
self.filterComboBox = ComboBox()

Expand All @@ -1021,11 +1023,7 @@ def __initWidget(self):
self.careerButton.setEnabled(False)
self.filterComboBox.setEnabled(False)

# self.searchLineEdit.searchButton.setShortcut("Return")
# self.searchLineEdit.searchButton.setShortcut("Key_Enter")
# self.searchLineEdit.searchButton.setShortcut(Qt.Key_Return)
self.searchLineEdit.searchButton.setShortcut(Qt.Key_Enter)
# self.searchButton.setShortcut("Return")

StyleSheet.SEARCH_INTERFACE.apply(self)

Expand All @@ -1042,7 +1040,6 @@ def __initWidget(self):
def __initLayout(self):
self.searchLayout.addWidget(self.searchLineEdit)
self.searchLayout.addSpacing(5)
# self.searchLayout.addWidget(self.searchButton)
self.searchLayout.addWidget(self.careerButton)
self.searchLayout.addWidget(self.filterComboBox)

Expand All @@ -1062,7 +1059,7 @@ def __onSearchButtonClicked(self):
if targetName in history:
history.remove(targetName)
history.insert(0, targetName)
cfg.set(cfg.searchHistory, ",".join([t for t in history if t])[:10], True) # 过滤空值, 只存十个
cfg.set(cfg.searchHistory, ",".join([t for t in history if t][:10]), True) # 过滤空值, 只存十个

if self.loadGamesThread and self.loadGamesThread.is_alive():
self.loadGamesThreadStop.set()
Expand Down Expand Up @@ -1096,10 +1093,15 @@ def loadGames(self, puuid):
begIdx = 0
endIdx = begIdx + 9
while True:
games = connector.getSummonerGamesByPuuidSlowly(
puuid, begIdx, endIdx)
try:
games = connector.getSummonerGamesByPuuidSlowly(
puuid, begIdx, endIdx)
except SummonerGamesNotFound:
self.gamesNotFound.emit()
return

if not games["games"]: # 所有对局都在一年内, 查完了
self.gamesNotFound.emit()
return

for game in games["games"]:
Expand Down Expand Up @@ -1137,6 +1139,7 @@ def __connectSignalToSlot(self):
self.searchLineEdit.searchButton.clicked.connect(self.__onSearchButtonClicked)
# self.searchButton.clicked.connect(self.__onSearchButtonClicked)
self.summonerPuuidGetted.connect(self.__onSummonerPuuidGetted)
self.gamesNotFound.connect(self.__onShowGamesNotFoundMessage)
self.filterComboBox.currentIndexChanged.connect(
self.__onFilterComboBoxChanged)

Expand All @@ -1155,6 +1158,17 @@ def __showSummonerNotFoundMessage(self):
parent=self,
)

def __onShowGamesNotFoundMessage(self):
InfoBar.error(
title=self.tr("Games not found"),
content=self.tr("No matches were found for this summoner"),
orient=Qt.Vertical,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=5000,
parent=self,
)

def setEnabled(self, a0: bool) -> None:
self.gamesView.gamesTab.backToDefaultPage()
self.gamesView.gameDetailView.clear()
Expand Down

0 comments on commit aa31537

Please sign in to comment.