1
1
import sys
2
2
import os
3
+
3
4
try :
4
- from PyQt6 .QtWidgets import QApplication , QProgressBar , QVBoxLayout , QWidget , QPushButton
5
+ from PyQt6 .QtWidgets import (
6
+ QApplication ,
7
+ QProgressBar ,
8
+ QVBoxLayout ,
9
+ QWidget ,
10
+ QPushButton ,
11
+ )
5
12
from PyQt6 .QtCore import Qt , QTimer
6
13
except ImportError :
7
14
os .system ("pip install PyQt6" )
8
- from PyQt6 .QtWidgets import QApplication , QProgressBar , QVBoxLayout , QWidget , QPushButton
15
+ from PyQt6 .QtWidgets import (
16
+ QApplication ,
17
+ QProgressBar ,
18
+ QVBoxLayout ,
19
+ QWidget ,
20
+ QPushButton ,
21
+ )
9
22
from PyQt6 .QtCore import Qt , QTimer
10
23
try :
11
24
import qdarktheme
14
27
import qdarktheme
15
28
from hPyT import rainbow_title_bar
16
29
30
+
17
31
class RainbowProgressBar (QProgressBar ):
18
32
def __init__ (self , * args , interval = int , ** kwargs ):
19
33
super ().__init__ (* args , ** kwargs )
@@ -23,22 +37,27 @@ def __init__(self, *args, interval=int, **kwargs):
23
37
24
38
def update_color (self ):
25
39
# get current title bar color from the rainbow_title_bar
26
- r ,g , b = rainbow_title_bar .get_current_color ()
27
-
40
+ r , g , b = rainbow_title_bar .get_current_color ()
41
+
28
42
# set the current title bar color as the current progressbar color
29
- self .setStyleSheet (f"QProgressBar::chunk {{ background-color: rgb({ r } , { g } , { b } ); }}" )
43
+ self .setStyleSheet (
44
+ f"QProgressBar::chunk {{ background-color: rgb({ r } , { g } , { b } ); }}"
45
+ )
46
+
30
47
31
48
class MainWindow (QWidget ):
32
49
def __init__ (self ):
33
50
super ().__init__ ()
34
51
# initialize the window
35
52
self .setWindowTitle ('"Rainbow ProgressBar" hPyT Sync Example' )
36
53
self .setGeometry (100 , 100 , 600 , 400 )
37
- qdarktheme .setup_theme (theme = "dark" , custom_colors = {"[dark]" : {"primary" : "#FFFFFF" }})
54
+ qdarktheme .setup_theme (
55
+ theme = "dark" , custom_colors = {"[dark]" : {"primary" : "#FFFFFF" }}
56
+ )
57
+
58
+ self .interval = 30 # define the interval for color updates
59
+ window = self .window () # define the window for the rainbow title bar
38
60
39
- self .interval = 30 # define the interval for color updates
40
- window = self .window () # define the window for the rainbow title bar
41
-
42
61
# Start the rainbow title bar effect for the winow
43
62
rainbow_title_bar .start (window , interval = self .interval )
44
63
@@ -47,34 +66,37 @@ def __init__(self):
47
66
self .setLayout (layout )
48
67
49
68
# initialize the custom color changing progress bar class
50
- self .progress_bar = RainbowProgressBar (self , interval = self .interval ) # in order to synchronize the colors make sure the rainbow title bar and your custom color changing widget (here: a progressbar) use the same interval for color updates
69
+ self .progress_bar = RainbowProgressBar (
70
+ self , interval = self .interval
71
+ ) # in order to synchronize the colors make sure the rainbow title bar and your custom color changing widget (here: a progressbar) use the same interval for color updates
51
72
self .progress_bar .setGeometry (50 , 50 , 500 , 50 )
52
73
self .progress_bar .setRange (0 , 100 )
53
-
74
+
54
75
# create a button which starts a progress simulation for the progressbar
55
76
self .start_button = QPushButton ("start" )
56
77
self .start_button .clicked .connect (self .start_progress_simulation )
57
-
78
+
58
79
# define the layout
59
80
layout .addStretch ()
60
81
layout .addWidget (self .progress_bar , alignment = Qt .AlignmentFlag .AlignVCenter )
61
82
layout .addWidget (self .start_button , alignment = Qt .AlignmentFlag .AlignVCenter )
62
83
layout .addStretch ()
63
-
84
+
64
85
# initialize a timer for the progressbar-progress simulation
65
86
self .progress_timer = QTimer ()
66
87
self .progress_timer .timeout .connect (self .progress_simulation )
67
-
88
+
68
89
def start_progress_simulation (self ):
69
90
self .pb_value = 0
70
91
progress_update_interval = 500
71
-
92
+
72
93
self .progress_timer .start (progress_update_interval )
73
-
94
+
74
95
def progress_simulation (self ):
75
96
self .pb_value += 5
76
97
self .progress_bar .setValue (self .pb_value )
77
-
98
+
99
+
78
100
if __name__ == "__main__" :
79
101
app = QApplication (sys .argv )
80
102
window = MainWindow ()
0 commit comments