fixes crash in DVDBurn
[enigma2.git] / lib / python / Screens / TaskView.py
1 from Screen import Screen
2 from InfoBarGenerics import InfoBarNotifications
3
4 class JobView(InfoBarNotifications, Screen):
5         def __init__(self, session, job, cancelable = True, close_on_finish = False):
6                 from Components.Sources.StaticText import StaticText
7                 from Components.Sources.Progress import Progress
8                 from Components.Sources.Boolean import Boolean
9                 from Components.ActionMap import ActionMap
10                 Screen.__init__(self, session)
11                 InfoBarNotifications.__init__(self)
12                 self.job = job
13                 self.close_on_finish = close_on_finish
14                 self.cancelable = cancelable
15
16                 self["job_name"] = StaticText(job.name)
17                 self["job_progress"] = Progress()
18                 self["job_status"] = StaticText()
19                 self["job_task"] = StaticText()
20                 self["finished"] = Boolean()
21
22                 self.onShow.append(self.windowShow)
23                 self.onHide.append(self.windowHide)
24
25                 self["actions"] = ActionMap(["OkCancelActions"], 
26                         {
27                                 "ok": self.ok,
28                                 "cancel": self.abort
29                         })
30
31         def windowShow(self):
32                 self.job.state_changed.append(self.state_changed)
33                 self.state_changed()
34
35         def windowHide(self):
36                 if len(self.job.state_changed) > 0:
37                     self.job.state_changed.remove(self.state_changed)
38
39         def state_changed(self):
40                 j = self.job
41                 self["job_progress"].range = j.end
42                 self["job_progress"].value = j.progress
43                 print "JobView::state_changed:", j.end, j.progress
44                 self["job_status"].text = {j.NOT_STARTED: _("Waiting"), j.IN_PROGRESS: _("In Progress"), j.FINISHED: _("Finished"), j.FAILED: _("Failed")}[j.status]
45                 if j.status == j.IN_PROGRESS:
46                         self["job_task"].text = j.tasks[j.current_task].name
47                 else:
48                         self["job_task"].text = ""
49                 if j.status in [j.FINISHED, j.FAILED]:
50                         if self.close_on_finish:
51                                 self.close()
52                         else:
53                                 self["finished"].boolean = True
54
55         def ok(self):
56                 if self.job.status in [self.job.FINISHED, self.job.FAILED]:
57                         self.close()
58
59         def abort(self):
60                 if self.job.status in [self.job.FINISHED, self.job.FAILED]:
61                         self.close()
62                 if self.cancelable:
63                         self.job.cancel()