1 from Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, ConfigSubsection, ConfigSelection, getConfigListEntry
4 from InfoBarGenerics import InfoBarNotifications
6 from Tools import Notifications
8 class JobView(InfoBarNotifications, Screen, ConfigListScreen):
9 def __init__(self, session, job, parent=None, cancelable = True, backgroundable = True, afterEvent = 0):
10 from Components.Sources.StaticText import StaticText
11 from Components.Sources.Progress import Progress
12 from Components.Sources.Boolean import Boolean
13 from Components.ActionMap import ActionMap
14 Screen.__init__(self, session, parent)
15 InfoBarNotifications.__init__(self)
18 self.job.taskview = self
20 self["job_name"] = StaticText(job.name)
21 self["job_progress"] = Progress()
22 self["job_status"] = StaticText()
23 self["job_task"] = StaticText()
24 self["finished"] = Boolean()
25 self["cancelable"] = Boolean(cancelable)
26 self["backgroundable"] = Boolean(backgroundable)
28 self["key_blue"] = StaticText(_("Background"))
30 self.onShow.append(self.windowShow)
31 self.onHide.append(self.windowHide)
33 self["actions"] = ActionMap(["OkCancelActions"],
38 self["ColorActions"] = ActionMap(["ColorActions"],
42 "blue": self.background,
44 ConfigListScreen.__init__(self, [])
45 self.afterevents = [ "nothing", "standby", "deepstandby", "close" ]
46 self.settings = ConfigSubsection()
47 self.settings.afterEvent = ConfigSelection(choices = [("nothing", _("do nothing")), ("close", _("Close")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby"))], default = self.afterevents[afterEvent])
52 self["config"].setList( [ getConfigListEntry(_("After event"), self.settings.afterEvent) ])
55 ConfigListScreen.keyLeft(self)
59 ConfigListScreen.keyRight(self)
63 self.job.state_changed.append(self.state_changed)
66 if len(self.job.state_changed) > 0:
67 self.job.state_changed.remove(self.state_changed)
69 def state_changed(self):
71 self["job_progress"].range = j.end
72 self["job_progress"].value = j.progress
73 #print "JobView::state_changed:", j.end, j.progress
74 self["job_status"].text = {j.NOT_STARTED: _("Waiting"), j.IN_PROGRESS: _("In Progress"), j.FINISHED: _("Finished"), j.FAILED: _("Failed")}[j.status]
75 if j.status == j.IN_PROGRESS:
76 self["job_task"].text = j.tasks[j.current_task].name
78 self["job_task"].text = ""
79 if j.status in [j.FINISHED, j.FAILED]:
80 self.performAfterEvent()
81 self["backgroundable"].boolean = False
82 if j.status == j.FINISHED:
83 self["finished"].boolean = True
84 self["cancelable"].boolean = False
85 elif j.status == j.FAILED:
86 self["cancelable"].boolean = True
89 if self["backgroundable"].boolean == True:
93 if self.job.status in [self.job.FINISHED, self.job.FAILED]:
97 if self.job.status in [self.job.FINISHED, self.job.FAILED]:
99 if self["cancelable"].boolean == True:
102 def performAfterEvent(self):
103 if self.settings.afterEvent.getValue() == "nothing":
105 elif self.settings.afterEvent.getValue() == "close":
107 from Screens.MessageBox import MessageBox
108 if self.settings.afterEvent.getValue() == "deepstandby":
109 if not Screens.Standby.inTryQuitMainloop:
110 Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A sleep timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
111 elif self.settings.afterEvent.getValue() == "standby":
112 if not Screens.Standby.inStandby:
113 Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A sleep timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
115 def sendStandbyNotification(self, answer):
117 Notifications.AddNotification(Screens.Standby.Standby)
119 def sendTryQuitMainloopNotification(self, answer):
121 Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)