d3573743070af3ddf489c4fc4fa74d522f920612
[enigma2.git] / lib / python / Plugins / Extensions / CutListEditor / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2
3 from Screens.Screen import Screen
4 from Screens.MessageBox import MessageBox
5 from Components.ServicePosition import ServicePositionGauge
6 from Components.ActionMap import HelpableActionMap
7 from Components.MenuList import MenuList
8 from Components.MultiContent import MultiContentEntryText, RT_HALIGN_RIGHT
9 from Components.ServiceEventTracker import ServiceEventTracker
10
11 from Screens.InfoBarGenerics import InfoBarSeek, InfoBarCueSheetSupport
12
13 from Components.GUIComponent import GUIComponent
14
15 from enigma import eListboxPythonMultiContent, eListbox, gFont, iPlayableService
16
17 def CutListEntry(where, what):
18         res = [ (where, what) ]
19         w = where / 90
20         ms = w % 1000
21         s = (w / 1000) % 60
22         m = (w / 60000) % 60
23         h = w / 3600000
24         if what == 0:
25                 type = "IN"
26         elif what == 1:
27                 type = "OUT"
28         elif what == 2:
29                 type = "MARK"
30         res.append(MultiContentEntryText(size=(400, 20), text = "%dh:%02dm:%02ds:%03d" % (h, m, s, ms)))
31         res.append(MultiContentEntryText(pos=(400,0), size=(130, 20), text = type, flags = RT_HALIGN_RIGHT))
32
33         return res
34
35 class CutList(GUIComponent):
36         def __init__(self, list):
37                 GUIComponent.__init__(self)
38                 self.l = eListboxPythonMultiContent()
39                 self.setList(list)
40                 self.l.setFont(0, gFont("Regular", 20))
41                 self.onSelectionChanged = [ ]
42         
43         def getCurrent(self):
44                 return self.l.getCurrentSelection()
45         
46         def getCurrentIndex(self):
47                 return self.l.getCurrentSelectionIndex()
48         
49         def GUIcreate(self, parent):
50                 self.instance = eListbox(parent)
51                 self.instance.setContent(self.l)
52                 self.instance.setItemHeight(30)
53                 self.instance.selectionChanged.get().append(self.selectionChanged)
54
55         def selectionChanged(self):
56                 for x in self.onSelectionChanged:
57                         x()
58         
59         def GUIdelete(self):
60                 self.instance.selectionChanged.get().remove(self.selectionChanged)
61                 self.instance.setContent(None)
62                 self.instance = None
63         
64         def invalidateEntry(self, index):
65                 self.l.invalidateEntry(index)
66         
67         def setIndex(self, index, data):
68                 self.list[index] = data
69                 self.invalidateEntry(index)
70
71         def setList(self, list):
72                 self.list = list
73                 self.l.setList(self.list)
74
75 class CutListEditor(Screen, InfoBarSeek, InfoBarCueSheetSupport):
76         skin = """
77                 <screen position="100,100" size="550,400" title="Test" >
78                         <widget name="Timeline" position="10,0" size="530,40" 
79                                 pointer="/usr/share/enigma2/position_pointer.png:3,5" />
80                         <widget name="Cutlist" position="10,50" size="530,200" />
81                 </screen>"""
82         def __init__(self, session, service):
83                 self.skin = CutListEditor.skin
84                 Screen.__init__(self, session)
85                 InfoBarSeek.__init__(self)
86                 InfoBarCueSheetSupport.__init__(self)
87                 session.nav.playService(service)
88                 
89                 self.downloadCuesheet()
90         
91                 self["Timeline"] = ServicePositionGauge(self.session.nav)
92                 self["Cutlist"] = CutList(self.getCutlist())
93                 self["Cutlist"].onSelectionChanged.append(self.selectionChanged)
94                 
95                 self["actions"] = HelpableActionMap(self, "CutListEditorActions",
96                         {
97                                 "setIn": (self.setIn, _("Make this mark an 'in' point")),
98                                 "setOut": (self.setOut, _("Make this mark an 'out' point")),
99                                 "setMark": (self.setMark, _("Make this mark just a mark")),
100                                 "leave": (self.exit, _("Exit editor"))
101                         })
102                 
103                 self.tutorial_seen = False
104                 
105                 self.onExecBegin.append(self.showTutorial)
106                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
107                         {
108                                 iPlayableService.evCuesheetChanged: self.refillList
109                         })
110                 
111         def showTutorial(self):
112                 if not self.tutorial_seen:
113                         self.tutorial_seen = True
114                         self.session.open(MessageBox, 
115                                 """Welcome to the Cutlist editor. It has a *very* unintuitive handling:
116
117 You can add use the color keys to move around in the recorded movie. 
118 By pressing shift-yellow, you can add a mark or remove an existing one.
119 You can then assign them to be either 'in' or 'out' positions by selecting them in the list and pressing 1 or 2.
120                                 """, MessageBox.TYPE_INFO)
121         
122         def checkSkipShowHideLock(self):
123                 pass
124         
125         def setType(self, index, type):
126                 self.cut_list[index] = (self.cut_list[index][0], type)
127                 self["Cutlist"].setIndex(index, CutListEntry(*self.cut_list[index]))
128         
129         def setIn(self):
130                 m = self["Cutlist"].getCurrentIndex()
131                 self.setType(m, 0)
132                 self.uploadCuesheet()
133         
134         def setOut(self):
135                 m = self["Cutlist"].getCurrentIndex()
136                 self.setType(m, 1)
137                 self.uploadCuesheet()
138
139         def setMark(self):
140                 m = self["Cutlist"].getCurrentIndex()
141                 self.setType(m, 2)
142                 self.uploadCuesheet()
143         
144         def exit(self):
145                 self.close()
146
147         def getCutlist(self):
148                 r = [ ]
149                 for e in self.cut_list:
150                         r.append(CutListEntry(*e))
151                 return r
152
153         def selectionChanged(self):
154                 where = self["Cutlist"].getCurrent()
155                 if where is None:
156                         print "no selection"
157                         return
158                 pts = where[0][0]
159                 seek = self.getSeek()
160                 if seek is None:
161                         print "no seek"
162                         return
163                 seek.seekTo(pts)
164
165         def refillList(self):
166                 print "cue sheet changed, refilling"
167                 self.downloadCuesheet()
168                 self["Cutlist"].setList(self.getCutlist())
169
170 def main(session, service):
171         session.open(CutListEditor, service)
172
173 def Plugins():
174         return PluginDescriptor(name="Cutlist Editor", description=_("Cutlist editor..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc=main)