Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yjg30737/pyqt-translucent-full-loading-screen-thread
PyQt thread which overlays the translucent loading screen with label on the whole window like some generic application loading screen.
https://github.com/yjg30737/pyqt-translucent-full-loading-screen-thread
pyqt pyqt-examples pyqt-loading pyqt-loading-screen pyqt5 pyqt5-examples pyqt5-tutorial python python3 python37 qlabel qmovie qt qt-loading-screen qthread qtimer
Last synced: 13 days ago
JSON representation
PyQt thread which overlays the translucent loading screen with label on the whole window like some generic application loading screen.
- Host: GitHub
- URL: https://github.com/yjg30737/pyqt-translucent-full-loading-screen-thread
- Owner: yjg30737
- License: mit
- Created: 2022-02-03T03:50:33.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-04T05:03:05.000Z (almost 3 years ago)
- Last Synced: 2023-03-04T22:18:00.373Z (over 1 year ago)
- Topics: pyqt, pyqt-examples, pyqt-loading, pyqt-loading-screen, pyqt5, pyqt5-examples, pyqt5-tutorial, python, python3, python37, qlabel, qmovie, qt, qt-loading-screen, qthread, qtimer
- Language: Python
- Homepage:
- Size: 92.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pyqt-translucent-full-loading-screen-thread
PyQt thread which overlays the translucent loading screen with label on the whole window like some generic application loading screen.## Requirements
PyQt5 >= 5.8## Setup
```pip3 install git+https://github.com/yjg30737/pyqt-translucent-full-loading-screen-thread.git --upgrade```## Usage
This package mainly consists of two classes. ```LoadingTranslucentScreen(parent: QWidget, description_text: str = '', dot_animation: bool = True)``` and ```LoadingThread(loading_screen: LoadingTranslucentScreen)```. I can show you how it works basically.
```python
self.loadingTranslucentScreen = LoadingTranslucentScreen(parent=self,
description_text='Waiting...', dot_animation=False)
self.thread = LoadingThread(loading_screen=self.loadingTranslucentScreen)
self.thread.start()
```Just give the parent widget to ```LoadingTranslucentScreen``` as a first argument.
Second argument is description text of ```QLabel``` which will be shown with loading icon(loading icon is .gif extension, ```QMovie``` will get the gif loading icon) when you start the ```LoadingThread```. 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 of ```LoadingTranslucentScreen``` to ```LoadingThread```'s argument and call the start method of it.
Default ```run()``` task of this thread is ```time.sleep(5)```.
You can inherit this module and override run method.
You can use ```setDescriptionLabelDirection(direction: str)``` method of ```LoadingTranslucentScreen``` 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 is ```Left```, ```Right```, ```Top```, ```Bottom```. All of them should be ```str``` type.
Default direction is ```Bottom```.
I show you how to use the method ```setDescriptionLabelDirection```.
```python
self.loadingTranslucentScreen.setDescriptionLabelDirection('Right')
```
If you set the description label direction right like the example above, description text will be shown on the right side of the loading icon.If you want to show loading icon only, make instance like this.
```python
self.__loadingTranslucentScreen = LoadingTranslucentScreen(parent=self, dot_animation=False)
```## Example
### Code Sample
```python
import time
from PyQt5.QtWidgets import QPushButton, QTextEdit, QVBoxLayout, QWidget, QApplicationfrom pyqt_translucent_full_loading_screen_thread import LoadingThread, LoadingTranslucentScreen
# for second result
class MyThread(LoadingThread):def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)def run(self):
time.sleep(1)class Main(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__':
import sysapp = QApplication(sys.argv)
window = Main()
window.show()
app.exec()
```### Result
#### 1. Result of ```LoadingThread``` which is module itself
https://user-images.githubusercontent.com/55078043/152469234-50e72870-e0c4-4b6a-a364-3a28fd23c501.mp4
Loading screen is shown for 5 seconds.
#### 2. Result of ```MyThread``` which inherits the ```LoadingThread```
https://user-images.githubusercontent.com/55078043/152469243-3044ff32-afe5-4e35-8c61-7b9003e30bf4.mp4
Loading screen is shown for 1 second. Because ```run()``` method of ```MyThread``` overrides ```LoadingThread```'s.