1
0
Fork 0
mirror of synced 2024-06-26 18:20:50 +12:00

LoadingWidget: Start playing movie once the widget is visible if autostart is enabled

Fixes a subtle bug that would cause increased CPU usage due to spawning
multiple singleshot times with very short timeouts (15ms) until the Store
tab was loaded.
This commit is contained in:
loathingKernel 2024-05-15 22:48:52 +03:00
parent 0c848c41b0
commit 8ebcc3a700
3 changed files with 7 additions and 5 deletions

View file

@ -2,7 +2,7 @@ import os
from logging import getLogger
from PyQt5.QtCore import Qt, QSettings, QTimer, QSize, pyqtSignal, pyqtSlot
from PyQt5.QtGui import QCloseEvent, QCursor, QShowEvent
from PyQt5.QtGui import QCloseEvent, QCursor
from PyQt5.QtWidgets import (
QMainWindow,
QApplication,

View file

@ -111,7 +111,6 @@ class GameWidget(LibraryWidget):
self.startTimer(random.randrange(42, 2361, 129), Qt.CoarseTimer)
# self.startTimer(random.randrange(42, 2361, 363), Qt.VeryCoarseTimer)
# self.rgame.load_pixmap()
# QTimer.singleShot(random.randrange(42, 2361, 7), Qt.VeryCoarseTimer, self.rgame.load_pixmap)
super().paintEvent(a0)
def timerEvent(self, a0):

View file

@ -14,8 +14,7 @@ class LoadingWidget(QLabel):
self.setMovie(self.movie)
if self.parent() is not None:
self.parent().installEventFilter(self)
if autostart:
self.movie.start()
self.autostart = autostart
def __center_on_parent(self):
rect = self.rect()
@ -34,6 +33,9 @@ class LoadingWidget(QLabel):
def showEvent(self, a0: QShowEvent) -> None:
if a0.spontaneous():
return super().showEvent(a0)
if self.autostart:
self.movie.start()
self.autostart = False
self.__center_on_parent()
super().showEvent(a0)
@ -45,7 +47,8 @@ class LoadingWidget(QLabel):
def start(self):
self.setVisible(True)
self.movie.start()
if not self.autostart:
self.movie.start()
def stop(self):
self.setVisible(False)