follow changes
[enigma2.git] / lib / python / Plugins / Extensions / CutListEditor / plugin.py
index 9c016c43fb2855f1e1e313f4a7ce2ae3f0815194..b17fa1763eebaa63ee29a444c5b87cda2bce93e3 100644 (file)
@@ -36,19 +36,22 @@ class CutListContextMenu(FixedMenu):
        RET_ENDCUT = 1
        RET_DELETECUT = 2
        RET_MARK = 3
        RET_ENDCUT = 1
        RET_DELETECUT = 2
        RET_MARK = 3
+       RET_DELETEMARK = 4
+       RET_REMOVEBEFORE = 5
+       RET_REMOVEAFTER = 6
        
        SHOW_STARTCUT = 0
        SHOW_ENDCUT = 1
        SHOW_DELETECUT = 2
        
        
        SHOW_STARTCUT = 0
        SHOW_ENDCUT = 1
        SHOW_DELETECUT = 2
        
-       def __init__(self, session, state):
-               menu = [(_("back"), self.close), (None, )]
+       def __init__(self, session, state, nearmark):
+               menu = [(_("back"), self.close)] #, (None, )]
 
                if state == self.SHOW_STARTCUT:
                        menu.append((_("start cut here"), self.startCut))
                else:
                        menu.append((_("start cut here"), ))
 
                if state == self.SHOW_STARTCUT:
                        menu.append((_("start cut here"), self.startCut))
                else:
                        menu.append((_("start cut here"), ))
-                       
+
                if state == self.SHOW_ENDCUT:
                        menu.append((_("end cut here"), self.endCut))
                else:
                if state == self.SHOW_ENDCUT:
                        menu.append((_("end cut here"), self.endCut))
                else:
@@ -58,12 +61,20 @@ class CutListContextMenu(FixedMenu):
                        menu.append((_("delete cut"), self.deleteCut))
                else:
                        menu.append((_("delete cut"), ))
                        menu.append((_("delete cut"), self.deleteCut))
                else:
                        menu.append((_("delete cut"), ))
-               
-               menu.append((None, ))
-               menu.append((_("insert mark here"), self.insertMark))
+
+               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))
+               else:
+                       menu.append((_("remove this mark"), self.removeMark))
+
                FixedMenu.__init__(self, session, _("Cut"), menu)
                self.skinName = "Menu"
                FixedMenu.__init__(self, session, _("Cut"), menu)
                self.skinName = "Menu"
-       
+
        def startCut(self):
                self.close(self.RET_STARTCUT)
 
        def startCut(self):
                self.close(self.RET_STARTCUT)
 
@@ -76,6 +87,16 @@ class CutListContextMenu(FixedMenu):
        def insertMark(self):
                self.close(self.RET_MARK)
 
        def insertMark(self):
                self.close(self.RET_MARK)
 
+       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):
                GUIComponent.__init__(self)
 class CutList(GUIComponent):
        def __init__(self, list):
                GUIComponent.__init__(self)
@@ -90,21 +111,17 @@ class CutList(GUIComponent):
        def getCurrentIndex(self):
                return self.l.getCurrentSelectionIndex()
        
        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 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)
        
        def invalidateEntry(self, index):
                self.l.invalidateEntry(index)
        
@@ -132,6 +149,7 @@ class CutListEditor(Screen, InfoBarSeek, InfoBarCueSheetSupport):
                Screen.__init__(self, session)
                InfoBarSeek.__init__(self)
                InfoBarCueSheetSupport.__init__(self)
                Screen.__init__(self, session)
                InfoBarSeek.__init__(self)
                InfoBarCueSheetSupport.__init__(self)
+               self.old_service = session.nav.getCurrentlyPlayingServiceReference()
                session.nav.playService(service)
                
                service = session.nav.getCurrentService()
                session.nav.playService(service)
                
                service = session.nav.getCurrentService()
@@ -168,7 +186,6 @@ class CutListEditor(Screen, InfoBarSeek, InfoBarCueSheetSupport):
 
                # to track new entries we save the last version of the cutlist
                self.last_cuts = [ ]
 
                # to track new entries we save the last version of the cutlist
                self.last_cuts = [ ]
-               
                self.cut_start = None
                
        def showTutorial(self):
                self.cut_start = None
                
        def showTutorial(self):
@@ -186,8 +203,9 @@ Then seek to the end, press OK, select 'end cut'. That's it.
                pass
        
        def setType(self, index, type):
                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()
        
        def setIn(self):
                m = self["Cutlist"].getCurrentIndex()
@@ -214,6 +232,7 @@ Then seek to the end, press OK, select 'end cut'. That's it.
                        self.removeMark(m)
        
        def exit(self):
                        self.removeMark(m)
        
        def exit(self):
+               self.session.nav.playService(self.old_service)
                self.close()
 
        def getCutlist(self):
                self.close()
 
        def getCutlist(self):
@@ -250,6 +269,11 @@ Then seek to the end, press OK, select 'end cut'. That's it.
 
        def getStateForPosition(self, pos):
                state = 0 # in
 
        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
                for (where, what) in self.cut_list:
                        if where < pos:
                                if what == 0: # in
@@ -267,6 +291,8 @@ Then seek to the end, press OK, select 'end cut'. That's it.
                
                self.context_position = curpos
                
                
                self.context_position = curpos
                
+               self.context_nearest_mark = self.toggleMark(onlyreturn=True)
+
                cur_state = self.getStateForPosition(curpos)
                if cur_state == 0:
                        print "currently in 'IN'"
                cur_state = self.getStateForPosition(curpos)
                if cur_state == 0:
                        print "currently in 'IN'"
@@ -278,7 +304,12 @@ Then seek to the end, press OK, select 'end cut'. That's it.
                        print "currently in 'OUT'"
                        state = CutListContextMenu.SHOW_DELETECUT
                
                        print "currently in 'OUT'"
                        state = CutListContextMenu.SHOW_DELETECUT
                
-               self.session.openWithCallback(self.menuCallback, CutListContextMenu, state)
+               if self.context_nearest_mark is None:
+                       nearmark = False
+               else:
+                       nearmark = True
+               
+               self.session.openWithCallback(self.menuCallback, CutListContextMenu, state, nearmark)
        
        def menuCallback(self, *result):
                self.setSeekState(self.SEEK_STATE_PLAY)
        
        def menuCallback(self, *result):
                self.setSeekState(self.SEEK_STATE_PLAY)
@@ -318,9 +349,28 @@ Then seek to the end, press OK, select 'end cut'. That's it.
                        self.uploadCuesheet()
                elif result == CutListContextMenu.RET_MARK:
                        self.__addMark()
                        self.uploadCuesheet()
                elif result == CutListContextMenu.RET_MARK:
                        self.__addMark()
+               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):
+def main(session, service, **kwargs):
        session.open(CutListEditor, service)
 
        session.open(CutListEditor, service)
 
-def Plugins():
+def Plugins(**kwargs):
        return PluginDescriptor(name="Cutlist Editor", description=_("Cutlist editor..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc=main)
        return PluginDescriptor(name="Cutlist Editor", description=_("Cutlist editor..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc=main)