Skip to content

Commit

Permalink
Windows下在任务栏显示进度条
Browse files Browse the repository at this point in the history
Close #68
  • Loading branch information
TransparentLC committed Mar 7, 2024
1 parent 7bd7bbf commit 68cdfcb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Binary file added TaskbarLib.tlb
Binary file not shown.
22 changes: 22 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ def __init__(self, parent: tk.Tk, config: configparser.ConfigParser, models: lis
self.progressValue: list[int | float] = [0, 0, 1]
# 初始值/结束值/进度/after ID
self.progressAnimation: list[float | str] = [0, 0, 0, None]
# 任务栏进度条
match sys.platform:
case 'win32':
import comtypes.client
comtypes.client.GetModule(os.path.join(define.APP_PATH, 'TaskbarLib.tlb'))
import comtypes.gen.TaskbarLib
self.progressNativeTaskbar = comtypes.client.CreateObject('{56FDF344-FD6D-11d0-958A-006097C9A090}', interface=comtypes.gen.TaskbarLib.ITaskbarList3)
self.progressNativeTaskbar.HrInit()
self.progressNativeTaskbar.ActivateTab(int(self.master.wm_frame(), 16))
self.progressNativeTaskbar.SetProgressState(int(self.master.wm_frame(), 16), 0) # TBPF_NOPROGRESS
case _:
self.progressNativeTaskbar = None
# 控制是否暂停
self.pauseEvent = threading.Event()

Expand Down Expand Up @@ -496,6 +508,11 @@ def buttonProcess_click(self):
default_notification_application_name=define.APP_TITLE,
default_notification_icon=os.path.join(define.BASE_PATH, 'icon-128px.png'),
)
match sys.platform:
case 'win32':
self.progressNativeTaskbar.SetProgressState(int(self.master.wm_frame(), 16), 2) # TBPF_NORMAL
# 初始进度应该是0,但是直接设为0没有效果,所以改成使用非常接近0的值
self.progressNativeTaskbar.SetProgressValue(int(self.master.wm_frame(), 16), 1, 0xFFFFFFFF)
ts = time.perf_counter()
def completeCallback(withError: bool):
te = time.perf_counter()
Expand Down Expand Up @@ -531,6 +548,7 @@ def failCallback(ex: Exception):
self.buttonProcess.config(style='' if self.varboolProcessing.get() and not self.varboolProcessingPaused.get() else 'Accent.TButton'),
self.varstrLabelStartProcessing.set(i18n.getTranslatedString(('ContinueProcessing' if self.varboolProcessingPaused.get() else 'PauseProcessing') if self.varboolProcessing.get() else 'StartProcessing')),
self.logFile.close(),
sys.platform == 'win32' and self.progressNativeTaskbar.SetProgressState(int(self.master.wm_frame(), 16), 0), # TBPF_NOPROGRESS
),
self.varboolIgnoreError.get(),
)
Expand Down Expand Up @@ -578,6 +596,10 @@ def anim():
self.progressAnimation[1] = progressTo
self.progressAnimation[2] = 0
self.progressAnimation[3] = self.progressbar.after(10, anim)
match sys.platform:
case 'win32':
self.progressNativeTaskbar.SetProgressState(int(self.master.wm_frame(), 16), 2) # TBPF_NORMAL
self.progressNativeTaskbar.SetProgressValue(int(self.master.wm_frame(), 16), round(progressTo), 100)

def getConfigParams(self) -> param.REConfigParams:
resizeModeValue = 0
Expand Down
2 changes: 2 additions & 0 deletions realesrgan-gui.spec
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ a = Analysis(
('i18n.ini', '.'),
('icon-256px.ico', '.'),
('icon-128px.png', '.'),
# Windows下在任务栏显示进度条
*(('TaskbarLib.tlb', '.') if sys.platform == 'win32' else ()),
# macOS下通过app实现通知,打包时需要附带
*collect_data_files('notifypy'),
],
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
comtypes == 1.*; sys_platform == 'win32'
darkdetect == 0.8.*; sys_platform != 'darwin'
darkdetect[macos-listener] == 0.8.*; sys_platform == 'darwin'
notify-py == 0.3.*; sys_platform != 'darwin'
Expand Down

0 comments on commit 68cdfcb

Please sign in to comment.