2 from Components.Sources.Source import Source
3 from Screens.MessageBox import MessageBox
7 class Message( Source):
10 yesnoFile = "/tmp/yesno"
12 def __init__(self,session, func = PRINT):
14 self.session = session
18 error = "unknown command (%s)" % func
19 self.result = [[False,error]]
21 def handleCommand(self,cmd):
23 if self.func is self.PRINT:
24 self.result = self.printMessage(cmd)
25 elif self.func is self.ANSWER:
26 self.result = self.getYesNoAnswer(cmd)
28 def printMessage(self,param):
31 if self.cmd['text'] == "" or self.cmd['text'] is None:
32 return [[False,"no text for message"]]
34 mtext = self.cmd['text']
37 typeint = int(self.cmd['type'])
39 return [[False,"type %s is not a number"%self.cmd['type']]]
41 if typeint == MessageBox.TYPE_YESNO:
42 #dont know how to give the result to the webif back
43 mtype= MessageBox.TYPE_YESNO
44 elif typeint == MessageBox.TYPE_INFO:
45 mtype= MessageBox.TYPE_INFO
46 elif typeint == MessageBox.TYPE_WARNING:
47 mtype= MessageBox.TYPE_WARNING
48 elif typeint == MessageBox.TYPE_ERROR:
49 mtype= MessageBox.TYPE_ERROR
51 return [[False,"unsupported type %s"%self.cmd['type']]]
54 mtimeout = int(self.cmd['timeout'])
58 if typeint == MessageBox.TYPE_YESNO:
59 self.session.openWithCallback(self.yesNoAnswer, MessageBox, mtext, type = mtype, timeout = mtimeout)
61 self.session.open(MessageBox, mtext, type = mtype ,timeout = mtimeout)
63 return [[True,"message send successfully! it appears on TV-Screen"]]
65 def yesNoAnswer(self, confirmed):
66 print "yesNoAnswer",confirmed
67 #self.session.messageboxanswer = confirmed
69 yesnoFile = self.yesnoFile
71 cmdstr = "/bin/echo -n yes > %s" % yesnoFile
73 cmdstr = "/bin/echo -n no > %s" % yesnoFile
77 def getYesNoAnswer(self,param):
78 print "getYesNoAnswer"#,self.session.messageboxanswer
79 yesnoFile = self.yesnoFile
80 if os.path.exists(yesnoFile) == True:
81 file = open(yesnoFile, "r")
82 lines = file.readlines()
84 cmdstr = "rm %s" % yesnoFile
86 print "Answer: (%s)"%lines[0]
88 return [[True,"Answer is YES!"]]
90 return [[True,"Answer is NO!"]]
92 return [[False,"No answer yet"]]
94 # if self.session.messageboxanswer == True:
95 # self.session.messageboxanswer = None
96 # return [[True,"Answer is YES!"]]
98 # self.session.messageboxanswer = None
99 # return [[True,"Answer is NO!"]]
101 def getResults(self):
104 list = property(getResults)