diff --git a/app/common/util.py b/app/common/util.py index 960e357e..647e4730 100644 --- a/app/common/util.py +++ b/app/common/util.py @@ -25,4 +25,5 @@ def checkUpdate(self): return info return None + github = Github() diff --git a/app/components/search_line_edit.py b/app/components/search_line_edit.py index 6ea29a75..df881c30 100644 --- a/app/components/search_line_edit.py +++ b/app/components/search_line_edit.py @@ -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 diff --git a/app/lol/connector.py b/app/lol/connector.py index 47b250a0..c2e05e9a 100644 --- a/app/lol/connector.py +++ b/app/lol/connector.py @@ -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 @@ -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: @@ -72,7 +65,6 @@ def __init__(self): self.url = None self.tackleFlag = threading.Event() - self.slowlyFlag = threading.Event() self.manager = None self.timeoutApi = None diff --git a/app/view/career_interface.py b/app/view/career_interface.py index a8a09ce0..00baab79 100644 --- a/app/view/career_interface.py +++ b/app/view/career_interface.py @@ -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']) diff --git a/app/view/main_window.py b/app/view/main_window.py index f10573f6..33f887e5 100644 --- a/app/view/main_window.py +++ b/app/view/main_window.py @@ -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 @@ -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): @@ -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() @@ -957,7 +974,7 @@ def _(callback=None): queueId = data['queue']['id'] # 特判一下斗魂竞技场 - if queueId == 1700: + if queueId in (1700, 1090, 1100): # 斗魂 云顶匹配(排位) return team1 = data['teamOne'] diff --git a/app/view/search_interface.py b/app/view/search_interface.py index b2315bb4..a360cf13 100644 --- a/app/view/search_interface.py +++ b/app/view/search_interface.py @@ -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 @@ -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): @@ -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) @@ -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() @@ -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) @@ -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) @@ -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() @@ -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"]: @@ -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) @@ -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()