1+ import sys
2+ from PySide2 .QtCore import QBasicTimer
3+ from PySide2 .QtWidgets import QApplication , QWidget , QPushButton , QHBoxLayout
4+ from PySide2 .QtWinExtras import QWinTaskbarButton
5+ class Form (QWidget ):
6+ def __init__ (self ):
7+ super ().__init__ ()
8+ self .initUI ()
9+ def initUI (self ):
10+ self .resize (500 , 300 )
11+ self .setWindowTitle ("Windows Taskbar ProgressBar" )
12+ self .start_stop_button = QPushButton ("Start" )
13+ self .start_stop_button .resize (self .start_stop_button .sizeHint ())
14+ self .start_stop_button .clicked .connect (self .start_stop )
15+ self .pause_button = QPushButton ("Pause" )
16+ self .pause_button .resize (self .pause_button .sizeHint ())
17+ self .pause_button .clicked .connect (self .pause )
18+ self .stop_button = QPushButton ("Stop" )
19+ self .stop_button .resize (self .stop_button .sizeHint ())
20+ self .stop_button .clicked .connect (self .stop )
21+ self .reset_button = QPushButton ("Reset" )
22+ self .reset_button .resize (self .reset_button .sizeHint ())
23+ self .reset_button .clicked .connect (self .reset )
24+ self .hbox = QHBoxLayout ()
25+ self .hbox .addWidget (self .start_stop_button )
26+ self .hbox .addWidget (self .pause_button )
27+ self .hbox .addWidget (self .stop_button )
28+ self .hbox .addWidget (self .reset_button )
29+ self .timer = QBasicTimer ()
30+ self .step = 0
31+ self .setLayout (self .hbox )
32+ self .show ()
33+ self .taskbar_init ()
34+ def taskbar_init (self ):
35+ self .taskbar_button = QWinTaskbarButton (self )
36+ self .taskbar_button .setWindow (self .windowHandle ())
37+ self .taskbar_progress = self .taskbar_button .progress ()
38+ self .taskbar_progress .setMinimum (0 )
39+ self .taskbar_progress .setMaximum (100 )
40+ self .taskbar_progress .setValue (0 )
41+ self .taskbar_progress .setVisible (True )
42+ self .taskbar_progress .show ()
43+ def timerEvent (self , timer_event ):
44+ if self .step <= 100 :
45+ self .taskbar_progress .setValue (self .step )
46+ self .step += 1
47+ else :
48+ self .timer .stop ()
49+ return super ().timerEvent (timer_event )
50+ def start_stop (self ):
51+ if self .timer .isActive ():
52+ self .timer .stop ()
53+ self .start_stop_button .setText ("Start" )
54+ self .start_stop_button .resize (self .start_stop_button .sizeHint ())
55+ elif not self .timer .isActive ():
56+ self .timer .start (100 , self )
57+ self .start_stop_button .setText ("Stop" )
58+ self .start_stop_button .resize (self .start_stop_button .sizeHint ())
59+ def pause (self ):
60+ if not self .taskbar_progress .isPaused ():
61+ self .taskbar_progress .pause ()
62+ elif self .taskbar_progress .isPaused ():
63+ self .taskbar_progress .resume ()
64+ def stop (self ):
65+ if not self .taskbar_progress .isStopped ():
66+ self .timer .stop ()
67+ self .taskbar_progress .stop ()
68+ elif self .taskbar_progress .isStopped ():
69+ self .taskbar_progress .resume ()
70+ def reset (self ):
71+ self .timer .stop ()
72+ self .step = 0
73+ self .taskbar_progress .reset ()
74+ app = QApplication (sys .argv )
75+ form = Form ()
76+ sys .exit (app .exec_ ())
0 commit comments