11import sys
2+ 23from PySide2 .QtCore import QBasicTimer
3- from PySide2 .QtWidgets import QApplication , QWidget , QPushButton , QHBoxLayout
4+ from PySide2 .QtWidgets import QApplication , QWidget , QPushButton , QCheckBox , QHBoxLayout
5+ from PySide2 .QtGui import QIcon
46from PySide2 .QtWinExtras import QWinTaskbarButton
7+ 8+ 59class Form (QWidget ):
610 def __init__ (self ):
711 super ().__init__ ()
812 self .initUI ()
13+ 914 def initUI (self ):
1015 self .resize (500 , 300 )
1116 self .setWindowTitle ("Windows Taskbar ProgressBar" )
1217 self .start_stop_button = QPushButton ("Start" )
1318 self .start_stop_button .resize (self .start_stop_button .sizeHint ())
1419 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 )
20+ self .pause_checkbox = QCheckBox ("Pause" )
21+ self .pause_checkbox .resize (self .pause_checkbox .sizeHint ())
22+ self .pause_checkbox .clicked .connect (self .pause )
23+ self .stop_checkbox = QCheckBox ("Stop" )
24+ self .stop_checkbox .resize (self .stop_checkbox .sizeHint ())
25+ self .stop_checkbox .clicked .connect (self .stop )
26+ self .overlay_checkbox = QCheckBox ("Overlay icon" )
27+ self .overlay_checkbox .resize (self .overlay_checkbox .sizeHint ())
28+ self .overlay_checkbox .clicked .connect (self .toggle_overlay_icon )
2129 self .reset_button = QPushButton ("Reset" )
2230 self .reset_button .resize (self .reset_button .sizeHint ())
2331 self .reset_button .clicked .connect (self .reset )
2432 self .hbox = QHBoxLayout ()
2533 self .hbox .addWidget (self .start_stop_button )
26- self .hbox .addWidget (self .pause_button )
27- self .hbox .addWidget (self .stop_button )
34+ self .hbox .addWidget (self .pause_checkbox )
35+ self .hbox .addWidget (self .stop_checkbox )
36+ self .hbox .addWidget (self .overlay_checkbox )
2837 self .hbox .addWidget (self .reset_button )
2938 self .timer = QBasicTimer ()
3039 self .step = 0
3140 self .setLayout (self .hbox )
3241 self .show ()
3342 self .taskbar_init ()
43+ 3444 def taskbar_init (self ):
3545 self .taskbar_button = QWinTaskbarButton (self )
3646 self .taskbar_button .setWindow (self .windowHandle ())
@@ -40,13 +50,15 @@ def taskbar_init(self):
4050 self .taskbar_progress .setValue (0 )
4151 self .taskbar_progress .setVisible (True )
4252 self .taskbar_progress .show ()
53+ 4354 def timerEvent (self , timer_event ):
4455 if self .step <= 100 :
4556 self .taskbar_progress .setValue (self .step )
4657 self .step += 1
4758 else :
4859 self .timer .stop ()
4960 return super ().timerEvent (timer_event )
61+ 5062 def start_stop (self ):
5163 if self .timer .isActive ():
5264 self .timer .stop ()
@@ -56,21 +68,30 @@ def start_stop(self):
5668 self .timer .start (100 , self )
5769 self .start_stop_button .setText ("Stop" )
5870 self .start_stop_button .resize (self .start_stop_button .sizeHint ())
71+ 5972 def pause (self ):
6073 if not self .taskbar_progress .isPaused ():
6174 self .taskbar_progress .pause ()
6275 elif self .taskbar_progress .isPaused ():
6376 self .taskbar_progress .resume ()
77+ 6478 def stop (self ):
6579 if not self .taskbar_progress .isStopped ():
66- self .timer .stop ()
6780 self .taskbar_progress .stop ()
6881 elif self .taskbar_progress .isStopped ():
6982 self .taskbar_progress .resume ()
83+ 84+ def toggle_overlay_icon (self ):
85+ if self .overlay_checkbox .isChecked ():
86+ self .taskbar_button .setOverlayIcon (QIcon ("badge-1.ico" ))
87+ elif not self .overlay_checkbox .isChecked ():
88+ self .taskbar_button .clearOverlayIcon ()
89+ 7090 def reset (self ):
71- self .timer .stop ()
7291 self .step = 0
7392 self .taskbar_progress .reset ()
93+ 94+ 7495app = QApplication (sys .argv )
7596form = Form ()
76- sys .exit (app .exec_ ())
97+ sys .exit (app .exec_ ())
0 commit comments