diff --git a/PyTaskbar/ProgressAPI.py b/PyTaskbar/ProgressAPI.py new file mode 100644 index 0000000..f53a820 --- /dev/null +++ b/PyTaskbar/ProgressAPI.py @@ -0,0 +1,72 @@ +import ctypes + +import comtypes.client as cc +import sys +import warnings + + +parent_dir = __file__.rsplit("\\", 1)[0] +sys.path.append(parent_dir) +cc.GetModule("./TaskbarLib.tlb") + +import comtypes.gen.TaskbarLib as tbl +from comtypes.gen import _683BF642_E9CA_4124_BE43_67065B2FA653_0_1_0 +taskbar = cc.CreateObject( + "{56FDF344-FD6D-11d0-958A-006097C9A090}", + interface=tbl.ITaskbarList3) + +hWnd = ctypes.windll.kernel32.GetConsoleWindow() +taskbar.ActivateTab(hWnd) + +class Progress(object): + def __init__(self,hwnd=hWnd): + super().__init__() + self.initialised = False + self.state = None + self.win = hwnd + + def init(self): + self.thisWindow = self.win + taskbar.ActivateTab(self.win) + taskbar.HrInit() + self.state = 'normal' + self.progress = 0 + self.initialised = True + + def setState(self,value): + if not self.initialised == False: + if value == 'normal': + taskbar.SetProgressState(self.thisWindow,0) + self.state = 'normal' + + elif value == 'warning': + taskbar.SetProgressState(self.thisWindow,10) + self.state = 'warning' + + elif value == 'error': + taskbar.SetProgressState(self.thisWindow,15) + self.state = 'error' + + elif value == 'loading': + taskbar.SetProgressState(self.thisWindow,-15) + self.state = 'loading' + + elif value == 'done': + ctypes.windll.user32.FlashWindow(self.thisWindow,True) + self.state = 'done' + + else: + warnings.warn('Invalid Argument {} .Please selece one from (normal,warning,error,loading,done).'.format(value)) + + else: + warnings.warn('Please initialise the object (method:Progress.initialise())') + + def setProgress(self,value:int): + if not self.initialised == False: + taskbar.setProgressValue(self.thisWindow,value,100) + + elif value>100 or value<0: + warnings.warn('Invalid Argument {} .Please selece one from (<100,>0).'.fromat(value)) + + else: + warnings.warn('Please initialise the object (method:Progress.initialise())') \ No newline at end of file diff --git a/PyTaskbar/TaskbarLib.tlb b/PyTaskbar/TaskbarLib.tlb new file mode 100644 index 0000000..93eb0ae Binary files /dev/null and b/PyTaskbar/TaskbarLib.tlb differ diff --git a/PyTaskbar/__init__.py b/PyTaskbar/__init__.py new file mode 100644 index 0000000..0b90151 --- /dev/null +++ b/PyTaskbar/__init__.py @@ -0,0 +1 @@ +from .ProgressAPI import Progress \ No newline at end of file diff --git a/PyTaskbarProgress/readme.md b/PyTaskbarProgress/readme.md deleted file mode 100644 index c84e1b2..0000000 --- a/PyTaskbarProgress/readme.md +++ /dev/null @@ -1 +0,0 @@ -# The main library! diff --git a/setup.py b/setup.py index 80a7c35..089dc11 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def copy_tlb(dst): setuptools.setup( name='PyTaskbarProgress', - version='0.0.3', + version='0.0.5', author='somePythonProgrammer', description='The ultimate taskbar progress python package!', packages = setuptools.find_packages(include=['PyTaskbarProgress']), @@ -25,11 +25,12 @@ def copy_tlb(dst): python_requires='>=3.6', install_requires=[ 'comtypes', + 'pygetwindow', 'setuptools', ], include_package_data=True, url = 'https://github.com/somePythonProgrammer/PyTaskbar', long_description_content_type='text/markdown', long_description=open('README.md').read(), - download_url = 'https://github.com/somePythonProgrammer/PyTaskbar/releases/download/0.0.2/PyTaskbarProgress-0.0.2.tar.gz', + download_url = 'https://github.com/somePythonProgrammer/PyTaskbar/releases/download/0.0.5/PyTaskbarProgress-0.0.5.tar.gz', )