Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
N3RDIUM committed May 21, 2021
1 parent 088e44c commit 06a3829
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
70 changes: 70 additions & 0 deletions PyTaskbar/ProgressAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import ctypes

import comtypes.client as cc
import time
import warnings

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)
#print('HWND: '+str(hWnd))

class TaskbarProgress(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())')
Binary file added PyTaskbar/TaskbarLib.tlb
Binary file not shown.
1 change: 1 addition & 0 deletions PyTaskbar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .ProgressAPI import TaskbarProgress as Progress
35 changes: 35 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import time
import PyTaskbar

prog = PyTaskbar.Progress()
prog.init()

prog.setState('loading')
time.sleep(5)

prog.setState('normal')

for i in range(100):
prog.setProgress(i)
time.sleep(0.05)
prog.setProgress(0)

prog.setState('warning')

for i in range(100):
prog.setProgress(i)
time.sleep(0.05)

prog.setProgress(0)
prog.setState('error')

for i in range(100):
prog.setProgress(i)
time.sleep(0.05)

prog.setProgress(0)

prog.setState('done')
while True:
time.sleep(1)
print('close me!')
7 changes: 7 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os
import shutil
os.system('cd '+os.path.join('.'))
os.system('python setup.py install')
print('\n\n\nNOTE: Copy the TaskbarLib.tlb file to your project directory')
print('\nRunning the example for a quick test,hang on...')
os.system('python example.py')
20 changes: 20 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import setuptools

setuptools.setup(
name='PyTaskbar',
version='0.0.1',
author='somePythonProgrammer',
description='The ultimate taskbar progress python package!',
packages = setuptools.find_packages(include=['PyTaskbar']),
package_dir={'PyTaskbar': 'PyTaskbar'},
classifiers = [
'Programming Language :: Python :: 3',
'Liscence :: OSI Approved :: MIT Licence',
'Operating System :: Windows'
],
python_requires='>=3.6',
install_requires=[
'comtypes',
'setuptools',
]
)

0 comments on commit 06a3829

Please sign in to comment.