allow DVD burning in background. to view progress of jobs, press extensions key ...
[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, parent=None, cancelable = True, backgroundable = 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, parent)
11                 InfoBarNotifications.__init__(self)
12                 self.parent = parent
13                 self.job = job
14                 self.job.taskview = self
15                 self.close_on_finish = close_on_finish
16
17                 self["job_name"] = StaticText(job.name)
18                 self["job_progress"] = Progress()
19                 self["job_status"] = StaticText()
20                 self["job_task"] = StaticText()
21                 self["finished"] = Boolean()
22                 self["cancelable"] = Boolean(cancelable)
23                 self["backgroundable"] = Boolean(backgroundable)
24
25                 self["key_blue"] = StaticText(_("Background"))
26
27                 self.onShow.append(self.windowShow)
28                 self.onHide.append(self.windowHide)
29
30                 self["actions"] = ActionMap(["OkCancelActions"], 
31                         {
32                                 "ok": self.ok,
33                                 "cancel": self.ok
34                         })
35                 self["ColorActions"] = ActionMap(["ColorActions"],
36                         {
37                                 "red": self.abort,
38                                 "green": self.ok,
39                                 "blue": self.background,
40                         })
41
42         def windowShow(self):
43                 self.job.state_changed.append(self.state_changed)
44                 self.state_changed()
45
46         def windowHide(self):
47                 if len(self.job.state_changed) > 0:
48                     self.job.state_changed.remove(self.state_changed)
49
50         def state_changed(self):
51                 j = self.job
52                 self["job_progress"].range = j.end
53                 self["job_progress"].value = j.progress
54                 #print "JobView::state_changed:", j.end, j.progress
55                 self["job_status"].text = {j.NOT_STARTED: _("Waiting"), j.IN_PROGRESS: _("In Progress"), j.FINISHED: _("Finished"), j.FAILED: _("Failed")}[j.status]
56                 if j.status == j.IN_PROGRESS:
57                         self["job_task"].text = j.tasks[j.current_task].name
58                 else:
59                         self["job_task"].text = ""
60                 if j.status in [j.FINISHED, j.FAILED]:
61                         if self.close_on_finish:
62                                 self.close()
63                         self["backgroundable"].boolean = False
64                         if j.status == j.FINISHED:
65                                 self["finished"].boolean = True
66                                 self["cancelable"].boolean = False
67                         elif j.status == j.FAILED:
68                                 self["cancelable"].boolean = True
69
70         def background(self):
71                 print "[background]"
72                 if self["backgroundable"].boolean == True:
73                         self.close(True)
74
75         def ok(self):
76                 if self.job.status in [self.job.FINISHED, self.job.FAILED]:
77                         self.close(False)
78
79         def abort(self):
80                 if self.job.status in [self.job.FINISHED, self.job.FAILED]:
81                         self.close(False)
82                 if self["cancelable"].boolean == True:
83                         self.job.cancel()