Skip to content

Commit

Permalink
修复生涯界面最近队友飞出组件的内存泄漏问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzaphkiel committed Jun 15, 2024
1 parent bea31d8 commit 95dec93
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions app/view/career_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, parent=None):
self.currentSummonerName = None
self.puuid = None
self.showTagLine = False
self.recentTeammatesInfo = None

self.vBoxLayout = QVBoxLayout(self)
self.IconNameHBoxLayout = QHBoxLayout()
Expand Down Expand Up @@ -80,8 +81,8 @@ def __init__(self, parent=None):
self.kdaLabel = QLabel(self.tr("KDA:") + " None / None / None")
self.championsCard = ChampionsCard()
self.recentTeamButton = PushButton(self.tr("Recent teammates"))
self.teammatesFlyout = TeammatesFlyOut()
self.filterComboBox = ComboBox()
self.recentTeammatesFlyout: Flyout = None

self.gameInfoAreaLayout = QHBoxLayout()
self.gameInfoArea = SmoothScrollArea()
Expand Down Expand Up @@ -382,6 +383,10 @@ async def updateInterface(self, puuid=None, summoner=None):
assert summoner or puuid

self.setLoadingPageEnabled(True)
self.recentTeammatesInfo = None
if self.recentTeammatesFlyout:
self.recentTeammatesFlyout.close()
self.recentTeammatesFlyout = None

if summoner is None:
summoner = await connector.getSummonerByPuuid(puuid)
Expand Down Expand Up @@ -477,7 +482,6 @@ async def repaintInterface(self, info):
self.__updateGameInfo()

self.backToMeButton.setEnabled(not self.isCurrentSummoner())
self.teammatesFlyout.updatePuuid(puuid)

if 'champions' in info:
self.championsCard.updateChampions(info['champions'])
Expand Down Expand Up @@ -560,18 +564,20 @@ def isCurrentSummoner(self):
return self.currentSummonerName == None or self.currentSummonerName == self.name.text()

def __onRecentTeammatesButtonClicked(self):
self.w = Flyout.make(
self.teammatesFlyout, self.recentTeamButton, self,
aniType=FlyoutAnimationType.DROP_DOWN, isDeleteOnClose=False)
view = TeammatesFlyOut()
if self.info:
view.setLoadingPageEnabled(False)
view.updateSummoners(self.info)

async def __updateRecentTeammates(self):
self.teammatesFlyout.setLoadingPageEnabled(True)
self.recentTeammatesFlyout = Flyout.make(
view, self.recentTeamButton, self, FlyoutAnimationType.DROP_DOWN)

info = await getRecentTeammates(
self.games['games'], self.puuid)
async def __updateRecentTeammates(self):
self.info = await getRecentTeammates(self.games['games'], self.puuid)

self.teammatesFlyout.updateSummoners(info)
self.teammatesFlyout.setLoadingPageEnabled(False)
if self.recentTeammatesFlyout:
self.recentTeammatesFlyout.close()
self.__onRecentTeammatesButtonClicked()


class TeammatesFlyOut(FlyoutViewBase):
Expand Down Expand Up @@ -604,9 +610,6 @@ def __initLayout(self):
self.stackedWidget.setFixedHeight(352)
self.stackedWidget.setFixedWidth(490)

def updatePuuid(self, puuid):
self.puuid = puuid

def clear(self):
for i in reversed(range(self.infopageVBoxLayout.count())):
item = self.infopageVBoxLayout.itemAt(i)
Expand All @@ -616,11 +619,6 @@ def clear(self):
item.widget().deleteLater()

def updateSummoners(self, info):
if self.puuid != info['puuid']:
return

self.clear()

for summoner in info['summoners']:
infoBar = TeammateInfoBar(summoner)
self.infopageVBoxLayout.addWidget(infoBar)
Expand Down

0 comments on commit 95dec93

Please sign in to comment.