1 from Plugins.Plugin import PluginDescriptor
3 from Screens.Screen import Screen
4 from Screens.InfoBar import InfoBar
5 from Screens.ChoiceBox import ChoiceBox
6 from Screens.MessageBox import MessageBox
7 from Screens.InfoBarGenerics import InfoBarNotifications
8 from Screens.VirtualKeyBoard import VirtualKeyBoard
10 from Components.PluginComponent import plugins
11 from Components.Button import Button
12 from Components.Label import Label
13 from Components.Sources.StaticText import StaticText
14 from Components.ActionMap import NumberActionMap, ActionMap
15 from Components.ServiceEventTracker import ServiceEventTracker
16 from Components.MenuList import MenuList
17 from Components.Label import Label, MultiColorLabel
18 from Components.ConfigList import ConfigListScreen
19 from Components.config import config, ConfigSubsection, ConfigPosition, getConfigListEntry, ConfigBoolean, ConfigInteger, ConfigText, ConfigSelection, configfile, getCharValue
21 from enigma import eTimer, eConsoleAppContainer, getDesktop, eServiceReference, iPlayableService, iServiceInformation, RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_HALIGN_CENTER, RT_VALIGN_CENTER, getPrevAsciiCode, eRCInput, fbClass
23 import os, struct, threading, stat, select, time, socket, select
25 strIsEmpty = lambda x: x is None or len(x) == 0
27 HBBTVAPP_PATH = "/usr/local/hbb-browser"
28 COMMAND_PATH = '/tmp/.sock.hbbtv.cmd'
36 channel_info_sid = None
37 channel_info_onid = None
38 channel_info_tsid = None
39 channel_info_name = None
40 channel_info_orgid = None
46 packet_hl = struct.calcsize(packet_h)
47 __gval__ = GlobalValues()
49 def getPacketHeaders():
51 return (__gval__.packet_m, __gval__.packet_h, __gval__.packet_hl)
53 def setChannelInfo(sid, onid, tsid, name, orgid):
54 if sid is None: sid = 0;
55 if onid is None: onid = 0;
56 if tsid is None: tsid = 0;
57 if name is None: name = "";
58 if orgid is None: orgid = 0;
60 __gval__.channel_info_sid = sid
61 __gval__.channel_info_onid = onid
62 __gval__.channel_info_tsid = tsid
63 __gval__.channel_info_name = name
64 __gval__.channel_info_orgid = orgid
65 print "Set Channel Info >> sid : %X, onid : %X, tsid : %X, name : %s, orgid : %d " % (sid, onid, tsid, name, orgid)
66 def getChannelInfos():
68 print "Get Channel Info >> sid : %X, onid : %X, tsid : %X, name : %s, orgid : %d " % (__gval__.channel_info_sid,
69 __gval__.channel_info_onid, __gval__.channel_info_tsid, __gval__.channel_info_name, __gval__.channel_info_orgid)
70 return (__gval__.channel_info_sid,
71 __gval__.channel_info_onid,
72 __gval__.channel_info_tsid,
73 __gval__.channel_info_name,
74 __gval__.channel_info_orgid)
78 return __gval__.command_util
79 def getCommandServer():
81 return __gval__.command_server
83 def setBeforeService(s):
85 __gval__.before_service = s
86 def getBeforeService():
88 return __gval__.before_service
90 def _unpack(packed_data):
91 (mg, h, hlen) = getPacketHeaders()
93 if strIsEmpty(packed_data):
95 (m, o, l, s) = struct.unpack(h, packed_data[:hlen])
100 d = packed_data[hlen:hlen+l]
103 def _pack(opcode, params=None, reserved=0):
104 (m, h, hlen) = getPacketHeaders()
105 if strIsEmpty(params):
107 packed_data = struct.pack(h, m, opcode, len(params), reserved)
108 return packed_data + params
114 ,'User-Agent: NSPlayer/7.10.0.3059 '
116 ,'Connection: Close '
121 for m in self.headers:
122 self.sendmsg += m + '\n'
123 self.sendmsg += '\n\n'
125 def request(self, host, port=80, location='/'):
126 sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
127 sock.connect((host, port))
128 sock.send(self.sendmsg%(location, host))
130 print self.sendmsg%(location, host)
133 res = sock.recv(1024)
139 def parse(self, data):
140 for d in data.splitlines():
141 if d.startswith('Location: '):
145 def getLocationData(self, url):
146 url_list,host,location = None,None,None
148 url = url[url.find(':')+3:]
149 url_list = url.split('/')
151 location = url[len(url_list[0]):]
152 except Exception, err_msg:
155 html = self.request(host=host, location=location)
156 return self.parse(html)
161 "OP_UNKNOWN" : 0x0000
162 ,"OP_HBBTV_EXIT" : 0x0001
163 ,"OP_HBBTV_OPEN_URL" : 0x0002
164 ,"OP_HBBTV_LOAD_AIT" : 0x0003
165 ,"OP_HBBTV_UNLOAD_AIT" : 0x0004
166 ,"OP_HBBTV_FULLSCREEN" : 0x0005
167 ,"OP_HBBTV_TITLE" : 0x0006
168 ,"OP_OIPF_GET_CHANNEL_INFO_URL" : 0x0101
169 ,"OP_OIPF_GET_CHANNEL_INFO_AIT" : 0x0102
170 ,"OP_OIPF_GET_CHANNEL_INFO_LIST": 0x0103
171 ,"OP_VOD_URI" : 0x0201
172 ,"OP_VOD_PLAY" : 0x0202
173 ,"OP_VOD_STOP" : 0x0203
174 ,"OP_VOD_PAUSE" : 0x0204
175 ,"OP_VOD_STATUS" : 0x0205
176 ,"OP_VOD_FORBIDDEN" : 0x0206
177 ,"OP_BROWSER_OPEN_URL" : 0x0301
180 0x0000 : "OP_UNKNOWN"
181 ,0x0001 : "OP_HBBTV_EXIT"
182 ,0x0002 : "OP_HBBTV_OPEN_URL"
183 ,0x0003 : "OP_HBBTV_LOAD_AIT"
184 ,0x0004 : "OP_HBBTV_UNLOAD_AIT"
185 ,0x0005 : "OP_HBBTV_FULLSCREEN"
186 ,0x0006 : "OP_HBBTV_TITLE"
187 ,0x0101 : "OP_OIPF_GET_CHANNEL_INFO_URL"
188 ,0x0102 : "OP_OIPF_GET_CHANNEL_INFO_AIT"
189 ,0x0103 : "OP_OIPF_GET_CHANNEL_INFO_LIST"
190 ,0x0201 : "OP_VOD_URI"
191 ,0x0202 : "OP_VOD_PLAY"
192 ,0x0203 : "OP_VOD_STOP"
193 ,0x0204 : "OP_VOD_PAUSE"
194 ,0x0205 : "OP_VOD_STATUS"
195 ,0x0206 : "OP_VOD_FORBIDDEN"
196 ,0x0301 : "OP_BROWSER_OPEN_URL"
199 def get(self, opstr):
201 return self._opcode_[opstr]
203 return self._opcode_["OP_UNKNOWN"]
205 def what(self, opcode):
207 return self._opstr_[opcode]
209 return self._opstr_["0x0000"]
222 def __init__(self, params):
223 self._protocol = params.protocol
224 self._type = params.type
225 self._addr = params.addr
226 self._buf_size = params.buf_size
227 self._handler = params.handler
228 self._timeout = params.timeout
229 self._destroy = params.destroy
231 self._terminated = False
232 self._server_thread = None
234 self.onHbbTVCloseCB = []
235 self.onSetPageTitleCB = []
238 if self._destroy is not None:
239 self._destroy(self._addr)
242 self._terminated = True
243 if self._server_thread is not None:
244 self._server_thread.join()
245 self._server_thread = None
248 self._socket = socket.socket(self._protocol, self._type)
249 self._socket.settimeout(self._timeout)
250 self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
251 self._socket.bind(self._addr)
252 self._socket.listen(True)
254 self._server_thread = threading.Thread(target=self._listen)
255 self._server_thread.start()
258 select_list = [self._socket]
261 conn, addr = self._socket.accept()
262 self._client(conn, addr)
263 except Exception, ErrMsg:
264 print "ServerSocket Error >>", ErrMsg
267 while not self._terminated:
268 readable, writable, errored = select.select(select_list, [], [], self._timeout)
270 if s is self._socket:
273 def _client(self, conn, addr):
276 received_data = conn.recv(self._buf_size)
277 if self._handler is not None and not strIsEmpty(received_data):
278 send_data = self._handler.doHandle(received_data, self.onHbbTVCloseCB, self.onSetPageTitleCB)
279 self._send(conn, send_data)
280 except Exception, ErrMsg:
283 if self._handler is not None:
284 self._handler.printError(ErrMsg)
285 def _send(self, conn, data) :
290 def doListenUnixTCP(self, name, handler):
292 if os.path.exists(name):
294 print "Removed ", name
297 params = SocketParams()
298 params.protocol = socket.AF_UNIX
299 params.type = socket.SOCK_STREAM
301 params.handler = handler
302 params.destroy = destroy
304 streamServer = StreamServer(params)
308 def doListenInetTCP(self, ip, port, handler):
309 print "not implemented yet!!"
310 def doListenUnixDGRAM(self, name, handler):
311 print "not implemented yet!!"
312 def doListenInetDGRAM(self, ip, port, handler):
313 print "not implemented yet!!"
316 def doUnpack(self, data):
319 def doPack(self, opcode, params, reserved=0):
320 return _pack(opcode, params, reserved)
322 def doHandle(self, data, onCloseCB):
323 opcode, params = 0x0, 'Invalid Request!!'
324 return _pack(opcode, params)
326 def printError(self, reason):
329 class BrowserCommandUtil(OpCodeSet):
332 OpCodeSet.__init__(self)
334 def isConnected(self):
339 def doConnect(self, filename):
340 if not os.path.exists(filename):
341 print "file not exists :", filename
344 self._fd = os.open(filename, os.O_WRONLY|os.O_NONBLOCK)
346 print "fail to open file :", filename
348 except Exception, ErrMsg:
352 print "connected!! to ", filename
355 def doDisconnect(self):
361 def doSend(self, command, params=None, reserved=0):
363 print "connected pipe was not exists!!"
367 data = _pack(self.get(command), params, reserved)
370 os.write(self._fd, data)
371 print "Send OK!! :", command
375 def sendCommand(self, command, params=None, reserved=0):
376 if not self.isConnected():
378 self.doConnect(COMMAND_PATH)
379 result = self.doSend(command, params, reserved)
383 class HandlerHbbTV(Handler):
385 def __init__(self, session):
386 self._session = session
387 self.opcode = OpCodeSet()
389 0x0001 : self._cb_handleCloseHbbTVBrowser
390 ,0x0006 : self._cb_handleSetPageTitle
391 ,0x0101 : self._cb_handleGetChannelInfoForUrl
392 ,0x0102 : self._cb_handleGetChannelInfoForAIT
393 ,0x0103 : self._cb_handleGetChannelInfoList
394 ,0x0201 : self._cb_handleVODPlayerURI
395 ,0x0202 : self._cb_handleVODPlayerPlay
396 ,0x0203 : self._cb_handleVODPlayerStop
397 ,0x0204 : self._cb_handleVODPlayerPlayPause
399 self._on_close_cb = None
400 self._on_set_title_cb = None
404 def _handle_dump(self, handle, opcode, data=None):
408 print " - opcode : ", self.opcode.what(opcode)
410 print " - data : ", data
412 def doHandle(self, data, onCloseCB, onSetPageTitleCB):
413 opcode, params, reserved = None, None, 0
414 self._on_close_cb = onCloseCB
415 self._on_set_title_cb = onSetPageTitleCB
417 datas = self.doUnpack(data)
418 except Exception, ErrMsg:
419 print "Unpacking packet ERR :", ErrMsg
420 params = 'fail to unpack packet!!'
421 opcode = self.opcode.get("OP_UNKNOWN")
422 return self.doPack(opcode, params)
426 self.opcode.what(opcode)
429 #print self.handle_map[opcode]
430 (reserved, params) = self.handle_map[opcode](opcode, params)
431 except Exception, ErrMsg:
432 print "Handling packet ERR :", ErrMsg
433 params = 'fail to handle packet!!'
434 opcode = self.opcode.get("OP_UNKNOWN")
435 return self.doPack(opcode, params)
436 self._on_close_cb = None
437 self._on_set_title_cb = None
438 return self.doPack(opcode, params, reserved)
440 def _cb_handleGetChannelInfoForUrl(self, opcode, data):
441 self._handle_dump(self._cb_handleGetChannelInfoForUrl, opcode, data)
442 (sid, onid, tsid, name, orgid) = getChannelInfos()
444 return (0, struct.pack('!IIII', sid, onid, tsid, namelen) + name)
446 def _cb_handleGetChannelInfoForAIT(self, opcode, data):
447 self._handle_dump(self._cb_handleGetChannelInfoForAIT, opcode, data)
448 (sid, onid, tsid, name, orgid) = getChannelInfos()
450 return (0, struct.pack('!IIIII', orgid, sid, onid, tsid, namelen) + name)
452 def _cb_handleGetChannelInfoList(self, opcode, data):
453 self._handle_dump(self._cb_handleGetChannelInfoList, opcode, data)
454 (sid, onid, tsid, name, orgid) = getChannelInfos()
456 channel_list_size = 1
457 return (channel_list_size, struct.pack('!IIII', sid, onid, tsid, namelen) + name)
459 def _cb_handleSetPageTitle(self, opcode, data):
460 self._handle_dump(self._cb_handleCloseHbbTVBrowser, opcode, data)
461 if data.startswith('file://') or data.startswith('http://'):
463 if self._on_set_title_cb is not None:
464 for x in self._on_set_title_cb:
467 except Exception, ErrMsg:
468 if x in self._on_set_title_cb:
469 self._on_set_title_cb.remove(x)
472 def _cb_handleCloseHbbTVBrowser(self, opcode, data):
473 self._handle_dump(self._cb_handleCloseHbbTVBrowser, opcode, data)
475 if self._on_close_cb:
476 for x in self._on_close_cb:
479 except Exception, ErrMsg:
480 if x in self._on_close_cb:
481 self._on_close_cb.remove(x)
483 command_util = getCommandUtil()
484 command_util.sendCommand('OP_HBBTV_FULLSCREEN', None)
486 before_service = getBeforeService()
487 if before_service is not None:
488 self._session.nav.playService(before_service)
491 def _cb_handleVODPlayerURI(self, opcode, data):
493 hl = struct.calcsize('!II')
494 datas = struct.unpack('!II', data[:hl])
496 vodUri = data[hl:hl+uriLength]
497 self._handle_dump(self._cb_handleVODPlayerURI, opcode, vodUri)
498 self._vod_uri = vodUri
501 def doStop(self, restoreBeforeService=True, needStop=True):
503 self._session.nav.stopService()
504 if self._vod_service is not None and restoreBeforeService:
505 before_service = getBeforeService()
506 self._session.nav.playService(before_service)
508 self._vod_service = None
513 def doRetryOpen(self, url):
517 self._vod_service = None
519 print "try to open vod [%d] : %s" % (ii, url)
520 self._vod_service = eServiceReference(4097, 0, url)
521 self._session.nav.playService(self._vod_service)
522 if self._vod_service is not None:
524 except Exception, ErrMsg:
525 print "OpenVOD ERR :", ErrMsg
529 def _cb_handleVODPlayerPlay(self, opcode, data):
530 self._handle_dump(self._cb_handleVODPlayerPlay, opcode, data)
531 self.doStop(restoreBeforeService=False)
532 if self.doRetryOpen(url=self._vod_uri) == False:
536 def _cb_handleVODPlayerStop(self, opcode, data):
537 self._handle_dump(self._cb_handleVODPlayerStop, opcode, data)
541 def _cb_handleVODPlayerPlayPause(self, opcode, data):
542 self._handle_dump(self._cb_handleVODPlayerPlayPause, opcode, data)
543 service = self._session.nav.getCurrentService()
546 servicePause = service.pause()
548 servicePause.unpause()
549 elif pauseFlag == 'P':
551 except Exception, ErrMsg:
552 print "onPause ERR :", ErrMsg
555 class HbbTVWindow(Screen, InfoBarNotifications):
557 <screen name="HbbTVWindow" position="0,0" size="1280,720" backgroundColor="transparent" flags="wfNoBorder" title="HbbTV Plugin">
560 def __init__(self, session, url=None, cbf=None, useAIT=False):
561 self._session = session
562 eRCInput.getInstance().lock()
564 Screen.__init__(self, session)
565 InfoBarNotifications.__init__(self)
566 self.__event_tracker = ServiceEventTracker(screen = self, eventmap = {
567 iPlayableService.evUser+20: self._serviceForbiden,
571 self._use_ait = useAIT
572 self._cb_closed_func = cbf
573 self.onLayoutFinish.append(self._layoutFinished)
575 command_server = getCommandServer()
576 if self._cb_set_page_title not in command_server.onSetPageTitleCB:
577 command_server.onSetPageTitleCB.append(self._cb_set_page_title)
579 if self._cb_close_window not in command_server.onHbbTVCloseCB:
580 command_server.onHbbTVCloseCB.append(self._cb_close_window)
582 self._closeTimer = eTimer()
583 self._closeTimer.callback.append(self._do_close)
585 def _layoutFinished(self):
586 command_util = getCommandUtil()
587 (sid, onid, tsid, name, orgid) = getChannelInfos()
588 params = struct.pack('!IIIII', orgid, sid, onid, tsid, len(name)) + name
590 command_util.sendCommand('OP_HBBTV_UNLOAD_AIT')
592 command_util.sendCommand('OP_HBBTV_LOAD_AIT', params, 1)
594 command_util.sendCommand('OP_HBBTV_LOAD_AIT', params)
596 command_util.sendCommand('OP_HBBTV_OPEN_URL', self._url)
598 def _cb_close_window(self):
599 self._closeTimer.start(1000)
602 self._closeTimer.stop()
603 command_server = getCommandServer()
605 if self._cb_set_page_title in command_server.onSetPageTitleCB:
606 command_server.onSetPageTitleCB.remove(self._cb_set_page_title)
607 except Exception, ErrMsg: pass
609 if self._cb_close_window in command_server.onHbbTVCloseCB:
610 command_server.onHbbTVCloseCB.remove(self._cb_close_window)
611 except Exception, ErrMsg: pass
613 if self._cb_closed_func is not None:
614 self._cb_closed_func()
616 eRCInput.getInstance().unlock()
619 def _serviceForbiden(self):
621 real_url = MMSStreamURL().getLocationData(__gval__.hbbtv_handelr.getUrl())
622 print "Received URI :\n",real_url
624 if real_url is not None:
625 __gval__.hbbtv_handelr.doRetryOpen(real_url.strip())
627 def _cb_set_page_title(self, title=None):
628 print "page title :",title
633 class HbbTVHelper(Screen):
634 skin = """<screen name="HbbTVHelper" position="0,0" size="0,0" backgroundColor="transparent" flags="wfNoBorder" title=" "></screen>"""
635 def __init__(self, session):
637 __gval__.hbbtv_handelr = HandlerHbbTV(session)
638 __gval__.command_server = ServerFactory().doListenUnixTCP('/tmp/.sock.hbbtv.url', __gval__.hbbtv_handelr)
644 Screen.__init__(self, session)
645 self._session = session
646 self._timer_infobar = eTimer()
647 self._timer_infobar.callback.append(self._cb_registrate_infobar)
648 self._timer_infobar.start(1000)
650 self._excuted_browser = False
652 __gval__.command_util = BrowserCommandUtil()
654 def _cb_registrate_infobar(self):
656 self._timer_infobar.stop()
657 if self._cb_ready_for_ait not in InfoBar.instance.onReadyForAIT:
658 InfoBar.instance.onReadyForAIT.append(self._cb_ready_for_ait)
659 if self._cb_hbbtv_activated not in InfoBar.instance.onHBBTVActivation:
660 InfoBar.instance.onHBBTVActivation.append(self._cb_hbbtv_activated)
662 def _cb_ready_for_ait(self, orgId=0):
664 if not self._excuted_browser:
665 command_util = getCommandUtil()
666 command_util.sendCommand('OP_HBBTV_UNLOAD_AIT')
668 setChannelInfo(None, None, None, None, None)
670 service = self._session.nav.getCurrentService()
671 info = service and service.info()
673 sid = info.getInfo(iServiceInformation.sSID)
674 onid = info.getInfo(iServiceInformation.sONID)
675 tsid = info.getInfo(iServiceInformation.sTSID)
676 name = info.getName()
681 for x in info.getInfoObject(iServiceInformation.sHBBTVUrl):
685 setChannelInfo(sid, onid, tsid, name, orgid)
687 def _cb_hbbtv_activated(self, title=None, url=None):
688 if not self._is_browser_running():
689 message = "HbbTV Browser was not running.\nPlease running browser before start HbbTV Application."
690 self.session.open(MessageBox, message, MessageBox.TYPE_INFO)
692 service = self._session.nav.getCurrentlyPlayingServiceReference()
693 setBeforeService(service)
694 self._start_hbbtv_application(title, url)
696 def _start_hbbtv_application(self, title, url):
697 tmp_url = self.getStartHbbTVUrl()
701 print "can't get url of hbbtv!!"
703 print "success to get url of hbbtv!! >>", url
704 if self._excuted_browser:
705 print "already excuted opera browser!!"
712 if tmp_url == url and control_code == 1:
714 self._excuted_browser = True
715 self._session.open(HbbTVWindow, url, self._cb_closed_browser, use_ait)
717 def _cb_closed_browser(self):
718 self._excuted_browser = False
720 def _start_opera(self):
721 if not self._is_browser_running():
723 start_command = '%s/launcher start'%(HBBTVAPP_PATH)
724 os.system(start_command)
726 def _stop_opera(self):
728 try: os.system('%s/launcher stop'%(HBBTVAPP_PATH))
731 def getStartHbbTVUrl(self):
732 url, self._urls = None, None
733 service = self._session.nav.getCurrentService()
734 info = service and service.info()
735 if not info: return None
736 self._urls = info.getInfoObject(iServiceInformation.sHBBTVUrl)
738 if u[0] == 1: # 0:control code, 1:name, 2:url, 3:orgid, 4:appid
741 url = info.getInfoString(iServiceInformation.sHBBTVUrl)
744 def showApplicationSelectionBox(self):
746 if self.getStartHbbTVUrl():
748 applications.append((x[1], x))
749 else: applications.append(("No detected HbbTV applications.", None))
750 self._session.openWithCallback(self._application_selected, ChoiceBox, title=_("Please choose an HbbTV application."), list=applications)
752 def _application_selected(self, selected):
754 if selected[1] is None: return
755 self._cb_hbbtv_activated(selected[1][1], selected[1][2])
756 except Exception, ErrMsg: print ErrMsg
758 def showBrowserConfigBox(self):
760 if self._is_browser_running():
761 start_stop_mode.append(('Stop',None))
762 else: start_stop_mode.append(('Start',None))
763 self._session.openWithCallback(self._browser_config_selected, ChoiceBox, title=_("Please choose one."), list=start_stop_mode)
765 def _browser_config_selected(self, selected):
771 if not self._is_browser_running():
775 except Exception, ErrMsg: print "Config ERR :", ErrMsg
777 def _is_browser_running(self):
780 ret = os.popen('%s/launcher check'%(HBBTVAPP_PATH)).read()
781 return ret.strip() != "0"
782 except Exception, ErrMsg:
783 print "Check Browser Running ERR :", ErrMsg
787 class OperaBrowser(Screen):
788 MENUBAR_ITEM_WIDTH = 150
789 MENUBAR_ITEM_HEIGHT = 30
790 SUBMENULIST_WIDTH = 200
791 SUBMENULIST_HEIGHT = 25
795 <screen name="Opera Browser" position="0,0" size="1280,720" backgroundColor="transparent" flags="wfNoBorder" title="Opera Browser">
796 <widget name="topArea" zPosition="-1" position="0,0" size="1280,60" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" />
797 <widget name="menuitemFile" position="30,20" size="150,30" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" foregroundColors="#9f1313,#a08500" />
798 <widget name="menuitemHelp" position="180,20" size="150,30" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" foregroundColors="#9f1313,#a08500" />
799 <widget name="menulist" position="50,%d" size="%d,150" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
800 <widget name="submenulist" position="%d,%d" size="%d,150" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
801 <widget name="bottomArea" position="0,640" size="1280,80" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" />
803 """ % (MENUBAR_ITEM_HEIGHT+30, SUBMENULIST_WIDTH, SUBMENULIST_WIDTH+50+SUBMENULIST_NEXT, MENUBAR_ITEM_HEIGHT+30, SUBMENULIST_WIDTH)
805 MENUITEMS_LIST =[[('Open Location', None), ('Start/Stop',None), ('Exit', None)],
807 def __init__(self, session):
808 Screen.__init__(self, session)
810 self["actions"] = ActionMap(["MinuteInputActions", "ColorActions", "InputActions", "InfobarChannelSelection", "EPGSelectActions", "KeyboardInputActions"], {
811 "cancel" : self.keyCancel
813 ,"left" : self.keyLeft
814 ,"right" : self.keyRight
816 ,"down" : self.keyDown
817 ,"menu" : self.keyCancel
820 self.menubarCurrentIndex = 0
821 self.lvMenuItems = []
822 self.lvSubMenuItems = []
824 self["topArea"] = Label()
825 self["bottomArea"] = Label()
827 self["menuitemFile"] = MultiColorLabel()
828 self["menuitemHelp"] = MultiColorLabel()
830 self["menulist"] = MenuList(self.setListOnView())
831 self["submenulist"] = MenuList(self.setSubListOnView())
833 self.toggleMainScreenFlag = True
834 self.toggleListViewFlag = False
835 self.toggleSubListViewFlag = False
836 self.currentListView = self["menulist"]
838 self.onLayoutFinish.append(self.layoutFinished)
840 self._onCloseTimer = eTimer()
841 self._onCloseTimer.callback.append(self._cb_onClose)
843 def enableRCMouse(self, mode): #mode=[0|1]|[False|True]
844 rcmouse_path = "/proc/stb/fp/mouse"
845 if os.path.exists(rcmouse_path):
846 os.system("echo %d > %s" % (mode, rcmouse_path))
848 def layoutFinished(self):
849 self["menuitemFile"].setText("File")
850 self["menuitemHelp"].setText("Help")
852 self["menulist"].hide()
853 self["submenulist"].hide()
855 self["bottomArea"].setText("Opera Web Browser Plugin v0.1")
856 self.setTitle("BrowserMain")
857 self.selectMenuitem()
859 def selectMenuitem(self):
860 tmp = [self["menuitemFile"], self["menuitemHelp"]]
861 self["menuitemFile"].setForegroundColorNum(0)
862 self["menuitemHelp"].setForegroundColorNum(0)
863 tmp[self.menubarCurrentIndex].setForegroundColorNum(1)
865 def popupCloseAll(self):
871 def setListOnView(self):
872 self.lvMenuItems = self.MENUITEMS_LIST[self.menubarCurrentIndex]
873 return self.lvMenuItems
875 def setSubListOnView(self):
876 self.lvSubMenuItems = []
877 xl = self["menulist"].getCurrent()[1]
878 if xl is None: return []
880 self.lvSubMenuItems.append((x,None))
881 return self.lvSubMenuItems
883 def toggleMainScreen(self):
884 if not self.toggleMainScreenFlag:
887 self.toggleMainScreenFlag = not self.toggleMainScreenFlag
889 def toggleListView(self):
890 if not self.toggleListViewFlag:
891 self["menulist"].show()
892 else: self["menulist"].hide()
893 self.toggleListViewFlag = not self.toggleListViewFlag
895 def toggleSubListView(self):
896 if not self.toggleSubListViewFlag:
897 self["submenulist"].show()
898 else: self["submenulist"].hide()
899 self.toggleSubListViewFlag = not self.toggleSubListViewFlag
901 def setCurrentListView(self, listViewIdx):
903 self.currentListView = None
904 elif listViewIdx == 1:
905 self.currentListView = self["menulist"]
906 elif listViewIdx == 2:
907 self.currentListView = self["submenulist"]
909 def _cb_onClose(self):
910 self._onCloseTimer.stop()
911 command_server = getCommandServer()
913 if self._on_close_window in command_server.onHbbTVCloseCB:
914 command_server.onHbbTVCloseCB.remove(self._on_close_window)
915 except Exception, ErrMsg: pass
917 if self._on_setPageTitle in command_server.onSetPageTitleCB:
918 command_server.onSetPageTitleCB.remove(self._on_setPageTitle)
919 except Exception, ErrMsg: pass
920 self._on_setPageTitle('Opera Browser')
921 self.enableRCMouse(False)
922 self.toggleMainScreen()
923 eRCInput.getInstance().unlock()
925 def _on_setPageTitle(self, title=None):
926 print "page title :",title
931 def cbUrlText(self, data=None):
932 print "Inputed Url :", data
935 command_server = getCommandServer()
936 if self._on_setPageTitle not in command_server.onSetPageTitleCB:
937 command_server.onSetPageTitleCB.append(self._on_setPageTitle)
938 if self._on_close_window not in command_server.onHbbTVCloseCB:
939 command_server.onHbbTVCloseCB.append(self._on_close_window)
940 self.toggleMainScreen()
941 self.enableRCMouse(True)
942 eRCInput.getInstance().lock()
943 command_util = getCommandUtil()
944 command_util.sendCommand('OP_BROWSER_OPEN_URL', data)
946 def _on_close_window(self):
947 self._onCloseTimer.start(1000)
949 def _cmd_on_OpenLocation(self):
951 if not _g_helper._is_browser_running():
952 message = "Opera Browser was not running.\nPlease running browser using [File]>[Start/Stop] menu."
953 self.session.open(MessageBox, message, MessageBox.TYPE_INFO)
955 self.session.openWithCallback(self.cbUrlText, VirtualKeyBoard, title=("Please enter URL here"), text='http://')
956 def _cmd_on_About(self):
957 self.session.open(MessageBox, 'Opera Web Browser Plugin v0.1(beta)', type = MessageBox.TYPE_INFO)
958 def _cmd_on_Exit(self):
960 def _cmd_on_StartStop(self):
962 if _g_helper is None:
964 _g_helper.showBrowserConfigBox()
965 def doCommand(self, command):
967 'Exit' :self._cmd_on_Exit
968 ,'About' :self._cmd_on_About
969 ,'Open Location' :self._cmd_on_OpenLocation
970 ,'Start/Stop' :self._cmd_on_StartStop
977 if not self.toggleListViewFlag:
980 if self.currentListView.getCurrent()[1] is None:
981 self.doCommand(self.currentListView.getCurrent()[0])
982 #self.session.open(MessageBox, _(self.currentListView.getCurrent()[0]), type = MessageBox.TYPE_INFO)
986 def updateSelectedMenuitem(self, status):
987 if self.menubarCurrentIndex == 0 and status < 0:
988 self.menubarCurrentIndex = 1
989 elif self.menubarCurrentIndex == 1 and status > 0:
990 self.menubarCurrentIndex = 0
991 else: self.menubarCurrentIndex += status
992 self.selectMenuitem()
995 if not self.toggleMainScreenFlag:
997 if not self.toggleListViewFlag:
998 self.updateSelectedMenuitem(-1)
1000 if self.toggleSubListViewFlag:
1001 self.setCurrentListView(1)
1002 self.toggleSubListView()
1004 if self.currentListView.getSelectedIndex():
1005 self.currentListView.pageUp()
1008 if not self.toggleMainScreenFlag:
1010 if not self.toggleListViewFlag:
1011 self.updateSelectedMenuitem(1)
1013 if self.currentListView is None:
1015 if self.currentListView.getCurrent()[1] is not None:
1016 parentSelectedIndex = self.currentListView.getSelectedIndex()
1017 self.setCurrentListView(2)
1018 self.currentListView.setList(self.setSubListOnView())
1019 self.currentListView.resize(self.SUBMENULIST_WIDTH, self.SUBMENULIST_HEIGHT*len(self.lvSubMenuItems)+5)
1020 self.currentListView.move(self.MENUBAR_ITEM_WIDTH*self.menubarCurrentIndex + self.SUBMENULIST_WIDTH+self.SUBMENULIST_NEXT + 50,self.MENUBAR_ITEM_HEIGHT+30+(parentSelectedIndex*self.SUBMENULIST_HEIGHT))
1021 self.toggleSubListView()
1024 if not self.toggleMainScreenFlag:
1026 if self.currentListView is None:
1028 if not self.toggleListViewFlag:
1029 self.currentListView.setList(self.setListOnView())
1030 self.currentListView.resize(self.SUBMENULIST_WIDTH, self.SUBMENULIST_HEIGHT*len(self.lvMenuItems)+5)
1031 self.currentListView.move(self.MENUBAR_ITEM_WIDTH*self.menubarCurrentIndex+1+ 50,self.MENUBAR_ITEM_HEIGHT+30)
1032 self.toggleListView()
1034 self.currentListView.down()
1037 if not self.toggleMainScreenFlag:
1039 if self.currentListView is None:
1041 if self.currentListView == self["menulist"]:
1042 if self.currentListView.getSelectedIndex() == 0:
1043 self.toggleListView()
1045 self.currentListView.up()
1047 def keyCancel(self):
1048 self.toggleMainScreen()
1050 def auto_start_main(reason, **kwargs):
1052 command_server = getCommandServer()
1053 command_server.stop()
1055 def session_start_main(session, reason, **kwargs):
1057 _g_helper = session.open(HbbTVHelper)
1059 def plugin_start_main(session, **kwargs):
1060 session.open(OperaBrowser)
1062 def plugin_extension_start_application(session, **kwargs):
1064 if _g_helper is None:
1066 _g_helper.showApplicationSelectionBox()
1068 def plugin_extension_browser_config(session, **kwargs):
1070 if _g_helper is None:
1072 _g_helper.showBrowserConfigBox()
1074 def Plugins(path, **kwargs):
1076 PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=auto_start_main),
1077 PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, needsRestart=True, fnc=session_start_main, weight=-10),
1078 PluginDescriptor(name="HbbTV Applications", where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=plugin_extension_start_application),
1079 PluginDescriptor(name="Browser Start/Stop", where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=plugin_extension_browser_config),
1080 PluginDescriptor(name="Opera Web Browser", description="start opera web browser", where=PluginDescriptor.WHERE_PLUGINMENU, needsRestart=True, fnc=plugin_start_main)