Skip to content

Commit 06a3829

Browse files
authored
Add files via upload
1 parent 088e44c commit 06a3829

File tree

6 files changed

+133
-0
lines changed

6 files changed

+133
-0
lines changed

PyTaskbar/ProgressAPI.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import ctypes
2+
3+
import comtypes.client as cc
4+
import time
5+
import warnings
6+
7+
cc.GetModule("./TaskbarLib.tlb")
8+
9+
import comtypes.gen.TaskbarLib as tbl
10+
from comtypes.gen import _683BF642_E9CA_4124_BE43_67065B2FA653_0_1_0
11+
taskbar = cc.CreateObject(
12+
"{56FDF344-FD6D-11d0-958A-006097C9A090}",
13+
interface=tbl.ITaskbarList3)
14+
15+
hWnd = ctypes.windll.kernel32.GetConsoleWindow()
16+
taskbar.ActivateTab(hWnd)
17+
#print('HWND: '+str(hWnd))
18+
19+
class TaskbarProgress(object):
20+
def __init__(self,hwnd=hWnd):
21+
super().__init__()
22+
self.initialised = False
23+
self.state = None
24+
self.win = hwnd
25+
26+
def init(self):
27+
self.thisWindow = self.win
28+
taskbar.ActivateTab(self.win)
29+
taskbar.HrInit()
30+
self.state = 'normal'
31+
self.progress = 0
32+
self.initialised = True
33+
34+
def setState(self,value):
35+
if not self.initialised == False:
36+
if value == 'normal':
37+
taskbar.SetProgressState(self.thisWindow,0)
38+
self.state = 'normal'
39+
40+
elif value == 'warning':
41+
taskbar.SetProgressState(self.thisWindow,10)
42+
self.state = 'warning'
43+
44+
elif value == 'error':
45+
taskbar.SetProgressState(self.thisWindow,15)
46+
self.state = 'error'
47+
48+
elif value == 'loading':
49+
taskbar.SetProgressState(self.thisWindow,-15)
50+
self.state = 'loading'
51+
52+
elif value == 'done':
53+
ctypes.windll.user32.FlashWindow(self.thisWindow,True)
54+
self.state = 'done'
55+
56+
else:
57+
warnings.warn('Invalid Argument {} .Please selece one from (normal,warning,error,loading,done).'.format(value))
58+
59+
else:
60+
warnings.warn('Please initialise the object (method:Progress.initialise())')
61+
62+
def setProgress(self,value:int):
63+
if not self.initialised == False:
64+
taskbar.setProgressValue(self.thisWindow,value,100)
65+
66+
elif value>100 or value<0:
67+
warnings.warn('Invalid Argument {} .Please selece one from (<100,>0).'.fromat(value))
68+
69+
else:
70+
warnings.warn('Please initialise the object (method:Progress.initialise())')

PyTaskbar/TaskbarLib.tlb

6.67 KB
Binary file not shown.

PyTaskbar/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .ProgressAPI import TaskbarProgress as Progress

example.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import time
2+
import PyTaskbar
3+
4+
prog = PyTaskbar.Progress()
5+
prog.init()
6+
7+
prog.setState('loading')
8+
time.sleep(5)
9+
10+
prog.setState('normal')
11+
12+
for i in range(100):
13+
prog.setProgress(i)
14+
time.sleep(0.05)
15+
prog.setProgress(0)
16+
17+
prog.setState('warning')
18+
19+
for i in range(100):
20+
prog.setProgress(i)
21+
time.sleep(0.05)
22+
23+
prog.setProgress(0)
24+
prog.setState('error')
25+
26+
for i in range(100):
27+
prog.setProgress(i)
28+
time.sleep(0.05)
29+
30+
prog.setProgress(0)
31+
32+
prog.setState('done')
33+
while True:
34+
time.sleep(1)
35+
print('close me!')

install.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
import shutil
3+
os.system('cd '+os.path.join('.'))
4+
os.system('python setup.py install')
5+
print('\n\n\nNOTE: Copy the TaskbarLib.tlb file to your project directory')
6+
print('\nRunning the example for a quick test,hang on...')
7+
os.system('python example.py')

setup.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
name='PyTaskbar',
5+
version='0.0.1',
6+
author='somePythonProgrammer',
7+
description='The ultimate taskbar progress python package!',
8+
packages = setuptools.find_packages(include=['PyTaskbar']),
9+
package_dir={'PyTaskbar': 'PyTaskbar'},
10+
classifiers = [
11+
'Programming Language :: Python :: 3',
12+
'Liscence :: OSI Approved :: MIT Licence',
13+
'Operating System :: Windows'
14+
],
15+
python_requires='>=3.6',
16+
install_requires=[
17+
'comtypes',
18+
'setuptools',
19+
]
20+
)

0 commit comments

Comments
 (0)