changes for new config
[enigma2.git] / lib / python / Plugins / Extensions / CutListEditor / plugin.py
index 16616cd201a9fddf5209d45b352b89e682837106..28ed7d64c8df8c5dd7645f18d1dcc349d6a91703 100644 (file)
@@ -26,6 +26,8 @@ def CutListEntry(where, what):
                type = "OUT"
        elif what == 2:
                type = "MARK"
+       elif what == 3:
+               type = "LAST"
        res.append(MultiContentEntryText(size=(400, 20), text = "%dh:%02dm:%02ds:%03d" % (h, m, s, ms)))
        res.append(MultiContentEntryText(pos=(400,0), size=(130, 20), text = type, flags = RT_HALIGN_RIGHT))
 
@@ -37,13 +39,15 @@ class CutListContextMenu(FixedMenu):
        RET_DELETECUT = 2
        RET_MARK = 3
        RET_DELETEMARK = 4
+       RET_REMOVEBEFORE = 5
+       RET_REMOVEAFTER = 6
        
        SHOW_STARTCUT = 0
        SHOW_ENDCUT = 1
        SHOW_DELETECUT = 2
        
        def __init__(self, session, state, nearmark):
-               menu = [(_("back"), self.close), (None, )]
+               menu = [(_("back"), self.close)] #, (None, )]
 
                if state == self.SHOW_STARTCUT:
                        menu.append((_("start cut here"), self.startCut))
@@ -60,7 +64,10 @@ class CutListContextMenu(FixedMenu):
                else:
                        menu.append((_("delete cut"), ))
 
-               menu.append((None, ))
+               menu.append((_("remove before this position"), self.removeBefore))
+               menu.append((_("remove after this position"), self.removeAfter))
+
+#              menu.append((None, ))
 
                if not nearmark:
                        menu.append((_("insert mark here"), self.insertMark))
@@ -84,6 +91,13 @@ class CutListContextMenu(FixedMenu):
 
        def removeMark(self):
                self.close(self.RET_DELETEMARK)
+       
+       def removeBefore(self):
+               self.close(self.RET_REMOVEBEFORE)
+
+       def removeAfter(self):
+               self.close(self.RET_REMOVEAFTER)
+
 
 class CutList(GUIComponent):
        def __init__(self, list):
@@ -99,21 +113,17 @@ class CutList(GUIComponent):
        def getCurrentIndex(self):
                return self.l.getCurrentSelectionIndex()
        
-       def GUIcreate(self, parent):
-               self.instance = eListbox(parent)
-               self.instance.setContent(self.l)
-               self.instance.setItemHeight(30)
-               self.instance.selectionChanged.get().append(self.selectionChanged)
+       GUI_WIDGET = eListbox
+       
+       def postWidgetCreate(self, instance):
+               instance.setContent(self.l)
+               instance.setItemHeight(30)
+               instance.selectionChanged.get().append(self.selectionChanged)
 
        def selectionChanged(self):
                for x in self.onSelectionChanged:
                        x()
        
-       def GUIdelete(self):
-               self.instance.selectionChanged.get().remove(self.selectionChanged)
-               self.instance.setContent(None)
-               self.instance = None
-       
        def invalidateEntry(self, index):
                self.l.invalidateEntry(index)
        
@@ -133,7 +143,7 @@ class CutListEditor(Screen, InfoBarSeek, InfoBarCueSheetSupport):
        skin = """
                <screen position="100,100" size="550,400" title="Test" >
                        <widget name="Timeline" position="10,0" size="530,40" 
-                               pointer="/usr/share/enigma2/position_pointer.png:3,5" />
+                               pointer="/usr/share/enigma2/position_pointer.png:3,5" foregroundColor="#225b7395" />
                        <widget name="Cutlist" position="10,50" size="530,300" scrollbarMode="showOnDemand" />
                </screen>"""
        def __init__(self, session, service):
@@ -141,6 +151,7 @@ class CutListEditor(Screen, InfoBarSeek, InfoBarCueSheetSupport):
                Screen.__init__(self, session)
                InfoBarSeek.__init__(self)
                InfoBarCueSheetSupport.__init__(self)
+               self.old_service = session.nav.getCurrentlyPlayingServiceReference()
                session.nav.playService(service)
                
                service = session.nav.getCurrentService()
@@ -165,7 +176,7 @@ class CutListEditor(Screen, InfoBarSeek, InfoBarCueSheetSupport):
                                "removeMark": (self.__removeMark, _("Remove a mark")),
                                "leave": (self.exit, _("Exit editor")),
                                "showMenu": self.showMenu,
-                       })
+                       }, prio=-4)
                
                self.tutorial_seen = False
                
@@ -177,7 +188,6 @@ class CutListEditor(Screen, InfoBarSeek, InfoBarCueSheetSupport):
 
                # to track new entries we save the last version of the cutlist
                self.last_cuts = [ ]
-               
                self.cut_start = None
                
        def showTutorial(self):
@@ -195,8 +205,9 @@ Then seek to the end, press OK, select 'end cut'. That's it.
                pass
        
        def setType(self, index, type):
-               self.cut_list[index] = (self.cut_list[index][0], type)
-               self["Cutlist"].setIndex(index, CutListEntry(*self.cut_list[index]))
+               if len(self.cut_list):
+                       self.cut_list[index] = (self.cut_list[index][0], type)
+                       self["Cutlist"].setIndex(index, CutListEntry(*self.cut_list[index]))
        
        def setIn(self):
                m = self["Cutlist"].getCurrentIndex()
@@ -223,6 +234,7 @@ Then seek to the end, press OK, select 'end cut'. That's it.
                        self.removeMark(m)
        
        def exit(self):
+               self.session.nav.playService(self.old_service)
                self.close()
 
        def getCutlist(self):
@@ -259,6 +271,11 @@ Then seek to the end, press OK, select 'end cut'. That's it.
 
        def getStateForPosition(self, pos):
                state = 0 # in
+               
+               # when first point is "in", the beginning is "out"
+               if len(self.cut_list) and self.cut_list[0][1] == 0:
+                       state = 1
+
                for (where, what) in self.cut_list:
                        if where < pos:
                                if what == 0: # in
@@ -337,6 +354,22 @@ Then seek to the end, press OK, select 'end cut'. That's it.
                elif result == CutListContextMenu.RET_DELETEMARK:
                        self.cut_list.remove(self.context_nearest_mark)
                        self.uploadCuesheet()
+               elif result == CutListContextMenu.RET_REMOVEBEFORE:
+                       # remove in/out marks before current position
+                       for (where, what) in self.cut_list[:]:
+                               if where <= self.context_position and what in [0,1]:
+                                       self.cut_list.remove((where, what))
+                       # add 'in' point
+                       bisect.insort(self.cut_list, (self.context_position, 0))
+                       self.uploadCuesheet()
+               elif result == CutListContextMenu.RET_REMOVEAFTER:
+                       # remove in/out marks after current position
+                       for (where, what) in self.cut_list[:]:
+                               if where >= self.context_position and what in [0,1]:
+                                       self.cut_list.remove((where, what))
+                       # add 'out' point
+                       bisect.insort(self.cut_list, (self.context_position, 1))
+                       self.uploadCuesheet()
 
 def main(session, service, **kwargs):
        session.open(CutListEditor, service)