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