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):
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()
57 self["config"].setList( [ getConfigListEntry(_("After event"), self.settings.afterEvent) ])
58 self.job.afterEvent = self.settings.afterEvent.getValue()
61 ConfigListScreen.keyLeft(self)
65 ConfigListScreen.keyRight(self)
69 self.job.state_changed.append(self.state_changed)
72 if len(self.job.state_changed) > 0:
73 self.job.state_changed.remove(self.state_changed)
75 def state_changed(self):
77 self["job_progress"].range = j.end
78 self["summary_job_progress"].range = j.end
79 self["job_progress"].value = j.progress
80 self["summary_job_progress"].value = j.progress
81 #print "JobView::state_changed:", j.end, j.progress
82 self["job_status"].text = j.getStatustext()
83 if j.status == j.IN_PROGRESS:
84 self["job_task"].text = j.tasks[j.current_task].name
85 self["summary_job_task"].text = j.tasks[j.current_task].name
87 self["job_task"].text = ""
88 self["summary_job_task"].text = j.getStatustext()
89 if j.status in (j.FINISHED, j.FAILED):
90 self.performAfterEvent()
91 self["backgroundable"].boolean = False
92 if j.status == j.FINISHED:
93 self["finished"].boolean = True
94 self["cancelable"].boolean = False
95 elif j.status == j.FAILED:
96 self["cancelable"].boolean = True
99 if self["backgroundable"].boolean == True:
103 if self.job.status in (self.job.FINISHED, self.job.FAILED):
107 if self.job.status in (self.job.FINISHED, self.job.FAILED):
109 if self["cancelable"].boolean == True:
112 def performAfterEvent(self):
113 self["config"].hide()
114 if self.settings.afterEvent.getValue() == "nothing":
116 elif self.settings.afterEvent.getValue() == "close":
118 from Screens.MessageBox import MessageBox
119 if self.settings.afterEvent.getValue() == "deepstandby":
120 if not Screens.Standby.inTryQuitMainloop:
121 Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A sleep timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
122 elif self.settings.afterEvent.getValue() == "standby":
123 if not Screens.Standby.inStandby:
124 Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A sleep timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
126 def sendStandbyNotification(self, answer):
128 Notifications.AddNotification(Screens.Standby.Standby)
130 def sendTryQuitMainloopNotification(self, answer):
132 Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)