remove no more exist isTop argument
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / TitleList.py
1 import DVDProject, DVDTitle, TitleList, TitleCutter
2
3 from Screens.Screen import Screen
4 from Components.ActionMap import HelpableActionMap, ActionMap
5 from Components.Sources.List import List
6 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT
7
8 class TitleList(Screen):
9
10         skin = """
11                 <screen position="100,100" size="550,400" title="DVD Tool" >
12                         <widget source="titles" render="Listbox" scrollbarMode="showOnDemand" position="0,0" size="400,400">
13                                 <convert type="StaticMultiList" />
14                         </widget>
15                 </screen>"""
16
17         def __init__(self, session, project = None):
18                 Screen.__init__(self, session)
19
20                 if project is not None:
21                         self.project = project
22                 else:
23                         self.newProject()
24
25                 self["titleactions"] = HelpableActionMap(self, "DVDTitleList",
26                         {
27                                 "addTitle": (self.addTitle, _("Add a new title"), _("Add title...")),
28                                 "editTitle": (self.editTitle, _("Edit current title"), _("Edit title...")),
29                                 "removeCurrentTitle": (self.removeCurrentTitle, _("Remove currently selected title"), _("Remove title")),
30                                 "saveProject": (self.saveProject, _("Save current project to disk"), _("Save...")),
31                                 "burnProject": (self.burnProject, _("Burn DVD"), _("Burn")),
32                         })
33
34                 self["actions"] = ActionMap(["OkCancelActions"],
35                         {
36                                 "cancel": self.leave
37                         })
38
39                 #Action("addTitle", self.addTitle)
40
41                 self["titles"] = List(list = [ ], enableWrapAround = True, item_height=50, fonts = [gFont("Regular", 20)])
42                 self.updateTitleList()
43
44                 #self["addTitle"] = ActionButton("titleactions", "addTitle")
45                 #self["editTitle"] = ActionButton("titleactions", "editTitle")
46                 #self["removeCurrentTitle"] = ActionButton("titleactions", "removeCurrentTitle")
47                 #self["saveProject"] = ActionButton("titleactions", "saveProject")
48                 #self["burnProject"] = ActionButton("titleactions", "burnProject")
49
50         def newProject(self):
51                 self.project = DVDProject.DVDProject()
52                 self.project.titles = [ ]
53
54         def addTitle(self):
55                 from Screens.MovieSelection import MovieSelection
56                 self.session.openWithCallback(self.selectedSource, MovieSelection)
57
58         def selectedSource(self, source):
59                 if source is None:
60                         return None
61                 t = self.project.addService(source)
62                 self.updateTitleList()
63
64                 self.editTitle(t)
65
66         def removeCurrentTitle(self):
67                 title = self.getCurrentTitle()
68                 if title is not None:
69                         self.project.titles.remove(title)
70                         self.updateTitleList()
71
72         def saveProject(self):
73                 pass
74
75         def burnProject(self):
76                 print "producing final cue sheet:"
77                 cue = self.produceFinalCuesheet()
78                 import Process
79                 job = Process.Burn(self.session, cue)
80                 print cue
81                 from Screens.TaskView import JobView
82                 self.session.open(JobView, job)
83
84         def updateTitleList(self):
85                 res = [ ]
86                 for title in self.project.titles:
87                         a = [ title, (eListboxPythonMultiContent.TYPE_TEXT, 0, 10, 400, 50, 0, RT_HALIGN_LEFT, title.name)  ]
88                         res.append(a)
89
90                 self["titles"].list = res
91
92         def getCurrentTitle(self):
93                 t = self["titles"].getCurrent()
94                 return t and t[0]
95
96         def editTitle(self, title = None):
97                 t = title or self.getCurrentTitle()
98                 if t is not None:
99                         self.current_edit_title = t
100                         self.session.openWithCallback(self.titleEditDone, TitleCutter.TitleCutter, t)
101
102         def titleEditDone(self, cutlist):
103                 t = self.current_edit_title
104                 t.cutlist = cutlist
105                 print "title edit of %s done, resulting cutlist:" % (t.source.toString()), t.cutlist
106
107         def leave(self):
108                 self.close()
109
110         def produceFinalCuesheet(self):
111                 res = [ ]
112                 for title in self.project.titles:
113                         path = title.source.getPath()
114                         print ">>> path:", path
115                         cutlist = title.cutlist
116
117                         # our demuxer expects *stricly* IN,OUT lists.
118                         first = True
119                         currently_in = False
120                         CUT_TYPE_IN = 0
121                         CUT_TYPE_OUT = 1
122                         CUT_TYPE_MARK = 2
123                         CUT_TYPE_LAST = 3
124
125                         accumulated_in = 0
126                         accumulated_at = 0
127                         last_in = 0
128
129                         res_cutlist = [ ]
130
131                         res_chaptermarks = [0]
132
133                         for (pts, type) in cutlist:
134                                 if first and type == CUT_TYPE_OUT: # first mark is "out"
135                                         res_cutlist.append(0) # emulate "in" at first
136                                         currently_in = True
137
138                                 first = False
139
140                                 if type == CUT_TYPE_IN and not currently_in:
141                                         res_cutlist.append(pts)
142                                         last_in = pts
143                                         currently_in = True
144
145                                 if type == CUT_TYPE_OUT and currently_in:
146                                         res_cutlist.append(pts)
147
148                                         # accumulate the segment
149                                         accumulated_in += pts - last_in 
150                                         accumulated_at = pts
151                                         currently_in = False
152
153                                 if type == CUT_TYPE_MARK and currently_in:
154                                         # relocate chaptermark against "in" time. This is not 100% accurate,
155                                         # as the in/out points are not.
156                                         res_chaptermarks.append(pts - accumulated_at + accumulated_in)
157
158                         res.append( (path, res_cutlist, res_chaptermarks) )
159
160                 return res