1 class ExportError(Exception):
2 def __init__(self, objs):
3 super().__init__(" -> ".join(o.name for o in objs))
7 def __init__(self, ctx, *args, verbose=False):
10 if type(ctx)==ExportContext:
11 self.level = ctx.level+1
13 self.context = ctx.context
14 self.verbose = ctx.verbose
15 self.descr, self.start, self.delta = args
16 if type(self.descr)!=str:
18 self.descr = self.descr.name
23 self.verbose = verbose
27 self.context.window_manager.progress_begin(self.start, self.delta)
29 if self.verbose and self.descr:
32 d += " ({})".format(type(self.obj).__name__)
33 print("{} {}".format("ยท"*self.level, d))
35 self.slice_delta = 0.0
36 self.progress = self.start
38 self.context.window_manager.progress_update(self.progress)
39 self.last_progress_update = self.progress
41 def export(self, func, *args, **kwargs):
43 func(self, *args, **kwargs)
44 except Exception as e:
50 objs = [t.obj for t in tasks if t.obj]
51 raise ExportError(objs) from e
53 def task(self, task, end):
54 self.child = ExportContext(self, task, self.progress, self.start+end*self.delta-self.progress)
55 self.progress += self.child.delta
58 def set_progress(self, progr):
59 self.progress = self.start+progr*self.delta
61 if self.progress>self.last_progress_update+0.001:
62 self.context.window_manager.progress_update(self.progress)
63 self.last_progress_update = self.progress
65 def set_slices(self, count):
67 self.slice_delta = self.delta/count
69 self.slice_delta = 0.0
71 def next_slice(self, task):
72 self.child = ExportContext(self, task, self.progress, self.slice_delta)
73 self.progress += self.slice_delta