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 InfoBarGenerics import InfoBarNotifications
7 from Tools import Notifications
9 class JobView(InfoBarNotifications, Screen, ConfigListScreen):
10 def __init__(self, session, job, parent=None, cancelable = True, backgroundable = True, afterEventChangeable = True):
11 from Components.Sources.StaticText import StaticText
12 from Components.Sources.Progress import Progress
13 from Components.Sources.Boolean import Boolean
14 from Components.ActionMap import ActionMap
15 Screen.__init__(self, session, parent)
16 InfoBarNotifications.__init__(self)
17 ConfigListScreen.__init__(self, [])
21 self["job_name"] = StaticText(job.name)
22 self["job_progress"] = Progress()
23 self["job_task"] = StaticText()
24 self["summary_job_name"] = StaticText(job.name)
25 self["summary_job_progress"] = Progress()
26 self["summary_job_task"] = StaticText()
27 self["job_status"] = StaticText()
28 self["finished"] = Boolean()
29 self["cancelable"] = Boolean(cancelable)
30 self["backgroundable"] = Boolean(backgroundable)
32 self["key_blue"] = StaticText(_("Background"))
34 self.onShow.append(self.windowShow)
35 self.onHide.append(self.windowHide)
37 self["setupActions"] = ActionMap(["ColorActions", "SetupActions"],
41 "blue": self.background,
46 self.settings = ConfigSubsection()
47 if SystemInfo["DeepstandbySupport"]:
48 shutdownString = _("go to deep standby")
50 shutdownString = _("shut down")
51 self.settings.afterEvent = ConfigSelection(choices = [("nothing", _("do nothing")), ("close", _("Close")), ("standby", _("go to standby")), ("deepstandby", shutdownString)], default = self.job.afterEvent or "nothing")
52 self.job.afterEvent = self.settings.afterEvent.getValue()
53 self.afterEventChangeable = afterEventChangeable
58 if self.afterEventChangeable:
59 self["config"].setList( [ getConfigListEntry(_("After event"), self.settings.afterEvent) ])
62 self.job.afterEvent = self.settings.afterEvent.getValue()
65 ConfigListScreen.keyLeft(self)
69 ConfigListScreen.keyRight(self)
73 self.job.state_changed.append(self.state_changed)
76 if len(self.job.state_changed) > 0:
77 self.job.state_changed.remove(self.state_changed)
79 def state_changed(self):
81 self["job_progress"].range = j.end
82 self["summary_job_progress"].range = j.end
83 self["job_progress"].value = j.progress
84 self["summary_job_progress"].value = j.progress
85 #print "JobView::state_changed:", j.end, j.progress
86 self["job_status"].text = j.getStatustext()
87 if j.status == j.IN_PROGRESS:
88 self["job_task"].text = j.tasks[j.current_task].name
89 self["summary_job_task"].text = j.tasks[j.current_task].name
91 self["job_task"].text = ""
92 self["summary_job_task"].text = j.getStatustext()
93 if j.status in (j.FINISHED, j.FAILED):
94 self.performAfterEvent()
95 self["backgroundable"].boolean = False
96 if j.status == j.FINISHED:
97 self["finished"].boolean = True
98 self["cancelable"].boolean = False
99 elif j.status == j.FAILED:
100 self["cancelable"].boolean = True
102 def background(self):
103 if self["backgroundable"].boolean == True:
107 if self.job.status in (self.job.FINISHED, self.job.FAILED):
111 if self.job.status in (self.job.FINISHED, self.job.FAILED):
113 if self["cancelable"].boolean == True:
116 def performAfterEvent(self):
117 self["config"].hide()
118 if self.settings.afterEvent.getValue() == "nothing":
120 elif self.settings.afterEvent.getValue() == "close" and self.job.status == self.job.FINISHED:
122 from Screens.MessageBox import MessageBox
123 if self.settings.afterEvent.getValue() == "deepstandby":
124 if not Screens.Standby.inTryQuitMainloop:
125 Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A sleep timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
126 elif self.settings.afterEvent.getValue() == "standby":
127 if not Screens.Standby.inStandby:
128 Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A sleep timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
130 def checkNotifications(self):
131 InfoBarNotifications.checkNotifications(self)
132 if Notifications.notifications == []:
133 if self.settings.afterEvent.getValue() == "close" and self.job.status == self.job.FAILED:
136 def sendStandbyNotification(self, answer):
138 Notifications.AddNotification(Screens.Standby.Standby)
140 def sendTryQuitMainloopNotification(self, answer):
142 Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)