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, afterEvent = 0):
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.afterevents = [ "nothing", "standby", "deepstandby", "close" ]
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.afterevents[afterEvent])
57 self["config"].setList( [ getConfigListEntry(_("After event"), self.settings.afterEvent) ])
60 ConfigListScreen.keyLeft(self)
64 ConfigListScreen.keyRight(self)
68 self.job.state_changed.append(self.state_changed)
71 if len(self.job.state_changed) > 0:
72 self.job.state_changed.remove(self.state_changed)
74 def state_changed(self):
76 self["job_progress"].range = j.end
77 self["summary_job_progress"].range = j.end
78 self["job_progress"].value = j.progress
79 self["summary_job_progress"].value = j.progress
80 #print "JobView::state_changed:", j.end, j.progress
81 self["job_status"].text = j.getStatustext()
82 if j.status == j.IN_PROGRESS:
83 self["job_task"].text = j.tasks[j.current_task].name
84 self["summary_job_task"].text = j.tasks[j.current_task].name
86 self["job_task"].text = ""
87 self["summary_job_task"].text = j.getStatustext()
88 if j.status in (j.FINISHED, j.FAILED):
89 self.performAfterEvent()
90 self["backgroundable"].boolean = False
91 if j.status == j.FINISHED:
92 self["finished"].boolean = True
93 self["cancelable"].boolean = False
94 elif j.status == j.FAILED:
95 self["cancelable"].boolean = True
98 if self["backgroundable"].boolean == True:
102 if self.job.status in (self.job.FINISHED, self.job.FAILED):
106 if self.job.status in (self.job.FINISHED, self.job.FAILED):
108 if self["cancelable"].boolean == True:
111 def performAfterEvent(self):
112 self["config"].hide()
113 if self.settings.afterEvent.getValue() == "nothing":
115 elif self.settings.afterEvent.getValue() == "close":
117 from Screens.MessageBox import MessageBox
118 if self.settings.afterEvent.getValue() == "deepstandby":
119 if not Screens.Standby.inTryQuitMainloop:
120 Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A sleep timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
121 elif self.settings.afterEvent.getValue() == "standby":
122 if not Screens.Standby.inStandby:
123 Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A sleep timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
125 def sendStandbyNotification(self, answer):
127 Notifications.AddNotification(Screens.Standby.Standby)
129 def sendTryQuitMainloopNotification(self, answer):
131 Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)