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)
16 ConfigListScreen.__init__(self, [])
20 self["job_name"] = StaticText(job.name)
21 self["job_progress"] = Progress()
22 self["job_task"] = StaticText()
23 self["summary_job_name"] = StaticText(job.name)
24 self["summary_job_progress"] = Progress()
25 self["summary_job_task"] = StaticText()
26 self["job_status"] = StaticText()
27 self["finished"] = Boolean()
28 self["cancelable"] = Boolean(cancelable)
29 self["backgroundable"] = Boolean(backgroundable)
31 self["key_blue"] = StaticText(_("Background"))
33 self.onShow.append(self.windowShow)
34 self.onHide.append(self.windowHide)
36 self["setupActions"] = ActionMap(["ColorActions", "SetupActions"],
40 "blue": self.background,
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["summary_job_progress"].range = j.end
73 self["job_progress"].value = j.progress
74 self["summary_job_progress"].value = j.progress
75 #print "JobView::state_changed:", j.end, j.progress
76 self["job_status"].text = j.getStatustext()
77 if j.status == j.IN_PROGRESS:
78 self["job_task"].text = j.tasks[j.current_task].name
79 self["summary_job_task"].text = j.tasks[j.current_task].name
81 self["job_task"].text = ""
82 self["summary_job_task"].text = j.getStatustext()
83 if j.status in [j.FINISHED, j.FAILED]:
84 self.performAfterEvent()
85 self["backgroundable"].boolean = False
86 if j.status == j.FINISHED:
87 self["finished"].boolean = True
88 self["cancelable"].boolean = False
89 elif j.status == j.FAILED:
90 self["cancelable"].boolean = True
93 if self["backgroundable"].boolean == True:
97 if self.job.status in [self.job.FINISHED, self.job.FAILED]:
101 if self.job.status in [self.job.FINISHED, self.job.FAILED]:
103 if self["cancelable"].boolean == True:
106 def performAfterEvent(self):
107 self["config"].hide()
108 if self.settings.afterEvent.getValue() == "nothing":
110 elif self.settings.afterEvent.getValue() == "close":
112 from Screens.MessageBox import MessageBox
113 if self.settings.afterEvent.getValue() == "deepstandby":
114 if not Screens.Standby.inTryQuitMainloop:
115 Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A sleep timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
116 elif self.settings.afterEvent.getValue() == "standby":
117 if not Screens.Standby.inStandby:
118 Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A sleep timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
120 def sendStandbyNotification(self, answer):
122 Notifications.AddNotification(Screens.Standby.Standby)
124 def sendTryQuitMainloopNotification(self, answer):
126 Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)