1 from Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, ConfigSubsection, ConfigSelection, getConfigListEntry
4 from Components.SystemInfo import SystemInfo
5 from Components.Task import job_manager
6 from InfoBarGenerics import InfoBarNotifications
8 from Tools import Notifications
10 class JobView(InfoBarNotifications, Screen, ConfigListScreen):
11 def __init__(self, session, job, parent=None, cancelable = True, backgroundable = True, afterEventChangeable = True):
12 from Components.Sources.StaticText import StaticText
13 from Components.Sources.Progress import Progress
14 from Components.Sources.Boolean import Boolean
15 from Components.ActionMap import ActionMap
16 Screen.__init__(self, session, parent)
17 InfoBarNotifications.__init__(self)
18 ConfigListScreen.__init__(self, [])
22 self["job_name"] = StaticText(job.name)
23 self["job_progress"] = Progress()
24 self["job_task"] = StaticText()
25 self["summary_job_name"] = StaticText(job.name)
26 self["summary_job_progress"] = Progress()
27 self["summary_job_task"] = StaticText()
28 self["job_status"] = StaticText()
29 self["finished"] = Boolean()
30 self["cancelable"] = Boolean(cancelable)
31 self["backgroundable"] = Boolean(backgroundable)
33 self["key_blue"] = StaticText(_("Background"))
35 self.onShow.append(self.windowShow)
36 self.onHide.append(self.windowHide)
38 self["setupActions"] = ActionMap(["ColorActions", "SetupActions"],
42 "blue": self.background,
47 self.settings = ConfigSubsection()
48 if SystemInfo["DeepstandbySupport"]:
49 shutdownString = _("go to deep standby")
51 shutdownString = _("shut down")
52 self.settings.afterEvent = ConfigSelection(choices = [("nothing", _("do nothing")), ("close", _("Close")), ("standby", _("go to standby")), ("deepstandby", shutdownString)], default = self.job.afterEvent or "nothing")
53 self.job.afterEvent = self.settings.afterEvent.getValue()
54 self.afterEventChangeable = afterEventChangeable
59 if self.afterEventChangeable:
60 self["config"].setList( [ getConfigListEntry(_("After event"), self.settings.afterEvent) ])
63 self.job.afterEvent = self.settings.afterEvent.getValue()
66 ConfigListScreen.keyLeft(self)
70 ConfigListScreen.keyRight(self)
74 self.job.state_changed.append(self.state_changed)
77 if len(self.job.state_changed) > 0:
78 self.job.state_changed.remove(self.state_changed)
80 def state_changed(self):
82 self["job_progress"].range = j.end
83 self["summary_job_progress"].range = j.end
84 self["job_progress"].value = j.progress
85 self["summary_job_progress"].value = j.progress
86 #print "JobView::state_changed:", j.end, j.progress
87 self["job_status"].text = j.getStatustext()
88 if j.status == j.IN_PROGRESS:
89 self["job_task"].text = j.tasks[j.current_task].name
90 self["summary_job_task"].text = j.tasks[j.current_task].name
92 self["job_task"].text = ""
93 self["summary_job_task"].text = j.getStatustext()
94 if j.status in (j.FINISHED, j.FAILED):
95 self.performAfterEvent()
96 self["backgroundable"].boolean = False
97 if j.status == j.FINISHED:
98 self["finished"].boolean = True
99 self["cancelable"].boolean = False
100 elif j.status == j.FAILED:
101 self["cancelable"].boolean = True
103 def background(self):
104 if self["backgroundable"].boolean == True:
108 if self.job.status in (self.job.FINISHED, self.job.FAILED):
112 if self.job.status == self.job.NOT_STARTED:
113 job_manager.active_jobs.remove(self.job)
115 elif self.job.status == self.job.IN_PROGRESS and self["cancelable"].boolean == True:
120 def performAfterEvent(self):
121 self["config"].hide()
122 if self.settings.afterEvent.getValue() == "nothing":
124 elif self.settings.afterEvent.getValue() == "close" and self.job.status == self.job.FINISHED:
126 from Screens.MessageBox import MessageBox
127 if self.settings.afterEvent.getValue() == "deepstandby":
128 if not Screens.Standby.inTryQuitMainloop:
129 Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A sleep timer wants to shut down\nyour STB. Shutdown now?"), timeout = 20)
130 elif self.settings.afterEvent.getValue() == "standby":
131 if not Screens.Standby.inStandby:
132 Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A sleep timer wants to set your\nSTB to standby. Do that now?"), timeout = 20)
134 def checkNotifications(self):
135 InfoBarNotifications.checkNotifications(self)
136 if Notifications.notifications == []:
137 if self.settings.afterEvent.getValue() == "close" and self.job.status == self.job.FAILED:
140 def sendStandbyNotification(self, answer):
142 Notifications.AddNotification(Screens.Standby.Standby)
144 def sendTryQuitMainloopNotification(self, answer):
146 Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)