]> git.tdb.fi Git - libs/gl.git/blob - io_mspgl/util.py
Check the flat qualifier from the correct member
[libs/gl.git] / io_mspgl / util.py
1 class Progress:
2         def __init__(self, context):
3                 self.task = ""
4                 self.start = 0.0
5                 self.delta = 1.0
6                 self.last = 0.0
7                 self.stack = []
8                 if context:
9                         self.window_manager = context.window_manager
10                         self.window_manager.progress_begin(0.0, 1.0)
11                 else:
12                         self.window_manager = None
13
14         def push_task(self, task, low, high):
15                 self.stack.append((self.task, self.start, self.delta))
16                 self.set_task(task, low, high)
17
18         def push_task_slice(self, task, index, count):
19                 self.push_task(task, index/count, (index+1)/count)
20
21         def pop_task(self):
22                 if not self.stack:
23                         return
24
25                 self.set_progress(1.0)
26                 self.task, self.start, self.delta = self.stack.pop()
27
28         def set_task(self, task, low, high):
29                 if self.stack:
30                         outer = self.stack[-1]
31                         if outer[0]:
32                                 task = "{}: {}".format(outer[0], task)
33                         low = outer[1]+low*outer[2]
34                         high = outer[1]+high*outer[2]
35
36                 self.task = task
37                 self.start = low
38                 self.delta = high-low
39
40                 self.set_progress(0.0)
41
42         def set_task_slice(self, task, index, count):
43                 self.set_task(task, index/count, (index+1)/count)
44
45         def set_progress(self, value):
46                 value = self.start+self.delta*value
47                 if value>self.last+0.01:
48                         if self.window_manager:
49                                 self.window_manager.progress_update(value)
50                         self.last = value