enigma2 (20120327 rel32 -> 20120430 master)
[enigma2.git] / usr / lib / enigma2 / python / Plugins / Extensions / DVDBurn / TitleProperties.py
1 from Screens.Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.Sources.StaticText import StaticText
4 from Components.Pixmap import Pixmap
5 from enigma import ePicLoad
6 from Components.config import config, getConfigListEntry, ConfigInteger
7 from Components.ConfigList import ConfigListScreen
8 from Components.AVSwitch import AVSwitch
9 import Title
10
11 class TitleProperties(Screen,ConfigListScreen):
12         skin = """
13                 <screen name="TitleProperties" position="center,center" size="560,445" title="Properties of current title" >
14                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
15                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
16                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
17                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
18                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
19                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
20                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
21                         <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
22                         <widget source="serviceinfo" render="Label" position="10,46" size="350,144" font="Regular;18" />
23                         <widget name="thumbnail" position="370,46" size="180,144" alphatest="on" />
24                         <widget name="config" position="10,206" size="540,228" scrollbarMode="showOnDemand" />
25                 </screen>"""
26
27         def __init__(self, session, parent, project, title_idx):
28                 Screen.__init__(self, session)
29                 self.parent = parent
30                 self.project = project
31                 self.title_idx = title_idx
32
33                 self["key_red"] = StaticText(_("Cancel"))
34                 self["key_green"] = StaticText(_("OK"))
35                 self["key_yellow"] = StaticText(_("Edit Title"))
36                 self["key_blue"] = StaticText()
37                 self["serviceinfo"] = StaticText()
38
39                 self["thumbnail"] = Pixmap()
40                 self.picload = ePicLoad()
41                 self.picload.PictureData.get().append(self.paintThumbPixmapCB)
42
43                 self.properties = project.titles[title_idx].properties
44                 ConfigListScreen.__init__(self, [])
45                 self.properties.crop = Title.ConfigFixedText("crop")
46                 self.properties.autochapter.addNotifier(self.initConfigList)
47                 self.properties.aspect.addNotifier(self.initConfigList)
48                 for audiotrack in self.properties.audiotracks:
49                         audiotrack.active.addNotifier(self.initConfigList)
50
51                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
52                 {
53                     "green": self.exit,
54                     "red": self.cancel,
55                     "yellow": self.editTitle,
56                     "cancel": self.cancel,
57                     "ok": self.ok,
58                 }, -2)
59                 
60                 self.onShown.append(self.update)
61                 self.onLayoutFinish.append(self.layoutFinished)
62
63         def layoutFinished(self):
64                 self.setTitle(_("Properties of current title"))
65
66         def initConfigList(self, element=None):
67                 try:
68                         self.properties.position = ConfigInteger(default = self.title_idx+1, limits = (1, len(self.project.titles)))
69                         title = self.project.titles[self.title_idx]
70                         self.list = []
71                         self.list.append(getConfigListEntry("DVD " + _("Track"), self.properties.position))
72                         self.list.append(getConfigListEntry("DVD " + _("Title"), self.properties.menutitle))
73                         self.list.append(getConfigListEntry("DVD " + _("Description"), self.properties.menusubtitle))
74                         if config.usage.setup_level.index >= 2: # expert+
75                                 for audiotrack in self.properties.audiotracks:
76                                         DVB_aud = audiotrack.DVB_lang.getValue() or audiotrack.pid.getValue()
77                                         self.list.append(getConfigListEntry(_("burn audio track (%s)") % DVB_aud, audiotrack.active))
78                                         if audiotrack.active.getValue():
79                                                 self.list.append(getConfigListEntry(_("audio track (%s) format") % DVB_aud, audiotrack.format))
80                                                 self.list.append(getConfigListEntry(_("audio track (%s) language") % DVB_aud, audiotrack.language))
81                                                 
82                                 self.list.append(getConfigListEntry("DVD " + _("Aspect Ratio"), self.properties.aspect))
83                                 if self.properties.aspect.getValue() == "16:9":
84                                         self.list.append(getConfigListEntry("DVD " + "widescreen", self.properties.widescreen))
85                                 else:
86                                         self.list.append(getConfigListEntry("DVD " + "widescreen", self.properties.crop))
87                         if len(title.chaptermarks) == 0:
88                                 self.list.append(getConfigListEntry(_("Auto chapter split every ? minutes (0=never)"), self.properties.autochapter))
89                         infotext = "DVB " + _("Title") + ': ' + title.DVBname + "\n" + _("Description") + ': ' + title.DVBdescr + "\n" + _("Channel") + ': ' + title.DVBchannel + '\n' + _("Begin time") + title.formatDVDmenuText(": $D.$M.$Y, $T\n", self.title_idx+1)
90                         chaptermarks = title.getChapterMarks(template="$h:$m:$s")
91                         chapters_count = len(chaptermarks)
92                         if chapters_count >= 1:
93                                 infotext += str(chapters_count+1) + ' ' + _("chapters") + ': '
94                                 infotext += ' / '.join(chaptermarks)
95                         self["serviceinfo"].setText(infotext)
96                         self["config"].setList(self.list)
97                 except AttributeError:
98                         pass
99
100         def editTitle(self):
101                 self.parent.editTitle()
102
103         def update(self):
104                 print "[onShown]"
105                 self.initConfigList()
106                 self.loadThumb()
107
108         def loadThumb(self):
109                 thumbfile = self.project.titles[self.title_idx].inputfile.rsplit('.',1)[0] + ".png"
110                 sc = AVSwitch().getFramebufferScale()
111                 self.picload.setPara((self["thumbnail"].instance.size().width(), self["thumbnail"].instance.size().height(), sc[0], sc[1], False, 1, "#00000000"))
112                 self.picload.startDecode(thumbfile)
113
114         def paintThumbPixmapCB(self, picInfo=None):
115                 ptr = self.picload.getData()
116                 if ptr != None:
117                         self["thumbnail"].instance.setPixmap(ptr.__deref__())
118
119         def changedConfigList(self):
120                 self.initConfigList()
121
122         def exit(self):
123                 self.applySettings()
124                 self.close()
125
126         def applySettings(self):
127                 for x in self["config"].list:
128                         x[1].save()
129                 current_pos = self.title_idx+1
130                 new_pos = self.properties.position.getValue()
131                 if new_pos != current_pos:
132                         print "title got repositioned from ", current_pos, "to", new_pos
133                         swaptitle = self.project.titles.pop(current_pos-1)
134                         self.project.titles.insert(new_pos-1, swaptitle)
135
136         def ok(self):
137                 #key = self.keydict[self["config"].getCurrent()[1]]
138                 #if key in self.project.filekeys:
139                         #self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, key, self.settings)
140                 pass
141
142         def cancel(self):
143                 self.close()