You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This package mainly consists of two classes.LoadingTranslucentScreen(parent: QWidget, description_text: str = '', dot_animation: bool = True) andLoadingThread(loading_screen: LoadingTranslucentScreen). I can show you how it works basically.
Just give the parent widget toLoadingTranslucentScreen as afirst argument.
Second argument is description text ofQLabel which will be shown with loading icon(loading icon is .gif extension,QMovie will get the gif loading icon) when you start theLoadingThread. Defaut value is empty string.
Third argument(dot_animation) decides if triple dots animation of description text will operate or not. There is an explanation of triple dots animation feature below. Default value is True.
Give instant ofLoadingTranslucentScreen toLoadingThread's argument and call the start method of it.
Defaultrun() task of this thread istime.sleep(5).
You can inherit this module and override run method.
You can usesetDescriptionLabelDirection(direction: str) method ofLoadingTranslucentScreen to set the direction of description label.
If thread starts running, dot animation will be activated. If the description text is 'Waiting', dot animation will be like below.
Waiting.Waiting..Waiting...
Of course this feature can reveal a couple of potential flaws if any dots are included in description text. I will fix that soon enough.
Valid argument isLeft,Right,Top,Bottom. All of them should bestr type.
Default direction isBottom.
I show you how to use the methodsetDescriptionLabelDirection.
importtimefromPyQt5.QtWidgetsimportQPushButton,QTextEdit,QVBoxLayout,QWidget,QApplicationfrompyqt_translucent_full_loading_screen_threadimportLoadingThread,LoadingTranslucentScreen# for second resultclassMyThread(LoadingThread):def__init__(self,*args,**kwargs):super().__init__(*args,**kwargs)defrun(self):time.sleep(1)classMain(QWidget):def__init__(self):super().__init__()self.__initUi()def__initUi(self):btn=QPushButton('Start Loading Thread')btn.clicked.connect(self.__startLoadingThread)self.__te=QTextEdit()lay=QVBoxLayout()lay.addWidget(btn)lay.addWidget(self.__te)self.setLayout(lay)def__startLoadingThread(self):self.__loadingTranslucentScreen=LoadingTranslucentScreen(parent=self,description_text='Waiting')self.__loadingTranslucentScreen.setDescriptionLabelDirection('Right')self.__thread=LoadingThread(loading_screen=self.__loadingTranslucentScreen)# for second result# self.__thread = MyThread(loading_screen=self.__loadingTranslucentScreen)self.__thread.start()if__name__=='__main__':importsysapp=QApplication(sys.argv)window=Main()window.show()app.exec()
Result
1. Result ofLoadingThread which is module itself
example1.mp4
Loading screen is shown for 5 seconds.
2. Result ofMyThread which inherits theLoadingThread
example2.mp4
Loading screen is shown for 1 second. Becauserun() method ofMyThread overridesLoadingThread's.
About
PyQt thread which overlays the translucent loading screen with label on the whole window like some generic application loading screen.