[MerlinSkinThemes] - add support for layouts
[enigma2-plugins.git] / skipintro / src / SkipIntroSetup.py
1 # -*- coding: utf-8 -*-
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Screens.ChoiceBox import ChoiceBox
5 from Components.ConfigList import ConfigListScreen
6 from Components.ActionMap import ActionMap
7 from Components.config import config, ConfigInteger, ConfigSelection, getConfigListEntry, NoSave
8 from Components.Button import Button
9 from Components.Label import Label
10 from Components.ScrollLabel import ScrollLabel
11 from Components.Sources.StaticText import StaticText
12 from enigma import getDesktop
13 from SkipIntroDatabase import SIDatabase
14 from Plugins.SystemPlugins.Toolkit.NTIVirtualKeyBoard import NTIVirtualKeyBoard
15
16 version = "1.1"
17
18 sz_w = getDesktop(0).size().width()
19
20
21 class SISetupScreen(ConfigListScreen, Screen):
22
23         if sz_w == 1920:
24                 skin = """
25                 <screen name="SISetupScreen" position="center,170" size="1200,820" title="SkipIntro">
26                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="295,70" scale="stretch" alphatest="on" />
27                         <ePixmap pixmap="skin_default/buttons/green.png" position="305,5" size="295,70" scale="stretch" alphatest="on" />
28                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="600,5" size="295,70" scale="stretch" alphatest="on" />
29                         <ePixmap pixmap="skin_default/buttons/blue.png" position="895,5" size="295,70" scale="stretch" alphatest="on" />
30                         <widget name="key_red" position="10,5" zPosition="1" size="300,70" font="Regular;30" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
31                         <widget name="key_green" position="310,5" zPosition="1" size="300,70" font="Regular;30" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
32                         <widget name="key_yellow" position="610,5" zPosition="1" size="300,70" font="Regular;30" halign="center" valign="center" backgroundColor="#a08500" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
33                         <widget name="key_blue" position="910,5" zPosition="1" size="300,70" font="Regular;30" halign="center" valign="center" backgroundColor="#18188b" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
34                         <widget name="config" position="10,90" itemHeight="35" size="1180,540" enableWrapAround="1" scrollbarMode="showOnDemand" />
35                         <ePixmap pixmap="skin_default/div-h.png" position="10,650" zPosition="2" size="1180,2" />
36                         <widget name="help" position="10,655" size="1180,145" font="Regular;32" />
37                         <eLabel text="MENU" position="1110,770" size="80,35" backgroundColor="#777777" valign="center" halign="center" font="Regular;24"/>
38                         <eLabel text="HELP" position="1020,770" size="80,35" backgroundColor="#777777" valign="center" halign="center" font="Regular;24"/>
39                 </screen>"""
40         else:
41                 skin = """
42                 <screen name="SISetupScreen" position="center,120" size="800,530" title="SkipIntro">
43                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="200,40" scale="stretch" alphatest="on" />
44                         <ePixmap pixmap="skin_default/buttons/green.png" position="200,0" size="200,40" scale="stretch" alphatest="on" />
45                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="400,0" size="200,40" scale="stretch" alphatest="on" />
46                         <ePixmap pixmap="skin_default/buttons/blue.png" position="600,0" size="200,40" scale="stretch" alphatest="on" />
47                         <widget name="key_red" position="0,0" zPosition="1" size="200,40" font="Regular;22" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
48                         <widget name="key_green" position="200,0" zPosition="1" size="200,40" font="Regular;22" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
49                         <widget name="key_yellow" position="400,0" zPosition="1" size="200,40" font="Regular;22" halign="center" valign="center" backgroundColor="#a08500" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
50                         <widget name="key_blue" position="600,0" zPosition="1" size="200,40" font="Regular;22" halign="center" valign="center" backgroundColor="#18188b" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
51                         <widget name="config" position="5,50" itemHeight="30" size="790,390" enableWrapAround="1" scrollbarMode="showOnDemand" />
52                         <ePixmap pixmap="skin_default/div-h.png" position="0,445" zPosition="2" size="800,2" />
53                         <widget name="help" position="5,450" size="790,65" font="Regular;22" />
54                         <eLabel text="MENU" position="735,497" size="60,25" backgroundColor="#777777" valign="center" halign="center" font="Regular;18"/>
55                         <eLabel text="HELP" position="665,497" size="60,25" backgroundColor="#777777" valign="center" halign="center" font="Regular;18"/>
56                 </screen>"""
57
58         def __init__(self, session):
59                 Screen.__init__(self, session)
60
61                 self.session = session
62                 self.list = []
63                 self.database = SIDatabase()
64                 self.database.initialize()
65                 self.database.beginTransaction()
66
67                 ConfigListScreen.__init__(self, self.list, session=session)
68
69                 self["key_red"] = Button(_("Cancel"))
70                 self["key_green"] = Button(_("Save"))
71                 self["key_yellow"] = Button(_("Delete"))
72                 self["key_blue"] = Button(_("Setup"))
73                 self["help"] = Label("")
74
75                 self.itemChanged = False
76                 self.populateList()
77                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions", "MenuActions", "HelpActions"],
78                                                                                  {
79                                                                                          "red": self.cancel,
80                                                                                          "green": self.save,
81                                                                                          "yellow": self.delete,
82                                                                                          "blue": self.setup,
83                                                                                          "save": self.save,
84                                                                                          "cancel": self.cancel,
85                                                                                          "ok": self.save,
86                                                                                          "menu": self.menu,
87                                                                                          "displayHelp": self.help,
88                                                                                  }, -2)
89
90                 self.onLayoutFinish.append(self.layoutFinished)
91                 self["config"].onSelectionChanged.append(self.updateHelp)
92
93         def layoutFinished(self):
94                 self.setTitle(_("SkipIntro Version %s") % version)
95
96         def populateList(self):
97                 self.list = []
98
99                 skipTimes = self.database.getAllSkipTimes()
100                 for name, skipTime in skipTimes:
101                         skipTimeConfig = NoSave(ConfigInteger(default=skipTime / 90000, limits=(0, 3600)))
102                         self.list.append(getConfigListEntry(name, skipTimeConfig, _("Skip time saved for '%s'") % name))
103                 self["config"].list = self.list
104                 self["config"].l.setList(self.list)
105
106         def updateHelp(self):
107                 cur = self["config"].getCurrent()
108                 if cur:
109                         self["help"].text = cur[2]
110
111         def delete(self):
112                 currentSelection = self["config"].getCurrent()
113                 if currentSelection:
114                         self.session.openWithCallback(self.deleteCallBack, MessageBox, _("Do you really want to delete this entry?") + "\n'" + currentSelection[0] + "'")
115
116         def deleteCallBack(self, result):
117                 if result:
118                         currentSelection = self["config"].getCurrent()
119                         self.database.removeSkipTime(currentSelection[0])
120                         self.itemChanged = True
121                         self.populateList()
122
123         def save(self):
124                 #save skiptimes to database
125                 for item in self.list:
126                         self.database.setSkipTime(item[0], item[1].value * 90000)
127                 self.database.commit()
128                 self.close()
129
130         def cancelConfirm(self, result):
131                 if not result:
132                         return
133                 self.database.rollback()
134                 self.close()
135
136         def cancel(self):
137                 if self["config"].isChanged() or self.itemChanged:
138                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Do you really want to close without saving settings?"))
139                 else:
140                         self.database.rollback()
141                         self.close()
142
143         def help(self):
144                 self.session.open(SIHelpScreen)
145
146         def setup(self):
147                 self.session.open(SISettingsScreen)
148
149         def menu(self):
150                 currentSelection = self["config"].getCurrent()
151                 if not currentSelection:
152                         return
153
154                 list = []
155                 #list.append(("--", ""))
156                 list.append((_("Change series name"), "change_series_name"))
157
158                 self.session.openWithCallback(
159                         self.menuCallback,
160                         ChoiceBox,
161                         title = _('Menu SkipIntro'),
162                         list = list,
163                 )
164
165         def menuCallback(self, ret):
166                 ret = ret and ret[1]
167                 if ret:
168                         if ret == "change_series_name":
169                                 currentSelection = self["config"].getCurrent()
170                                 if currentSelection:
171                                         self.session.openWithCallback(
172                                                 self.NTIVirtualKeyBoardCallback,
173                                                 NTIVirtualKeyBoard,
174                                                 title = _("Enter series name"),
175                                                 text = currentSelection[0]
176                                                 )
177
178         def NTIVirtualKeyBoardCallback(self, ret):
179                 if ret:
180                         currentSelection = self["config"].getCurrent()
181                         if currentSelection:
182                                 self.database.renameSeries(currentSelection[0], ret)
183                                 self.itemChanged = True
184                                 self.populateList()
185
186 class SISettingsScreen(ConfigListScreen, Screen):
187
188         if sz_w == 1920:
189                 skin = """
190                 <screen name="SISettingsScreen" position="center,170" size="1200,820" title="SkipIntro">
191                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="295,70" scale="stretch" alphatest="on" />
192                         <ePixmap pixmap="skin_default/buttons/green.png" position="305,5" size="295,70" scale="stretch" alphatest="on" />
193                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="600,5" size="295,70" scale="stretch" alphatest="on" />
194                         <ePixmap pixmap="skin_default/buttons/blue.png" position="895,5" size="295,70" scale="stretch" alphatest="on" />
195                         <widget name="key_red" position="10,5" zPosition="1" size="295,70" font="Regular;30" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
196                         <widget name="key_green" position="310,5" zPosition="1" size="300,70" font="Regular;30" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
197                         <widget name="key_yellow" position="610,5" zPosition="1" size="300,70" font="Regular;30" halign="center" valign="center" backgroundColor="#a08500" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
198                         <widget name="key_blue" position="910,5" zPosition="1" size="300,70" font="Regular;30" halign="center" valign="center" backgroundColor="#18188b" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
199                         <widget name="config" position="10,90" itemHeight="35" size="1180,540" enableWrapAround="1" scrollbarMode="showOnDemand" />
200                         <ePixmap pixmap="skin_default/div-h.png" position="10,650" zPosition="2" size="1180,2" />
201                         <widget name="help" position="10,655" size="1180,145" font="Regular;32" />
202                 </screen>"""
203         else:
204                 skin = """
205                 <screen name="SISettingsScreen" position="center,120" size="800,530" title="SkipIntro">
206                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="200,40" scale="stretch" alphatest="on" />
207                         <ePixmap pixmap="skin_default/buttons/green.png" position="200,0" size="200,40" scale="stretch" alphatest="on" />
208                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="400,0" size="200,40" scale="stretch" alphatest="on" />
209                         <ePixmap pixmap="skin_default/buttons/blue.png" position="600,0" size="200,40" scale="stretch" alphatest="on" />
210                         <widget name="key_red" position="0,0" zPosition="1" size="200,40" font="Regular;22" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
211                         <widget name="key_green" position="200,0" zPosition="1" size="200,40" font="Regular;22" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
212                         <widget name="key_yellow" position="400,0" zPosition="1" size="200,40" font="Regular;22" halign="center" valign="center" backgroundColor="#a08500" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
213                         <widget name="key_blue" position="600,0" zPosition="1" size="200,40" font="Regular;22" halign="center" valign="center" backgroundColor="#18188b" transparent="1" shadowColor="black" shadowOffset="-2,-2" />
214                         <widget name="config" position="5,50" itemHeight="30" size="790,390" enableWrapAround="1" scrollbarMode="showOnDemand" />
215                         <ePixmap pixmap="skin_default/div-h.png" position="0,445" zPosition="2" size="800,2" />
216                         <widget name="help" position="5,450" size="790,65" font="Regular;22" />
217                 </screen>"""
218
219         def __init__(self, session):
220                 Screen.__init__(self, session)
221
222                 self.session = session
223                 self.list = []
224
225                 ConfigListScreen.__init__(self, self.list, session=session)
226
227                 self["key_red"] = Button(_("Cancel"))
228                 self["key_green"] = Button(_("Save"))
229                 self["key_yellow"] = Button(_(" "))
230                 self["key_blue"] = Button(_(" "))
231                 self["help"] = Label("")
232
233                 self.populateList()
234                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
235                                                                                  {
236                                                                                          "red": self.keyCancel,
237                                                                                          "green": self.keySave,
238                                                                                          "save": self.keySave,
239                                                                                          "cancel": self.keyCancel,
240                                                                                          "ok": self.keySave,
241                                                                                  }, -2)
242
243                 self.onLayoutFinish.append(self.layoutFinished)
244                 self["config"].onSelectionChanged.append(self.updateHelp)
245
246         def layoutFinished(self):
247                 self.setTitle(_("SkipIntro Version %s") % version)
248
249         def populateList(self):
250                 self.list = [
251                         getConfigListEntry(_("Show message when skipping intro"), config.plugins.skipintro.show_skipmsg, _("Displays a message when button '2' is pressed to skip the intro.")),
252                         getConfigListEntry(_("Show message when playback of recording starts"), config.plugins.skipintro.show_videostartmsg, _("Displays a message when the playback of the recording starts and a skip time has already been saved for this series.")),
253                         getConfigListEntry(_("Auto-reduce calculated skip time (in seconds)"), config.plugins.skipintro.skiptime_decrease, _("Automatically reduces the skip time by the defined number of seconds when saving the skip time.")),
254                         getConfigListEntry(_("Pattern for series name (title)"), config.plugins.skipintro.title_pattern, _("Select the title pattern to identify the series from the recording title. If disabled the complete recording title is used.")),
255                 #self.list.append( getConfigListEntry(_("Identify series with season"), config.plugins.skipintro.save_season, _("Identify the series from the record title with the season. So you can use different skip times with different seasons.")) )
256                 ]
257                 self["config"].list = self.list
258                 self["config"].l.setList(self.list)
259
260         def updateHelp(self):
261                 cur = self["config"].getCurrent()
262                 if cur:
263                         self["help"].text = cur[2]
264
265
266 class SIHelpScreen(Screen):
267
268         if sz_w == 1920:
269                 skin = """
270                 <screen name="SIHelpScreen" position="center,170" size="1200,820" title="SkipIntro Help">
271                         <widget name="help" position="20,5" size="1100,780" font="Regular;30" />
272                 </screen>"""
273         else:
274                 skin = """
275                 <screen name="SIHelpScreen" position="center,120" size="800,530" title="SkipIntro Help">
276                         <widget name="help" position="10,5" size="760,500" font="Regular;21" />
277                 </screen>"""
278
279         def __init__(self, session):
280                 Screen.__init__(self, session)
281                 self.session = session
282
283                 help_txt = _("==== Remote control button definitions when playing a recording ====\n\n")
284                 help_txt += _("=== Remote control button 2 ===\n")
285                 help_txt += _("- skip by a stored skip time or\n")
286                 help_txt += _("- start timekeeping when no skip time is stored or\n")
287                 help_txt += _("- stop timekeeping (save without season number)\n\n")
288                 help_txt += _("=== Remote control button 2 (long press) ===\n")
289                 help_txt += _("- start timekeeping when skip time is already stored or \n")
290                 help_txt += _("- stop timekeeping (save with season number)\n\n")
291                 help_txt += _("Remote control button 8 can be used as an alternative to 2 (long press).\n\n")
292                 help_txt += _("==== Configuration of title pattern ====\n\n")
293                 help_txt += _("Pattern stored in '/etc/enigma2/SkipIntro.pattern.json' can be selected in settings")
294
295                 self["help"] = ScrollLabel(help_txt)
296
297                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
298                                                                                  {
299                                                                                          "red": self.close,
300                                                                                          "cancel": self.close,
301                                                                                          "ok": self.close,
302                                                                                  }, -2)
303
304                 self.onLayoutFinish.append(self.layoutFinished)
305
306         def layoutFinished(self):
307                 self.setTitle(_("SkipIntro Version %s - Help") % version)