chiark / gitweb /
Merge pull request #601 from CapnBry/reloadscene
[cura.git] / Cura / gui / util / taskbar.py
1 """
2 Api for taskbar. Only for windows 7 or higher (filling up the icon while its progressing).
3 """
4 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
5
6 try:
7         import comtypes.client as cc
8         cc.GetModule('taskbarlib.tlb')
9         import comtypes.gen.TaskbarLib as tbl
10
11         ITaskbarList3 = cc.CreateObject("{56FDF344-FD6D-11d0-958A-006097C9A090}", interface=tbl.ITaskbarList3)
12         ITaskbarList3.HrInit()
13
14         #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.
15         TBPF_NOPROGRESS = 0x00000000
16         #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.
17         TBPF_INDETERMINATE = 0x00000001
18         #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.
19         TBPF_NORMAL = 0x00000002
20         #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.
21         TBPF_ERROR = 0x00000004
22         #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.
23         TBPF_PAUSED = 0x00000008
24 except:
25         #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
26         ITaskbarList3 = None
27
28 def setBusy(frame, busy):
29         if ITaskbarList3 is not None:
30                 if busy:
31                         ITaskbarList3.SetProgressState(frame.GetHandle(), TBPF_INDETERMINATE)
32                 else:
33                         ITaskbarList3.SetProgressState(frame.GetHandle(), TBPF_NOPROGRESS)
34
35 def setPause(frame, pause):
36         if ITaskbarList3 is not None:
37                 if pause:
38                         ITaskbarList3.SetProgressState(frame.GetHandle(), TBPF_PAUSED)
39                 else:
40                         ITaskbarList3.SetProgressState(frame.GetHandle(), TBPF_NORMAL)
41
42 def setProgress(frame, done, total):
43         if ITaskbarList3 is not None:
44                 ITaskbarList3.SetProgressState(frame.GetHandle(), TBPF_NORMAL)
45                 ITaskbarList3.SetProgressValue(frame.GetHandle(), done, total)