-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .ProgressAPI import TaskbarProgress as Progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
] | ||
) |