From feec03b4ded0225aa46bd1a5f03d561d3e49ad13 Mon Sep 17 00:00:00 2001 From: Hpero4 Date: Mon, 18 Sep 2023 23:48:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E9=97=AA=E9=80=80?= =?UTF-8?q?=E9=97=AE=E9=A2=98=202.=20=E4=BC=98=E5=8C=96=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/view/search_interface.py | 38 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/app/view/search_interface.py b/app/view/search_interface.py index 54e6ed72..ba3e60f3 100644 --- a/app/view/search_interface.py +++ b/app/view/search_interface.py @@ -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: @@ -212,26 +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: @@ -952,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) @@ -1043,7 +1042,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("", "") @@ -1054,14 +1057,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) From a8879427db381adcb32b90440f4de090bc52a6d8 Mon Sep 17 00:00:00 2001 From: Hpero4 Date: Mon, 18 Sep 2023 23:48:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E9=97=AA=E9=80=80?= =?UTF-8?q?=E9=97=AE=E9=A2=98=202.=20=E4=BC=98=E5=8C=96=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/view/search_interface.py | 40 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/app/view/search_interface.py b/app/view/search_interface.py index 2764c871..933a088a 100644 --- a/app/view/search_interface.py +++ b/app/view/search_interface.py @@ -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: @@ -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: @@ -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) @@ -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("", "") @@ -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)