chiark / gitweb /
c3dc4f3d4f95909a93f72358ae25456305902cf4
[cura.git] / Cura / gui / util / taskbar.py
1 from __future__ import absolute_import
2
3 try:
4         import comtypes.client as cc
5         cc.GetModule('taskbarlib.tlb')
6         import comtypes.gen.TaskbarLib as tbl
7
8         ITaskbarList3 = cc.CreateObject("{56FDF344-FD6D-11d0-958A-006097C9A090}", interface=tbl.ITaskbarList3)
9         ITaskbarList3.HrInit()
10
11         #Stops displaying progress and returns the button to its normal state. Call this method with this flag to dismiss the progress bar when the operation is complete or canceled.
12         TBPF_NOPROGRESS = 0x00000000
13         #The progress indicator does not grow in size, but cycles repeatedly along the length of the taskbar button. This indicates activity without specifying what proportion of the progress is complete. Progress is taking place, but there is no prediction as to how long the operation will take.
14         TBPF_INDETERMINATE = 0x00000001
15         #The progress indicator grows in size from left to right in proportion to the estimated amount of the operation completed. This is a determinate progress indicator; a prediction is being made as to the duration of the operation.
16         TBPF_NORMAL = 0x00000002
17         #The progress indicator turns red to show that an error has occurred in one of the windows that is broadcasting progress. This is a determinate state. If the progress indicator is in the indeterminate state, it switches to a red determinate display of a generic percentage not indicative of actual progress.
18         TBPF_ERROR = 0x00000004
19         #The progress indicator turns yellow to show that progress is currently stopped in one of the windows but can be resumed by the user. No error condition exists and nothing is preventing the progress from continuing. This is a determinate state. If the progress indicator is in the indeterminate state, it switches to a yellow determinate display of a generic percentage not indicative of actual progress.
20         TBPF_PAUSED = 0x00000008
21 except:
22         #The taskbar API is only available for Windows7, on lower windows versions, linux or Mac it will cause an exception. Ignore the exception and don't use the API
23         ITaskbarList3 = None
24
25 def setBusy(frame, busy):
26         if ITaskbarList3 != None:
27                 if busy:
28                         ITaskbarList3.SetProgressState(frame.GetHandle(), TBPF_INDETERMINATE)
29                 else:
30                         ITaskbarList3.SetProgressState(frame.GetHandle(), TBPF_NOPROGRESS)
31
32 def setPause(frame, pause):
33         if ITaskbarList3 != None:
34                 if pause:
35                         ITaskbarList3.SetProgressState(frame.GetHandle(), TBPF_PAUSED)
36                 else:
37                         ITaskbarList3.SetProgressState(frame.GetHandle(), TBPF_NORMAL)
38
39 def setProgress(frame, done, total):
40         if ITaskbarList3 != None:
41                 ITaskbarList3.SetProgressState(frame.GetHandle(), TBPF_NORMAL)
42                 ITaskbarList3.SetProgressValue(frame.GetHandle(), done, total)