[MerlinSkinThemes] - add support for globals
[enigma2-plugins.git] / serienfilm / src / SerienFilm.py
1 # -*- coding: utf-8 -*-
2 import os
3 from Components.ConfigList import ConfigListScreen
4 from Screens.Screen import Screen
5 from Components.Label import Label
6 from Components.ActionMap import HelpableActionMap, ActionMap, NumberActionMap
7
8 from Components.Input import Input
9 from Screens.InputBox import InputBox
10 from Screens.MessageBox import MessageBox
11
12 SerienFilmVersion = "v1.1"
13
14
15
16 class SerienFilmCfg(Screen):
17         skin = """
18                 <screen position="130,150" size="500,200" title="SerienFilm setup" >
19                         <widget name="myLabel" position="10,20" size="480,160" font="Regular;20"/>
20                 </screen>"""
21
22         def __init__(self, session, args = None):
23                 print "[SF-Plugin] SerienFilmCfg init"
24                 self.session = session
25                 Screen.__init__(self, session)
26                 self["myLabel"] = Label(_("This plugin is configured by the MENU key in the movielist\n\nApplication details provides the HELP key in the movielist"))
27                 self["myActionMap"] = ActionMap(["SetupActions"],
28                 {
29                         "ok": self.close,
30                         "cancel": self.close
31                 }, -1)
32
33
34 class EpiSepCfg(Screen):
35
36         def __init__(self, session, separator = None):
37
38                 skincontent = """
39                         <widget name="sfLabel" position="10,20" size="590,220" font="Regular;20"/>
40                         <widget name="sfRedBtn" position="10,250" size="140,40" backgroundColor="red" valign="center" halign="center" zPosition="2"  foregroundColor="white" font="Regular;20"/>
41                         <widget name="sfGreenBtn" position="160,250" size="140,40" backgroundColor="green" valign="center" halign="center" zPosition="2"  foregroundColor="white" font="Regular;20"/>
42                         <widget name="sfYellowBtn" position="310,250" size="140,40" backgroundColor="yellow" valign="center" halign="center" zPosition="2"  foregroundColor="white" font="Regular;20"/>
43                         <widget name="sfBlueBtn" position="460,250" size="140,40" backgroundColor="blue" valign="center" halign="center" zPosition="2"  foregroundColor="white" font="Regular;20"/>
44                 </screen>"""
45
46                 self.skin = "<screen position=\"130,150\" size=\"610,300\" title=\"" + _("Configuration of the title:episode separator") + "\" >" + skincontent
47
48                 self.session = session
49                 self.defaultsep = _(": ")
50                 self.newsep = self.currentsep = separator
51                 Screen.__init__(self, session)
52                 self.skinName = "skin"
53
54                 intro = _("Usually the episode of a series is tansmitted separate of the title in the description field\nIn a few series however it is appended to the title behind a colon\ne.g. Tatort: Der Fluch der Mumie\n\nA commen part of the title up to this title:episode separator shared by several movies creates a series")
55                 self.firstlevel = [intro, _("Exit"), _("Set default"), _("Change"), _("Disable ")]
56                 if not separator:
57                         self.firstlevel[4] = _("Enable ")
58
59                 self.secondformat = _("The current title:episode separator is \"%s\" (%d characters)\nTo change it: first Set size and then Edit")
60
61                 self.secondlevel = ["", _("Cancel"), _("Save"), _("Edit"), _("Set size")]
62                 self.secondlevel[0] = self.secondformat % (self.currentsep, len(self.currentsep))
63
64                 self.level = 1
65                 
66                 self["sfLabel"] = Label()
67                 self["sfRedBtn"] = Label()
68                 self["sfGreenBtn"] = Label()
69                 self["sfYellowBtn"] = Label()
70                 self["sfBlueBtn"] = Label()
71                 self["sfActionMap"] = ActionMap(["SetupActions", "ColorActions"],
72                 {
73                         "ok": self.gotOk,
74                         "cancel": self.gotCancel,
75                         "red":  self.gotCancel,
76                         "green": self.gotGreen,
77                         "yellow": self.gotEdit,
78                         "blue": self.gotBlue
79                 }, -1)
80                 self.onShown.append(self.sfsetLabel)
81
82         def gotCancel(self):
83                 if self.newsep == self.currentsep:
84                         self.exitConfirmed(True)
85                 else:
86                         self.session.openWithCallback(self.exitConfirmed, MessageBox, _("Really close without saving settings?"))   
87
88         def exitConfirmed(self, confirmed):
89                 if confirmed:
90                         if self.level == 1:
91                                 self.close(self.currentsep)
92                         else:
93                                 self.newsep = self.currentsep   # discard changes
94                                 self.level = 1
95                                 self.secondlevel[0] = self.secondformat % (self.currentsep, len(self.currentsep))
96                                 self.sfsetLabel()
97
98         def gotOk(self):
99                 if self.level ==1:
100                         self.close(self.newsep)
101                 else:
102                         self.gotGreen() # save and back to level 1
103
104         def gotEdit(self):
105                 if self.level == 1:
106                         self.level = 2;
107                         self.sfsetLabel()
108                 else:
109                         self.session.openWithCallback(self.setSeparator,                # edit serarator
110                                 InputBox,
111                                 windowTitle = _("Edit title:episode separator"),
112                                 title = _("Key 0 provides special chracters, key 1 blank"),
113                                 text = self.newsep,
114                                 maxSize=True,
115                                 type=Input.TEXT)
116
117         def gotGreen(self):
118                 if self.level ==1:
119                         self.currentsep = self.newsep = self.defaultsep # set default
120                 else:
121                         self.currentsep = self.newsep   # save
122                         self.level = 1          # and back to level 1
123                         self.sfsetLabel()
124
125         def gotBlue(self):
126                 if self.level == 1:
127                         if self.newsep:
128                                 self.firstlevel[4] = _("Enable ")
129                                 self.currentsep = ""
130                         else:
131                                 self.firstlevel[4] = _("Disable ")
132                                 self.currentsep = self.defaultsep       # set default
133                         self.setSeparator(self.currentsep)
134                 else:
135                         self.session.openWithCallback(self.setSeparatorSize,    # set size
136                                 InputBox,
137                                 title=_("Number of characters"),
138                                 windowTitle=_("Length of the title:episode separator"),
139                                 text = str(len(self.newsep)),
140                                 type=Input.NUMBER)
141
142
143         def setSeparatorSize(self, length):
144                 len = int(length)
145                 self.setSeparator(self.newsep[:len].ljust(len))
146
147         def setSeparator(self, sep):
148                 if sep == None:
149                         sep = ""
150 #               print "[SF-Plugin] EpiSepCfg.setSeparator >%s< to >%s<" % (self.newsep, sep)
151                 self.newsep = sep
152                 self.secondlevel[0] = self.secondformat % (sep, len(sep))
153                 self.sfsetLabel()
154
155
156         def sfsetLabel(self):
157                 if self.level == 1:
158                         labels = self.firstlevel
159                 else:
160                         labels = self.secondlevel
161                 self["sfLabel"].setText(labels[0])
162                 self["sfRedBtn"].setText(labels[1])
163                 self["sfGreenBtn"].setText(labels[2])
164                 self["sfYellowBtn"].setText(labels[3])
165                 self["sfBlueBtn"].setText(labels[4])
166