prepare moving audio cdtext extraction to seperate plugin
[enigma2.git] / lib / python / Components / MediaPlayer.py
index d88b628..791274f 100644 (file)
@@ -1,21 +1,11 @@
-from HTMLComponent import *
-from GUIComponent import *
-
 from MenuList import MenuList
 
 from MenuList import MenuList
 
-from Tools.Directories import *
-import os
-
-from enigma import *
+from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename
+from os import path
 
 
-RT_HALIGN_LEFT = 0
-RT_HALIGN_RIGHT = 1
-RT_HALIGN_CENTER = 2
-RT_HALIGN_BLOCK = 4
+from enigma import eListboxPythonMultiContent, RT_VALIGN_CENTER, gFont, eServiceCenter
 
 
-RT_VALIGN_TOP = 0
-RT_VALIGN_CENTER = 8
-RT_VALIGN_BOTTOM = 16
+from Tools.LoadPixmap import LoadPixmap
 
 STATE_PLAY = 0
 STATE_PAUSE = 1
 
 STATE_PLAY = 0
 STATE_PAUSE = 1
@@ -24,15 +14,18 @@ STATE_REWIND = 3
 STATE_FORWARD = 4
 STATE_NONE = 5
 
 STATE_FORWARD = 4
 STATE_NONE = 5
 
-PlayIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_play.png"))
-PauseIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_pause.png"))
-StopIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_stop.png"))
-RewindIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_rewind.png"))
-ForwardIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_forward.png"))
+PlayIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/ico_mp_play.png"))
+PauseIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/ico_mp_pause.png"))
+StopIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/ico_mp_stop.png"))
+RewindIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/ico_mp_rewind.png"))
+ForwardIcon = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/ico_mp_forward.png"))
 
 def PlaylistEntryComponent(serviceref, state):
        res = [ serviceref ]
 
 def PlaylistEntryComponent(serviceref, state):
        res = [ serviceref ]
-       res.append((eListboxPythonMultiContent.TYPE_TEXT,25, 0, 470, 32, 0, RT_VALIGN_CENTER, os.path.split(serviceref.getPath().split('/')[-1])[1]))
+       text = serviceref.getName()
+       if text is "":
+               text = path.split(serviceref.getPath().split('/')[-1])[1]
+       res.append((eListboxPythonMultiContent.TYPE_TEXT,25, 0, 470, 32, 0, RT_VALIGN_CENTER, text))
        png = None
        if state == STATE_PLAY:
                png = PlayIcon
        png = None
        if state == STATE_PLAY:
                png = PlayIcon
@@ -50,37 +43,31 @@ def PlaylistEntryComponent(serviceref, state):
     
        return res
 
     
        return res
 
-class PlayList(MenuList, HTMLComponent, GUIComponent):
-       def __init__(self):
-               GUIComponent.__init__(self)
-               self.l = eListboxPythonMultiContent()
-               self.list = []
-               self.l.setList(self.list)
+class PlayList(MenuList):
+       def __init__(self, enableWrapAround = False):
+               MenuList.__init__(self, [], enableWrapAround, eListboxPythonMultiContent)
                self.l.setFont(0, gFont("Regular", 18))
                self.l.setFont(0, gFont("Regular", 18))
+               self.l.setItemHeight(22)
                self.currPlaying = -1
                self.oldCurrPlaying = -1
                self.currPlaying = -1
                self.oldCurrPlaying = -1
-       
+               self.serviceHandler = eServiceCenter.getInstance()
+
        def clear(self):
                del self.list[:]
                self.l.setList(self.list)
                self.currPlaying = -1
                self.oldCurrPlaying = -1
 
        def clear(self):
                del self.list[:]
                self.l.setList(self.list)
                self.currPlaying = -1
                self.oldCurrPlaying = -1
 
-       GUI_WIDGET = eListbox
-
-       def postWidgetCreate(self, instance):
-               instance.setContent(self.l)
-               instance.setItemHeight(22)
-
        def getSelection(self):
                return self.l.getCurrentSelection()[0]
        def getSelection(self):
                return self.l.getCurrentSelection()[0]
-               
-       def getSelectionIndex(self):
-               return self.l.getCurrentSelectionIndex()
 
        def addFile(self, serviceref):
                self.list.append(PlaylistEntryComponent(serviceref, STATE_NONE))
 
 
        def addFile(self, serviceref):
                self.list.append(PlaylistEntryComponent(serviceref, STATE_NONE))
 
+       def updateFile(self, index, newserviceref):
+               if index < len(self.list):
+                   self.list[index] = PlaylistEntryComponent(newserviceref, STATE_NONE)
+
        def deleteFile(self, index):
                if self.currPlaying >= index:
                        self.currPlaying -= 1
        def deleteFile(self, index):
                if self.currPlaying >= index:
                        self.currPlaying -= 1
@@ -89,7 +76,7 @@ class PlayList(MenuList, HTMLComponent, GUIComponent):
        def setCurrentPlaying(self, index):
                self.oldCurrPlaying = self.currPlaying
                self.currPlaying = index
        def setCurrentPlaying(self, index):
                self.oldCurrPlaying = self.currPlaying
                self.currPlaying = index
-       
+
        def updateState(self, state):
                if len(self.list) > self.oldCurrPlaying and self.oldCurrPlaying != -1:
                        self.list[self.oldCurrPlaying] = PlaylistEntryComponent(self.list[self.oldCurrPlaying][0], STATE_NONE)
        def updateState(self, state):
                if len(self.list) > self.oldCurrPlaying and self.oldCurrPlaying != -1:
                        self.list[self.oldCurrPlaying] = PlaylistEntryComponent(self.list[self.oldCurrPlaying][0], STATE_NONE)
@@ -108,21 +95,26 @@ class PlayList(MenuList, HTMLComponent, GUIComponent):
 
        def rewindFile(self):
                self.updateState(STATE_REWIND)
 
        def rewindFile(self):
                self.updateState(STATE_REWIND)
-               
+
        def forwardFile(self):
                self.updateState(STATE_FORWARD)
        def forwardFile(self):
                self.updateState(STATE_FORWARD)
-       
+
        def updateList(self):
                self.l.setList(self.list)
        def updateList(self):
                self.l.setList(self.list)
-               
+
        def getCurrentIndex(self):
                return self.currPlaying
        def getCurrentIndex(self):
                return self.currPlaying
-       
+
+       def getCurrentEvent(self):
+               l = self.l.getCurrentSelection()
+               return l and self.serviceHandler.info(l[0]).getEvent(l[0])
+
+       def getCurrent(self):
+               l = self.l.getCurrentSelection()
+               return l and l[0]
+
        def getServiceRefList(self):
        def getServiceRefList(self):
-               list = []
-               for x in self.list:
-                       list.append(x[0])
-               return list
-       
+               return [ x[0] for x in self.list ]
+
        def __len__(self):
                return len(self.list)
        def __len__(self):
                return len(self.list)