from . import _, PLUGIN_NAME, PLUGIN_VERSION from Screens.Screen import Screen from Components.ActionMap import ActionMap, HelpableActionMap from Screens.MessageBox import MessageBox from Components.VideoWindow import VideoWindow from Components.Sources.List import List from Components.Label import Label from Components.MenuList import MenuList from Screens.ChannelSelection import ChannelSelectionBase from enigma import ePoint, eSize, eServiceCenter, getBestPlayableServiceReference, eTimer, eServiceReference from Screens.ChoiceBox import ChoiceBox from Screens.VirtualKeyBoard import VirtualKeyBoard from Screens.HelpMenu import HelpableScreen from Components.config import config, ConfigSubsection, ConfigNumber from Components.Slider import Slider from Components.SystemInfo import BoxInfo from ServiceReference import ServiceReference import Screens.InfoBar import Components.ServiceEventTracker import pickle import os config.plugins.quadpip = ConfigSubsection() config.plugins.quadpip.lastchannel = ConfigNumber(default=1) ENABLE_QPIP_PROCPATH = "/proc/stb/video/decodermode" def setDecoderMode(value): if os.access(ENABLE_QPIP_PROCPATH, os.F_OK): open(ENABLE_QPIP_PROCPATH, "w").write(value) return open(ENABLE_QPIP_PROCPATH, "r").read().strip() == value class QuadPipChannelEntry: def __init__(self, name, idx, ch1, ch2, ch3, ch4): self.name = name self.idx = idx self.channel = {"1": ch1, "2": ch2, "3": ch1, "4": ch1, } def __str__(self): return "idx : %d, name : %s, ch0 : %s, ch1 : %s, ch2 : %s, ch3 : %s" % (self.idx, self.name, self.channel.get("1"), self.channel.get("2"), self.channel.get("3"), self.channel.get("4")) def __cmp__(self, other): return self.idx - other.idx def __lt__(self, other): return self.idx < other.idx def getName(self): return self.name def getIndex(self): return self.idx def setChannel(self, idx, chName, sref): if idx in self.channel: self.channel[idx] = (chName, sref) return True return False def deleteChannel(self, idx): if idx in self.channel: self.channel[idx] = None return True return False def getChannel(self, idx): return self.channel.get(idx, None) def getChannelName(self, idx): chName = None ch = self.getChannel(idx) if ch: chName = ch[0] if chName is None: chName = _(" ") return chName def getChannelSref(self, idx): chSref = None ch = self.getChannel(idx) if ch: chSref = ch[1] return chSref def setIndex(self, idx): self.idx = idx def setName(self, name): self.name = name class QuadPipChannelData: def __init__(self): self.PipChannelList = [] self.pipChannelDataPath = "/etc/enigma2/quadPipChannels.dat" self.dataLoad() def dataSave(self): fd = open(self.pipChannelDataPath, "wb") pickle.dump(self.PipChannelList, fd) fd.close() def dataLoad(self): if not os.access(self.pipChannelDataPath, os.R_OK): return fd = open(self.pipChannelDataPath, "rb") self.PipChannelList = pickle.load(fd) fd.close() def getPipChannels(self): return self.PipChannelList def length(self): return len(self.PipChannelList) class QuadPipChannelList(QuadPipChannelData): def __init__(self): QuadPipChannelData.__init__(self) self._curIdx = config.plugins.quadpip.lastchannel.value # starting from 1 self.defaultEntryPreName = _("Quad PiP channel ") def saveAll(self): self.dataSave() config.plugins.quadpip.lastchannel.value = self._curIdx config.plugins.quadpip.lastchannel.save() def setIdx(self, value): if self._curIdx != value: self._curIdx = value config.plugins.quadpip.lastchannel.value = self._curIdx config.plugins.quadpip.lastchannel.save() def getIdx(self): return self._curIdx def getCurrentChannel(self): return self.getChannel(self._curIdx) def getChannel(self, idx): for ch in self.PipChannelList: if idx == ch.getIndex(): return ch return None def addNewChannel(self, newChannel): self.PipChannelList.append(newChannel) def removeChannel(self, _channel): if self.getIdx() == _channel.getIndex(): self.setIdx(0) # set invalid index self.PipChannelList.remove(_channel) def sortPipChannelList(self): self.PipChannelList.sort() newIdx = 1 for ch in self.PipChannelList: ch.setIndex(newIdx) chName = ch.getName() if chName.startswith(self.defaultEntryPreName): ch.setName("%s%d" % (self.defaultEntryPreName, ch.getIndex())) newIdx += 1 def getDefaultPreName(self): return self.defaultEntryPreName quad_pip_channel_list_instance = QuadPipChannelList() class CreateQuadPipChannelEntry(ChannelSelectionBase): skin_default_1080p = """ """ skin_default_720p = """ """ skin_default_576p = """ """ def __init__(self, session, defaultEntryName, channel=None): ChannelSelectionBase.__init__(self, session) self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "QuadPipChannelEditActions"], { "cancel": self.Exit, "ok": self.channelSelected, "toggleList": self.toggleCurrList, "editName": self.editEntryName, "up": self.goUp, "down": self.goDown, }, -1) self.session = session dh = self.session.desktop.size().height() self.skin = {1080: CreateQuadPipChannelEntry.skin_default_1080p, 720: CreateQuadPipChannelEntry.skin_default_720p, 576: CreateQuadPipChannelEntry.skin_default_576p}.get(dh, CreateQuadPipChannelEntry.skin_default_1080p) self.defaultEntryName = defaultEntryName self["textChannels"] = Label(" ") self["description"] = Label(" ") self.currList = None self.newChannel = channel self.descChannels = [] self.prepareChannels() self["selectedList"] = MenuList(self.descChannels, True) self.selectedList = self["selectedList"] self.onLayoutFinish.append(self.layoutFinished) def getMutableList(self, root=None): return None def layoutFinished(self): self.setTvMode() self.showFavourites() self.switchToServices() self.updateEntryName() def updateEntryName(self): self["textChannels"].setText("%s :" % self.newChannel.getName()) def editEntryName(self): self.session.openWithCallback(self.editEntryNameCB, VirtualKeyBoard, title=(_("Input channel name.")), text=self.newChannel.getName()) def editEntryNameCB(self, newName): if newName: self.newChannel.setName(newName) self.updateEntryName() def updateDescription(self): if self.currList == "channelList": desc = _("EPG key : Switch to quad PiP entry\nOk key : Add to new entry\nPVR key : Input channel name\nExit key : Finish channel edit") else: desc = _("EPG key : Switch to channel list\nOk key : Remove selected channel\nPVR key : Input channel name\nExit key : Finish channel edit") self["description"].setText(desc) def prepareChannels(self): if self.newChannel is None: self.newChannel = QuadPipChannelEntry(self.defaultEntryName, 99999, None, None, None, None) self.updateDescChannels() def updateDescChannels(self): self.descChannels = [] for idx in range(1, 5): sIdx = str(idx) _isEmpty = False chName = self.newChannel.getChannelName(sIdx) if chName is None: chName = _(" ") _isEmpty = True self.descChannels.append(("%d) %s" % (idx, chName), sIdx, _isEmpty)) def updateDescChannelList(self): self["selectedList"].setList(self.descChannels) def goUp(self): if self.currList == "channelList": self.servicelist.moveUp() else: self.selectedList.up() def goDown(self): if self.currList == "channelList": self.servicelist.moveDown() else: self.selectedList.down() def toggleCurrList(self): if self.currList == "channelList": self.switchToSelected() else: self.switchToServices() def switchToServices(self): self.servicelist.selectionEnabled(1) self.selectedList.selectionEnabled(0) self.currList = "channelList" self.updateDescription() def switchToSelected(self): self.servicelist.selectionEnabled(0) self.selectedList.selectionEnabled(1) self.currList = "selectedList" self.updateDescription() def channelSelected(self): if self.currList == "channelList": ref = self.getCurrentSelection() if (ref.flags & 7) == 7: self.enterPath(ref) elif not (ref.flags & eServiceReference.isMarker): ref = self.getCurrentSelection() sref = ref.toString() #if not sref.startswith("1:"): # return serviceName = ServiceReference(ref).getServiceName() or "n/a" _title = _('Choice where to put "%s"') % serviceName _list = [] for idx in range(1, 5): sIdx = str(idx) _isEmpty = False chName = self.newChannel.getChannelName(sIdx) _list.append((chName, sIdx, serviceName, sref, _isEmpty)) self.session.openWithCallback(self.choiceIdxCallback, ChoiceBox, title=_title, list=tuple(_list)) else: self.removeChannel() def choiceIdxCallback(self, answer): if answer is not None: (desc, sIdx, serviceName, sref, _isEmpty) = answer self.addChannel(sIdx, serviceName, sref) def addChannel(self, sIdx, serviceName, sref): if self.newChannel.setChannel(sIdx, serviceName, sref): self.updateDescChannels() self.updateDescChannelList() def removeChannel(self): cur = self.selectedList.getCurrent() if cur: sIdx = cur[1] if self.newChannel.deleteChannel(sIdx): self.updateDescChannels() self.updateDescChannelList() def getNewChannel(self): for idx in range(1, 5): sIdx = str(idx) ch = self.newChannel.getChannel(sIdx) if ch is not None: return self.newChannel return None def Exit(self): self.close(self.getNewChannel()) class QuadPiPChannelSelection(Screen, HelpableScreen): skin = """ {"template": [ MultiContentEntryText(pos = (%d, %d), size = (%d, %d), font=0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 0), MultiContentEntryText(pos = (%d, %d), size = (%d, %d), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 1), MultiContentEntryText(pos = (%d, %d), size = (%d, %d), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 2), MultiContentEntryText(pos = (%d, %d), size = (%d, %d), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 3), MultiContentEntryText(pos = (%d, %d), size = (%d, %d), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 4), ], "fonts": [gFont("Regular", %d), gFont("Regular", %d)], "itemHeight": %d } """ def __init__(self, session): self.session = session Screen.__init__(self, session) HelpableScreen.__init__(self) self.setTitle(_("Quad PiP Channel Selection")) dw = self.session.desktop.size().width() dh = self.session.desktop.size().height() pw, ph = {1080: ("center", "center"), 720: ("center", "center"), 576: ("center", "20%")}.get(dh, ("center", "center")) (sw, sh) = {1080: (dw / 3, dh / 2), 720: (int(dw / 2), int(dh / 1.5)), 576: (int(dw / 1.3), int(dh / 1.5))}.get(dh, (28, 24)) button_margin = 5 button_h = 40 list_y = 40 + button_margin * 3 self.fontSize = {1080: (28, 24), 720: (24, 20), 576: (20, 18)}.get(dh, (28, 24)) self.skin = QuadPiPChannelSelection.skin % (pw, ph, sw, sh + list_y, sw / 8 - 70, button_margin, sw / 8 - 70 + sw / 4, button_margin, sw / 8 - 70 + sw / 4 * 2, button_margin, sw / 8 - 70 + sw / 4 * 3, button_margin, sw / 8 - 70, button_margin, sw / 8 - 70 + sw / 4, button_margin, sw / 8 - 70 + sw / 4 * 2, button_margin, sw / 8 - 70 + sw / 4 * 3, button_margin, 0, list_y, sw, sh, sw / 16, 1, sw - sw / 16 * 2, sh / 13, sw / 11, 1 + sh / 13, sw - sw / 16 * 2 - sw / 8, sh / 18, sw / 11, 1 + sh / 13 + sh / 18, sw - sw / 16 * 2 - sw / 8, sh / 18, sw / 11, 1 + sh / 13 + sh / 18 * 2, sw - sw / 16 * 2 - sw / 8, sh / 18, sw / 11, 1 + sh / 13 + sh / 18 * 3, sw - sw / 16 * 2 - sw / 8, sh / 18, self.fontSize[0], self.fontSize[1], sh / 3) self["key_red"] = Label(_("Select")) self["key_green"] = Label(_("Add")) self["key_yellow"] = Label(_("Remove")) self["key_blue"] = Label(_("Edit")) self.PipChannelListApply = [] self["ChannelList"] = List(self.PipChannelListApply) self["qpipActions"] = HelpableActionMap(self, "QuadPipSetupActions", { "red": (self.keyRed, _("Select Quad Channels")), "green": (self.keyGreen, _("Add New Quad Channel Entry")), "yellow": (self.keyYellow, _("Remove Quad Channel Entry")), "blue": (self.keyBlue, _("Edit Quad Channel Entry")), }, -2) self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions", { "ok": (self.keyOk, _("Select Quad Channels")), "cancel": (self.keyCancel, _("Exit Quad Channel Selection")), }, -2) self.oldPosition = None global quad_pip_channel_list_instance self.qpipChannelList = quad_pip_channel_list_instance self.oldPosition = self.qpipChannelList.getIdx() - 1 self.force_exit = False self.onLayoutFinish.append(self.layoutFinishedCB) def layoutFinishedCB(self): self.updateDisplay() self.updatePosition() def keyOk(self): idx = self.getCurrentIndex() if idx != -1: self.qpipChannelList.setIdx(idx) self.close() def keyCancel(self): self.close(self.force_exit) def keyRed(self): self.keyOk() def keyGreen(self): self.session.openWithCallback(self.CreateQuadPipChannelEntryCB, CreateQuadPipChannelEntry, self.getDefaultEntryName(), None) def keyYellow(self): curChannel = self.getSelectedChannel() if curChannel: self.session.openWithCallback(self.removeCallback, MessageBox, _("Really delete this entry?")) def removeCallback(self, answer): curChannel = self.getSelectedChannel() if answer and curChannel: self.oldPosition = self["ChannelList"].getIndex() self.qpipChannelList.removeChannel(curChannel) self.force_exit = True self.updateChannelList() def keyBlue(self): curChannel = self.getSelectedChannel() if curChannel: self.oldPosition = self["ChannelList"].getIndex() self.qpipChannelList.removeChannel(curChannel) self.force_exit = True self.session.openWithCallback(self.CreateQuadPipChannelEntryCB, CreateQuadPipChannelEntry, None, curChannel) def getCurrentIndex(self): idx = -1 cur = self["ChannelList"].getCurrent() if cur: idx = cur[5] return idx def getSelectedChannel(self): selectedChannel = None idx = self.getCurrentIndex() if idx != -1: selectedChannel = self.qpipChannelList.getChannel(idx) return selectedChannel def getDefaultEntryName(self): return "%s%d" % (self.qpipChannelList.getDefaultPreName(), self.qpipChannelList.length() + 1) def CreateQuadPipChannelEntryCB(self, newChannel): if newChannel: self.qpipChannelList.addNewChannel(newChannel) self.qpipChannelList.sortPipChannelList() self.oldPosition = newChannel.getIndex() - 1 self.updateDisplay() self.updatePosition() def updateDisplay(self): self.PipChannelListApply = [] for ch in self.getChannelList(): entry = [] entryName = ch.getName() if not entryName: entryName = "%s%d" % (self.qpipChannelList.getDefaultPreName(), ch.getIndex()) if self.qpipChannelList.getIdx() == ch.getIndex(): entryName += _(" (current channel)") entry.append(entryName) entry.append("1) " + ch.getChannelName("1")) entry.append("2) " + ch.getChannelName("2")) entry.append("3) " + ch.getChannelName("3")) entry.append("4) " + ch.getChannelName("4")) entry.append(ch.getIndex()) self.PipChannelListApply.append(tuple(entry)) self["ChannelList"].setList(self.PipChannelListApply) def updatePosition(self): if self.oldPosition: if self["ChannelList"].count() > self.oldPosition: self["ChannelList"].setIndex(self.oldPosition) self.oldPosition = None def updateChannelList(self): self.qpipChannelList.sortPipChannelList() self.updateDisplay() self.updatePosition() def getChannelList(self): return self.qpipChannelList.getPipChannels() class FocusShowHide: STATE_HIDDEN = 0 STATE_SHOWN = 1 def __init__(self): self.__state = self.STATE_SHOWN self.hideTimer = eTimer() self.hideTimer.callback.append(self.hideTimerCB) self.onLayoutFinish.append(self.startHideTimer) def startHideTimer(self): self.hideTimer.stop() self.hideTimer.start(5000, True) def hideTimerCB(self): self.hideFocus() def isShown(self): return self.__state == self.STATE_SHOWN def showFocus(self): self.show() self.__state = self.STATE_SHOWN self.startHideTimer() def hideFocus(self): self.hideTimer.stop() self.hide() self.__state = self.STATE_HIDDEN def toggleShow(self): if self.__state == self.STATE_SHOWN: self.hideFocus() elif self.__state == self.STATE_HIDDEN: self.showFocus() class QuadPipScreen(Screen, FocusShowHide, HelpableScreen): skin = """ """ def __init__(self, session): self.session = session self.session.qPips = None Screen.__init__(self, session) FocusShowHide.__init__(self) HelpableScreen.__init__(self) self.setTitle(_("Quad PiP Screen")) self.InfoBarInstance = Screens.InfoBar.InfoBar.instance self["actions"] = HelpableActionMap(self, "QuadPipSetupActions", { "cancel": (self.keyExit, _("Exit quad PiP")), "ok": (self.keyOk, _("Zap focused channel on full screen")), "left": (self.keyLeft, _("Select channel audio")), "right": (self.keyRight, _("Select channel audio")), "up": (self.keyUp, _("Select channel audio")), "down": (self.keyDown, _("Select channel audio")), "channelup": (self.KeyChannel, _("Show channel selection")), "channeldown": (self.KeyChannel, _("Show channel selection")), "menu": (self.KeyChannel, _("Show channel selection")), "channelPrev": (self.KeyPrev, _("Prev quad PiP channel")), "channelNext": (self.KeyNext, _("Next quad PiP channel")), "red": (self.KeyRed, _("Show/Hide focus bar")), }, -1) self["ch1"] = Label(" ") self["ch2"] = Label(" ") self["ch3"] = Label(" ") self["ch4"] = Label(" ") self["text1"] = Label(_(" Red key : Show/Hide texts")) self["text2"] = Label(_(" Menu key : Select quad channel")) self["focus"] = Slider(-1, -1) self.currentPosition = 1 # 1~4 self.updatePositionList() self.skin = QuadPipScreen.skin % (self.session.desktop.size().width(), self.session.desktop.size().height(), self.fontSize, self.fontSize, self.fontSize, self.fontSize, self.text1Pos[0], self.text1Pos[1] - 5, self.text1Pos[2], self.text1Pos[3], self.fontSize, self.text2Pos[0], self.text2Pos[1] - 5, self.text2Pos[2], self.text2Pos[3], self.fontSize) self.oldService = None self.curChannel = None self.curPlayAudio = -1 global quad_pip_channel_list_instance self.qpipChannelList = quad_pip_channel_list_instance self.oldLcdLiveTVEnable = False self.onLayoutFinish.append(self.layoutFinishedCB) self.notSupportTimer = eTimer() self.notSupportTimer.callback.append(self.showNotSupport) self.noChannelTimer = eTimer() self.noChannelTimer.callback.append(self.noChannelTimerCB) self.forceToExitTimer = eTimer() self.forceToExitTimer.callback.append(self.forceToExitTimerCB) def forceToExitTimerCB(self): self.session.openWithCallback(self.close, MessageBox, _("Quad PiP is not available."), MessageBox.TYPE_ERROR) def showNotSupport(self): self.session.openWithCallback(self.close, MessageBox, _("Box or driver is not support Quad PiP."), MessageBox.TYPE_ERROR) def noChannelTimerCB(self): self.session.openWithCallback(self.ChannelSelectCB, QuadPiPChannelSelection) def layoutFinishedCB(self): if not os.access(ENABLE_QPIP_PROCPATH, os.F_OK): self.notSupportTimer.start(100, True) return if os.path.exists("/proc/stb/vmpeg/0/dst_apply"): open("/proc/stb/vmpeg/0/dst_left", "w").write("00000000") open("/proc/stb/vmpeg/0/dst_top", "w").write("00000000") open("/proc/stb/vmpeg/0/dst_width", "w").write("00000000") open("/proc/stb/vmpeg/0/dst_height", "w").write("00000000") open("/proc/stb/vmpeg/0/dst_apply", "w").write("00000001") self.onClose.append(self.__onClose) if self.session.pipshown: if self.InfoBarInstance: hasattr(self.InfoBarInstance, "showPiP") and self.InfoBarInstance.showPiP() if hasattr(self.session, 'pip'): del self.session.pip self.session.pipshown = False self.oldService = self.session.nav.getCurrentlyPlayingServiceOrGroup() self.newService = None self.session.nav.stopService() self.disableLcdLiveTV() ret = setDecoderMode("mosaic") if ret is not True: self.forceToExitTimer.start(0, True) return self.moveLabel() if self.qpipChannelList.length() == 0: self.noChannelTimer.start(10, True) else: self.playLastChannel() def __onClose(self): self.disableQuadPip() setDecoderMode("normal") self.restoreLcdLiveTV() self.qpipChannelList.saveAll() if self.newService and (not self.oldService or self.newService != self.oldService): self.oldService = self.newService Components.ServiceEventTracker.InfoBarCount = 1 self.session.nav.playService(self.oldService) def getChannelPosMap(self, w, h): rectMap = {} ch1 = (0, 0, int(w * 0.5), int(h * 0.5)) ch2 = (int(w * 0.5), 0, int(w * 0.5), int(h * 0.5)) ch3 = (0, int(h * 0.5), int(w * 0.5), int(h * 0.5)) ch4 = (int(w * 0.5), int(h * 0.5), int(w * 0.5), int(h * 0.5)) rectMap = (None, ch1, ch2, ch3, ch4) return rectMap def updatePositionList(self): w = self.session.desktop.size().width() h = self.session.desktop.size().height() self.framePosMap = self.getChannelPosMap(w, h) self.eVideoPosMap = self.getChannelPosMap(720, 576) self.movePositionMap = {} self.movePositionMap["left"] = [-1, 2, 1, 4, 3] self.movePositionMap["right"] = [-1, 2, 1, 4, 3] self.movePositionMap["up"] = [-1, 3, 4, 1, 2] self.movePositionMap["down"] = [-1, 3, 4, 1, 2] self.labelPositionMap = {} self.labelPositionMap["ch1"] = (w / 8, h / 4 - h / 36, w / 4, h / 18) self.labelPositionMap["ch2"] = (w / 8 + w / 2, h / 4 - h / 36, w / 4, h / 18) self.labelPositionMap["ch3"] = (w / 8, h / 4 - h / 36 + h / 2, w / 4, h / 18) self.labelPositionMap["ch4"] = (w / 8 + w / 2, h / 4 - h / 36 + h / 2, w / 4, h / 18) self.decoderIdxMap = [None, 0, 1, 2, 3] self.fontSize = {1080: 40, 720: 28, 576: 18}.get(h, 40) self.text1Pos = (w - w / 2, h - h / 18 - h / 18, w / 2, h / 18) self.text2Pos = (w - w / 2, h - h / 18, w / 2, h / 18) def moveFrame(self): self.showFocus() pos = self.framePosMap[self.currentPosition] self["focus"].resize(int(pos[2]), int(pos[3])) self["focus"].move(int(pos[0]), int(pos[1])) def moveLabel(self): posMap = self.labelPositionMap ch1_posMap = posMap["ch1"] self["ch1"].move(int(ch1_posMap[0]), int(ch1_posMap[1])) self["ch1"].resize(int(ch1_posMap[2]), int(ch1_posMap[3])) ch2_posMap = posMap["ch2"] self["ch2"].move(int(ch2_posMap[0]), int(ch2_posMap[1])) self["ch2"].resize(int(ch2_posMap[2]), int(ch2_posMap[3])) ch3_posMap = posMap["ch3"] self["ch3"].move(int(ch3_posMap[0]), int(ch3_posMap[1])) self["ch3"].resize(int(ch3_posMap[2]), int(ch3_posMap[3])) ch4_posMap = posMap["ch4"] self["ch4"].move(int(ch4_posMap[0]), int(ch4_posMap[1])) self["ch4"].resize(int(ch4_posMap[2]), int(ch4_posMap[3])) def keyExit(self): self.close() def keyOk(self): if self.isShown(): channel = self.qpipChannelList.getCurrentChannel() if channel: chInfo = channel.getChannel(str(self.currentPosition)) if chInfo: (sname, sref) = chInfo self.newService = eServiceReference(sref) self.close() else: self.showFocus() def keyLeft(self): newPosition = self.movePositionMap["left"][self.currentPosition] self.selectPosition(newPosition) def keyRight(self): newPosition = self.movePositionMap["right"][self.currentPosition] self.selectPosition(newPosition) def keyUp(self): newPosition = self.movePositionMap["up"][self.currentPosition] self.selectPosition(newPosition) def keyDown(self): newPosition = self.movePositionMap["down"][self.currentPosition] self.selectPosition(newPosition) def KeyChannel(self): self.session.openWithCallback(self.ChannelSelectCB, QuadPiPChannelSelection) def KeyPrev(self): curIdx = self.qpipChannelList.getIdx() curIdx -= 1 if curIdx == 0: curIdx = self.qpipChannelList.length() self.qpipChannelList.setIdx(curIdx) self.playLastChannel() def KeyNext(self): curIdx = self.qpipChannelList.getIdx() curIdx += 1 if curIdx > self.qpipChannelList.length(): curIdx = 1 self.qpipChannelList.setIdx(curIdx) self.playLastChannel() def KeyRed(self): self.toggleShow() def selectPosition(self, pos): self.currentPosition = pos self.moveFrame() self.selectAudio() def selectAudio(self): print(" --audio switch==?", self.curPlayAudio, self.currentPosition) if self.curPlayAudio == -1: return if self.curPlayAudio != self.currentPosition: if self.session.qPips and len(self.session.qPips): self.playAudio(self.curPlayAudio, False) self.playAudio(self.currentPosition, True) def disableQuadPip(self): if self.session.qPips is not None: for qPip in self.session.qPips: del qPip self.session.qPips = None self.curPlayAudio = -1 self.updateChannelName(None) def ChannelSelectCB(self, force_exit=False): if force_exit: self.close() return if self.qpipChannelList.length() == 0: self.disableQuadPip() else: self.playLastChannel() def playLastChannel(self, first=True): if self.qpipChannelList.length() == 0: if not first: self.disableQuadPip() return channel = self.qpipChannelList.getCurrentChannel() if channel: self.playChannel(channel) elif first: self.qpipChannelList.setIdx(1) self.playLastChannel(False) return channel def playChannel(self, channel): print("[playChannel] channel : ", channel) if self.curChannel and self.curChannel == channel.channel: return self.disableQuadPip() self.selectPosition(1) self.curChannel = channel.channel.copy() self.session.qPips = [] for idx in range(1, 5): chInfo = channel.getChannel(str(idx)) if chInfo is None: self.session.qPips.append(None) if self.currentPosition == idx: self.curPlayAudio = idx continue (sname, sref) = chInfo qPipShown = False decoderIdx = self.decoderIdxMap[idx] pos = self.eVideoPosMap[idx] #print pos #print "====================================================================" #print "sname : ", sname #print "sref : ", sref #print "decoderIdx : " , decoderIdx #print "pos : ", pos #print "====================================================================" qPipInstance = self.session.instantiateDialog(QuadPiP, decoderIdx, pos) qPipInstance.show() isPlayAudio = False if self.currentPosition == idx: isPlayAudio = True self.curPlayAudio = idx if qPipInstance.playService(eServiceReference(sref), isPlayAudio): self.session.qPips.append(qPipInstance) else: del qPipInstance self.session.qPips.append(None) self.updateChannelName(channel) self.showFocus() def playAudio(self, idx, value): if self.session.qPips is not None: qPipInstance = self.session.qPips[idx - 1] if qPipInstance: qPipInstance.setQpipMode(True, value) if value: self.curPlayAudio = idx else: self.curPlayAudio = -1 def updateChannelName(self, channel): for idx in range(1, 5): self["ch%d" % idx].setText((channel and channel.getChannelName(str(idx))) or _("No channel")) def disableLcdLiveTV(self): if BoxInfo.getItem("LcdLiveTV", False): self.oldLcdLiveTVEnable = config.lcd.showTv.value config.lcd.showTv.value = False def restoreLcdLiveTV(self): if BoxInfo.getItem("LcdLiveTV", False): config.lcd.showTv.value = self.oldLcdLiveTVEnable class QuadPiP(Screen): def __init__(self, session, decoderIdx=1, pos=None): Screen.__init__(self, session) self["video"] = VideoWindow(decoderIdx, 720, 576) self.currentService = None self.onLayoutFinish.append(self.LayoutFinished) self.decoderIdx = decoderIdx self.pos = pos self.skinName = "PictureInPicture" def LayoutFinished(self): self.onLayoutFinish.remove(self.LayoutFinished) x = self.pos[0] y = self.pos[1] w = self.pos[2] h = self.pos[3] if x != -1 and y != -1 and w != -1 and h != -1: self.resize(w, h) self.move(x, y) def move(self, x, y): self.instance.move(ePoint(x, y)) def resize(self, w, h): self.instance.resize(eSize(*(w, h))) self["video"].instance.resize(eSize(*(w, h))) def getPosition(self): return ((self.instance.position().x(), self.instance.position().y())) def getSize(self): return (self.instance.size().width(), self.instance.size().height()) def playService(self, service, playAudio): print(" ---PLAY--> ", service, playAudio) if service and (service.flags & eServiceReference.isGroup): ref = getBestPlayableServiceReference(service, eServiceReference()) else: ref = service if ref: self.pipservice = eServiceCenter.getInstance().play(ref) if self.pipservice and not self.pipservice.setTarget(self.decoderIdx): self.setQpipMode(True, playAudio) self.pipservice.start() self.currentService = service return True else: self.pipservice = None self.currentService = None return False def setQpipMode(self, pipMode, playAudio): if self.pipservice: print(" ----> index, mode, audio ---> ", self.decoderIdx, pipMode, playAudio) self.pipservice.setQpipMode(pipMode, playAudio) def getCurrentService(self): return self.currentService