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, [])
19 self.job.taskview = self
21 self["job_name"] = StaticText(job.name)
22 self["job_progress"] = Progress()
23 self["job_status"] = StaticText()
24 self["job_task"] = StaticText()
25 self["finished"] = Boolean()
26 self["cancelable"] = Boolean(cancelable)
27 self["backgroundable"] = Boolean(backgroundable)
29 self["key_blue"] = StaticText(_("Background"))
31 self.onShow.append(self.windowShow)
32 self.onHide.append(self.windowHide)
34 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
38 "blue": self.background,
43 self.afterevents = [ "nothing", "standby", "deepstandby", "close" ]
44 self.settings = ConfigSubsection()
45 self.settings.afterEvent = ConfigSelection(choices = [("nothing", _("do nothing")), ("close", _("Close")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby"))], default = self.afterevents[afterEvent])
50 self["config"].setList( [ getConfigListEntry(_("After event"), self.settings.afterEvent) ])
53 ConfigListScreen.keyLeft(self)
57 ConfigListScreen.keyRight(self)
61 self.job.state_changed.append(self.state_changed)
64 if len(self.job.state_changed) > 0:
65 self.job.state_changed.remove(self.state_changed)
67 def state_changed(self):
69 self["job_progress"].range = j.end
70 self["job_progress"].value = j.progress
71 #print "JobView::state_changed:", j.end, j.progress
72 self["job_status"].text = j.getStatustext()
73 if j.status == j.IN_PROGRESS:
74 self["job_task"].text = j.tasks[j.current_task].name
76 self["job_task"].text = ""
77 if j.status in [j.FINISHED, j.FAILED]:
78 self.performAfterEvent()
79 self["backgroundable"].boolean = False
80 if j.status == j.FINISHED:
81 self["finished"].boolean = True
82 self["cancelable"].boolean = False
83 elif j.status == j.FAILED:
84 self["cancelable"].boolean = True
87 if self["backgroundable"].boolean == True:
91 if self.job.status in [self.job.FINISHED, self.job.FAILED]:
95 if self.job.status in [self.job.FINISHED, self.job.FAILED]:
97 if self["cancelable"].boolean == True:
100 def performAfterEvent(self):
101 self["config"].hide()
102 if self.settings.afterEvent.getValue() == "nothing":
104 elif self.settings.afterEvent.getValue() == "close":
106 from Screens.MessageBox import MessageBox
107 if self.settings.afterEvent.getValue() == "deepstandby":
108 if not Screens.Standby.inTryQuitMainloop:
109 Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A sleep timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
110 elif self.settings.afterEvent.getValue() == "standby":
111 if not Screens.Standby.inStandby:
112 Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A sleep timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
114 def sendStandbyNotification(self, answer):
116 Notifications.AddNotification(Screens.Standby.Standby)
118 def sendTryQuitMainloopNotification(self, answer):
120 Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)