Skip to content

Commit

Permalink
Merge pull request #61 from Hpero4/main
Browse files Browse the repository at this point in the history
筛选逻辑问题修复
  • Loading branch information
Zzaphkiel authored Sep 18, 2023
2 parents 457abac + 48884f3 commit 6f30574
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions app/view/search_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ def updateTabs(self, begin, n):

def updateGames(self, page):
def _(page, callback=None):
# retry = 0
tmp_games_cnt = len(self.games)
endIndex = self.begIndex + 9
while True:
Expand All @@ -212,27 +211,25 @@ def _(page, callback=None):
self.games = self.games[:10 * self.maxPage]
break

# if retry >= 5:
# self.maxPage = page
# break

self.begIndex = endIndex + 1
endIndex += 10
# retry += 1
if callback:
callback()

# self.gamesInfoReady.emit(page)

if page == 1: # 第一页时加载自身数据, 完成后切换; 并且并发加载下一页数据
threading.Thread(target=_, args=(
page, lambda page: self.gamesInfoReady.emit(page))).start()
def firstPageCallback():
"""
禁用下一页按钮必须在gamesInfoReady信号之后, 所以要另外拿出来做回调
"""
self.gamesInfoReady.emit(page)
self.nextButton.setEnabled(False)
threading.Thread(target=_, args=(page + 1, lambda: self.nextButton.setEnabled(True))).start()

threading.Thread(target=_, args=(page, firstPageCallback)).start()
else: # 除第一页外, 直接切换到该页, 并加载下一页;
self.gamesInfoReady.emit(page)

self.nextButton.setEnabled(False)
threading.Thread(target=_, args=(
page + 1, lambda: self.nextButton.setEnabled(True))).start()
self.nextButton.setEnabled(False)
threading.Thread(target=_, args=(page + 1, lambda: self.nextButton.setEnabled(True))).start()

def __onGamesInfoReady(self, page):
if len(self.games) == 0:
Expand Down Expand Up @@ -953,6 +950,7 @@ def __init__(self, parent=None):

self.filterData = (420, 440, 430, 450) # 默认全选
self.filterTimer = threading.Timer(.5, self.__onSearchButtonClicked)
self.filterOld = None # 条件改动前后若无变化, 则不触发更新逻辑

self.vBoxLayout = QVBoxLayout(self)

Expand Down Expand Up @@ -1048,7 +1046,11 @@ def setEnabled(self, a0: bool) -> None:

return super().setEnabled(a0)

# def clear(self):
def fillterTimerRun(self):
if self.filterOld != self.filterData:
self.__onSearchButtonClicked()

self.filterOld = None

def showFilterFlyout(self):
filterFlyout = FlyoutView("", "")
Expand All @@ -1059,15 +1061,17 @@ def showFilterFlyout(self):
def _():
self.filterTimer.cancel()

if not self.filterOld:
self.filterOld = self.filterData

# 将选中状态同步到 interface
self.filterData = filterBoxGroup.getFilterMode()
self.gamesView.gamesTab.currentIndex = 0

# 消除频繁切换筛选条件带来的抖动
self.filterTimer = threading.Timer(.5,
self.__onSearchButtonClicked)
self.filterTimer = threading.Timer(.7, lambda obj=self: obj.fillterTimerRun())
self.filterTimer.start()
# self.__onSearchButtonClicked()

filterBoxGroup.setCallback(_)

filterFlyout.widgetLayout.addWidget(filterBoxGroup, 0, Qt.AlignCenter)
Expand Down

0 comments on commit 6f30574

Please sign in to comment.