update .gitignore
[enigma2-plugins.git] / valixdcontrol / src / plugin.py
1 #######################################################################
2 #
3 #    Vali-XD-Skins Control for Dreambox/Enigma-2
4 #    Coded by Vali (c)2009-2011
5 #
6 #  This plugin is licensed under the Creative Commons 
7 #  Attribution-NonCommercial-ShareAlike 3.0 Unported License.
8 #  To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
9 #  or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
10 #
11 #  Alternatively, this plugin may be distributed and executed on hardware which
12 #  is licensed by Dream Multimedia GmbH.
13 #
14 #  This plugin is NOT free software. It is open source, you are allowed to
15 #  modify it (if you keep the license), but it may not be commercially 
16 #  distributed other than under the conditions noted above.
17 #
18 #######################################################################
19
20
21
22 from Plugins.Plugin import PluginDescriptor
23 from Screens.Screen import Screen
24 from Screens.MessageBox import MessageBox
25 from Screens.ChoiceBox import ChoiceBox
26 from Screens.Console import Console
27 from Screens.Standby import TryQuitMainloop
28 from Components.ActionMap import ActionMap
29 from Components.config import config, ConfigYesNo, ConfigSubsection, getConfigListEntry, ConfigSelection, ConfigText, ConfigInteger
30 from Components.ConfigList import ConfigListScreen
31 from Components.Label import Label
32 from Tools.Directories import fileExists
33 from skin import parseColor
34 from os import system
35
36
37
38 config.plugins.valiXDsetup  = ConfigSubsection()
39 config.plugins.valiXDsetup.ShowPicons = ConfigYesNo(default = False)
40 config.plugins.valiXDsetup.CenterMenus = ConfigYesNo(default = False)
41 config.plugins.valiXDsetup.Style = ConfigSelection(default="base", choices = [
42                                 ("base", _("Base")),
43                                 ("beyonddreams", _("Beyond Dreams")),
44                                 ("validator", _("Validator")),
45                                 ("shadow", _("Magic Shadow")),
46                                 ("shadow2", _("New Shadow")),
47                                 ("glas", _("Glas")),
48                                 ("metalpad", _("Metal Pad")),
49                                 ("vision", _("New Vision")),
50                                 ("atlantis", _("Atlantis")),
51                                 ("avalon", _("Avalon")),
52                                 ("blues", _("Blues of dream"))
53                                 ])
54 config.plugins.valiXDsetup.ChannSelector = ConfigSelection(default="simple", choices = [
55                                 ("simple", _("Simple")),
56                                 ("full", _("Full")),
57                                 ("full-vert", _("Full-vertical")),
58                                 ("full-hor", _("Full-horizontal")),
59                                 ("pig", _("with PiG"))
60                                 ])
61 config.plugins.valiXDsetup.dmType = ConfigSelection(default="800", choices = [
62                                 ("800", _("DM-800 Simple")),
63                                 ("8000", _("DM-8000 Full")),
64                                 ("7025", _("DM-7025")),
65                                 ("verysimple", _("Very simple"))
66                                 ])
67 config.plugins.valiXDsetup.BG = ConfigText(default = "18111112", fixed_size=8)
68 config.plugins.valiXDsetup.FG = ConfigText(default = "f0f0f0", fixed_size=6)
69 config.plugins.valiXDsetup.secondBG = ConfigText(default = "18071230", fixed_size=8)
70 config.plugins.valiXDsetup.secondFG = ConfigText(default = "fcc000", fixed_size=6)
71 config.plugins.valiXDsetup.selBG = ConfigText(default = "08303240", fixed_size=8)
72 config.plugins.valiXDsetup.selFG = ConfigText(default = "fcc000", fixed_size=6)
73 config.plugins.valiXDsetup.pollTime = ConfigInteger(default = 15, limits = (3, 60))
74
75
76
77 def main(session, **kwargs):
78         if fileExists("/usr/share/enigma2/Vali-XD/skin.xml"):
79                 session.open(XDsetup)
80         else:
81                 #session.open(MessageBox,_("Vali-XD skin not installed.\nWe have nothing to control."), MessageBox.TYPE_INFO)
82                 pass
83
84
85
86 def Plugins(**kwargs):
87         return PluginDescriptor(name="Vali-XD Skin Control", description=_("Configuration tool for Vali-XD skins"), where = PluginDescriptor.WHERE_PLUGINMENU, icon="plugin.png", fnc=main)
88
89
90
91 #######################################################################
92
93
94
95
96 class XDsetup(ConfigListScreen, Screen):
97         skin = """
98                 <screen name="XDsetup" position="center,center" size="600,340" title="Vali-XD-Skin Control">
99                         <eLabel font="Regular;20" foregroundColor="#00ff4A3C" halign="center" position="20,308" size="120,26" text="Cancel"/>
100                         <eLabel font="Regular;20" foregroundColor="#0056C856" halign="center" position="165,308" size="120,26" text="Save"/>
101                         <eLabel font="Regular;20" foregroundColor="#00ffc000" halign="center" position="300,308" size="140,26" text="Test colors"/>
102                         <eLabel font="Regular;20" foregroundColor="#00879ce1" halign="center" position="455,308" size="120,26" text="ToolBox"/>
103                         <widget name="config" position="5,5" scrollbarMode="showOnDemand" size="590,300"/>
104                         <widget name="myTestLabel" position="1000,1000" size="2,2"/>
105                 </screen>"""
106
107         def __init__(self, session):
108                 Screen.__init__(self, session)
109                 self.session = session
110                 self.datei = "/usr/share/enigma2/Vali-XD/skin.xml"
111                 self.daten = "/usr/lib/enigma2/python/Plugins/Extensions/ValiXDControl/data/"
112                 self.komponente = "/usr/lib/enigma2/python/Plugins/Extensions/ValiXDControl/comp/"
113                 self["myTestLabel"] = Label(_("t"))
114                 list = []
115                 list.append(getConfigListEntry(_("Infobar and Window Style:"), config.plugins.valiXDsetup.Style))
116                 list.append(getConfigListEntry(_("Channel and EPG selectors Style:"), config.plugins.valiXDsetup.ChannSelector))
117                 list.append(getConfigListEntry(_("Show Picons (Reference):"), config.plugins.valiXDsetup.ShowPicons))
118                 list.append(getConfigListEntry(_("Center Mainmenu and Plugins-list:"), config.plugins.valiXDsetup.CenterMenus))
119                 list.append(getConfigListEntry(_("OLED Layout like:"), config.plugins.valiXDsetup.dmType))
120                 list.append(getConfigListEntry(_("Base background:"), config.plugins.valiXDsetup.BG))
121                 #list.append(getConfigListEntry(_("Base foreground:"), config.plugins.valiXDsetup.FG))
122                 list.append(getConfigListEntry(_("Second background:"), config.plugins.valiXDsetup.secondBG))
123                 list.append(getConfigListEntry(_("Second foreground:"), config.plugins.valiXDsetup.secondFG))
124                 list.append(getConfigListEntry(_("Selected background:"), config.plugins.valiXDsetup.selBG))
125                 list.append(getConfigListEntry(_("Selected foreground:"), config.plugins.valiXDsetup.selFG))
126                 #list.append(getConfigListEntry(_("SmartInfo update time:"), config.plugins.valiXDsetup.pollTime))
127                 ConfigListScreen.__init__(self, list)
128                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], 
129                                                                         {
130                                                                         "red": self.exit, 
131                                                                         "green": self.save, 
132                                                                         "yellow": self.colortest,
133                                                                         "blue": self.toolBox,
134                                                                         "cancel": self.exit
135                                                                         }, -1)
136                 self.onLayoutFinish.append(self.UpdateComponents)
137         
138         def UpdateComponents(self):
139                 system('cp ' + self.komponente + 'vRendVolumeText.py /usr/lib/enigma2/python/Components/Renderer/vRendVolumeText.py')
140                 system('cp ' + self.komponente + 'vRendMaxTemp.py /usr/lib/enigma2/python/Components/Renderer/vRendMaxTemp.py')
141                 system('cp ' + self.komponente + 'vRendChNumber.py /usr/lib/enigma2/python/Components/Renderer/vRendChNumber.py')
142                 system('cp ' + self.komponente + 'vRendVideoSize.py /usr/lib/enigma2/python/Components/Renderer/vRendVideoSize.py')
143                 system('cp ' + self.komponente + 'vRendMovieDirSize.py /usr/lib/enigma2/python/Components/Renderer/vRendMovieDirSize.py')
144                 system('cp ' + self.komponente + 'vConvSmartInfo.py /usr/lib/enigma2/python/Components/Converter/vConvSmartInfo.py')
145                 system('cp ' + self.komponente + 'vConvClockToText.py /usr/lib/enigma2/python/Components/Converter/vConvClockToText.py')
146
147         def save(self):
148                 CompsAreOK = False
149                 if fileExists("/usr/lib/enigma2/python/Components/Renderer/vRendChNumber.py") \
150                         and fileExists("/usr/lib/enigma2/python/Components/Renderer/vRendMaxTemp.py") \
151                         and fileExists("/usr/lib/enigma2/python/Components/Renderer/vRendVolumeText.py") \
152                         and fileExists("/usr/lib/enigma2/python/Components/Renderer/vRendVideoSize.py") \
153                         and fileExists("/usr/lib/enigma2/python/Components/Renderer/vRendMovieDirSize.py") \
154                         and fileExists("/usr/lib/enigma2/python/Components/Converter/vConvSmartInfo.py") \
155                         and fileExists("/usr/lib/enigma2/python/Components/Converter/vConvClockToText.py"):
156                         CompsAreOK = True
157                 if not(CompsAreOK):
158                         self.session.open(MessageBox,_("Vali-XD converters and renderers are not installed!!!"), MessageBox.TYPE_ERROR)
159                         self.close()
160                 for x in self["config"].list:
161                         x[1].save()
162                 try:
163                         skin_lines = []
164                         head_file = self.daten + "head.xml"
165                         skFile = open(head_file, "r")
166                         head_lines = skFile.readlines()
167                         skFile.close()
168                         for x in head_lines:
169                                 skin_lines.append(x)
170                         skn_file = self.daten + "skin-" + config.plugins.valiXDsetup.Style.value
171                         if config.plugins.valiXDsetup.ShowPicons.value:
172                                 skn_file = skn_file + "-picon.xml"
173                         else:
174                                 skn_file = skn_file + ".xml"
175                         if (config.plugins.valiXDsetup.Style.value=='base'):
176                                 if self.checkUserColors():
177                                         skin_lines.append('  <!--  ##### Colors ##### -->\n')
178                                         skin_lines.append('  <colors>\n')
179                                         skin_lines.append('      <color name="background" value="#'+config.plugins.valiXDsetup.BG.value+'"/>\n')
180                                         skin_lines.append('      <color name="foreground" value="#00f0f0f0"/>\n')
181                                         skin_lines.append('      <color name="secondBG" value="#'+config.plugins.valiXDsetup.secondBG.value+'"/>\n')
182                                         skin_lines.append('      <color name="secondFG" value="#00'+config.plugins.valiXDsetup.secondFG.value+'"/>\n')
183                                         skin_lines.append('      <color name="selectedBG" value="#'+config.plugins.valiXDsetup.selBG.value+'"/>\n')
184                                         skin_lines.append('      <color name="selectedFG" value="#00'+config.plugins.valiXDsetup.selFG.value+'"/>\n')
185                                 else:
186                                         skin_lines.append('  <!--  ##### Colors ##### -->\n')
187                                         skin_lines.append('  <colors>\n')
188                                         skin_lines.append('      <color name="background" value="#18111112"/>\n')
189                                         skin_lines.append('      <color name="foreground" value="#00f0f0f0"/>\n')
190                                         skin_lines.append('      <color name="secondBG" value="#18071230"/>\n')
191                                         skin_lines.append('      <color name="secondFG" value="#00fcc000"/>\n')
192                                         skin_lines.append('      <color name="selectedBG" value="#08303240"/>\n')
193                                         skin_lines.append('      <color name="selectedFG" value="#00fcc000"/>\n')
194                         skFile = open(skn_file, "r")
195                         file_lines = skFile.readlines()
196                         skFile.close()
197                         for x in file_lines:
198                                 skin_lines.append(x)
199                         skn_file = self.daten + "channelselector-"
200                         if config.plugins.valiXDsetup.ChannSelector.value=="pig":
201                                 skn_file = skn_file + "pig.xml"
202                         elif config.plugins.valiXDsetup.ChannSelector.value=="full":
203                                 skn_file = skn_file + "full.xml"
204                         elif config.plugins.valiXDsetup.ChannSelector.value=="full-vert":
205                                 skn_file = skn_file + "full-vert.xml"
206                         elif config.plugins.valiXDsetup.ChannSelector.value=="full-hor":
207                                 skn_file = skn_file + "full-hor.xml"
208                         else:
209                                 skn_file = skn_file + "simple.xml"
210                         skFile = open(skn_file, "r")
211                         file_lines = skFile.readlines()
212                         skFile.close()
213                         for x in file_lines:
214                                 skin_lines.append(x)
215                         mnu_file = self.daten + "menu-"
216                         if config.plugins.valiXDsetup.CenterMenus.value:
217                                 mnu_file = mnu_file + "center.xml"
218                         else:
219                                 mnu_file = mnu_file + "right.xml"
220                         skFile = open(mnu_file, "r")
221                         file_lines = skFile.readlines()
222                         skFile.close()
223                         for x in file_lines:
224                                 skin_lines.append(x)
225                         base_file = self.daten + "main.xml"
226                         skFile = open(base_file, "r")
227                         file_lines = skFile.readlines()
228                         skFile.close()
229                         for x in file_lines:
230                                 skin_lines.append(x)
231                         if config.plugins.valiXDsetup.dmType.value == "8000":
232                                 oled_file = self.daten + "oled-8000.xml"
233                         elif config.plugins.valiXDsetup.dmType.value == "7025":
234                                 oled_file = self.daten + "oled-7025.xml"                                
235                         elif config.plugins.valiXDsetup.dmType.value == "verysimple":
236                                 oled_file = self.daten + "oled-VerySymple.xml"
237                         else:
238                                 oled_file = self.daten + "oled-800.xml"
239                         skFile = open(oled_file, "r")
240                         file_lines = skFile.readlines()
241                         skFile.close()
242                         for x in file_lines:
243                                 skin_lines.append(x)
244                         xFile = open(self.datei, "w")
245                         for xx in skin_lines:
246                                 xFile.writelines(xx)
247                         xFile.close()
248                 except:
249                         self.session.open(MessageBox, _("Error by processing the skin file !!!"), MessageBox.TYPE_ERROR)
250                 restartbox = self.session.openWithCallback(self.restartGUI,MessageBox,_("GUI needs a restart to apply a new skin.\nDo you want to Restart the GUI now?"), MessageBox.TYPE_YESNO)
251                 restartbox.setTitle(_("Restart GUI now?"))
252
253         def restartGUI(self, answer):
254                 if answer is True:
255                         self.session.open(TryQuitMainloop, 3)
256                 else:
257                         self.close()
258
259         def exit(self):
260                 for x in self["config"].list:
261                         x[1].cancel()
262                 self.close()
263
264         def toolBox(self):
265                 contextFileList = [(_("Help information"), "INFO"),
266                                                 (_("Install round buttons"), "ROUNDBUTT"),
267                                                 (_("Install magic buttons"), "MAGICBUTT"),
268                                                 (_("Suomipoeka-Movielist patch"), "PATCHSUOMI"),
269                                                 (_("Colored icons patch"), "PATCHCONSTABLE")]
270                 self.session.openWithCallback(self.toolExec, ChoiceBox, title=_("Vali-XD Tool Box..."), list=contextFileList)
271         
272         def toolExec(self, answer):
273                 answer = answer and answer[1]
274                 if answer == "INFO":
275                         hilfeText = _("Color format: TTRRGGBB (hexadecimal)\nTT=Transparenty RR=Red GG=Green BB=Blue\nSee more colors by www.colorpicker.com\n\nSupport: www.dreambox-tools.info")
276                         self.session.open(MessageBox, hilfeText, MessageBox.TYPE_INFO)
277                 elif answer == "PATCHSUOMI":
278                         self.session.open(Console, cmdlist=[("chmod 755 " + self.komponente + "suomi_patch"), (self.komponente + "suomi_patch")])
279                 elif answer == "PATCHCONSTABLE":
280                         self.session.open(Console, cmdlist=[("tar -xzvf " + self.komponente + "spetial_icons.tar.gz" + " -C /")])
281                 elif answer == "ROUNDBUTT":
282                         self.session.open(Console, cmdlist=[("tar -xzvf " + self.komponente + "round_buttons.tar.gz" + " -C /")])
283                 elif answer == "MAGICBUTT":
284                         self.session.open(Console, cmdlist=[("tar -xzvf " + self.komponente + "magic_buttons.tar.gz" + " -C /")])
285
286         def checkUserColors(self):
287                 if (config.plugins.valiXDsetup.Style.value=='base'):
288                         try:
289                                 self["myTestLabel"].instance.setBackgroundColor(parseColor('#'+config.plugins.valiXDsetup.BG.value))
290                                 self["myTestLabel"].instance.setBackgroundColor(parseColor('#'+config.plugins.valiXDsetup.FG.value))
291                                 self["myTestLabel"].instance.setBackgroundColor(parseColor('#'+config.plugins.valiXDsetup.secondBG.value))
292                                 self["myTestLabel"].instance.setBackgroundColor(parseColor('#'+config.plugins.valiXDsetup.secondFG.value))
293                                 self["myTestLabel"].instance.setBackgroundColor(parseColor('#'+config.plugins.valiXDsetup.selBG.value))
294                                 self["myTestLabel"].instance.setBackgroundColor(parseColor('#'+config.plugins.valiXDsetup.selFG.value))
295                                 config.plugins.valiXDsetup.BG.save()
296                                 config.plugins.valiXDsetup.FG.save()
297                                 config.plugins.valiXDsetup.secondBG.save()
298                                 config.plugins.valiXDsetup.secondFG.save()
299                                 config.plugins.valiXDsetup.selBG.save()
300                                 config.plugins.valiXDsetup.selFG.save()
301                                 return True
302                         except:
303                                 self.session.open(MessageBox, _("There are errors in the color-strings!\nThe PlugIn will use default colors."), MessageBox.TYPE_ERROR)
304                                 return False
305                 else:
306                         self.session.open(MessageBox, _("Colors setup are only for Base-Style possible."), MessageBox.TYPE_INFO)
307
308         def colortest(self):
309                 if self.checkUserColors():
310                         PreviewString='<screen backgroundColor="#'+config.plugins.valiXDsetup.BG.value+'" flags="wfNoBorder" position="0,433" size="1024,176" title="Preview">\n'
311                         PreviewString=PreviewString+'<ePixmap alphatest="off" pixmap="Vali-XD/border/up-shadow.png" position="0,0" size="1024,8" zPosition="0"/>\n'
312                         PreviewString=PreviewString+'<eLabel backgroundColor="#'+config.plugins.valiXDsetup.secondBG.value+'" font="Regular;22" foregroundColor="#'+config.plugins.valiXDsetup.secondFG.value
313                         PreviewString=PreviewString+'" halign="center" position="0,8" size="152,168" text="Second foreground" valign="center" zPosition="1"/>\n<eLabel backgroundColor="#'+config.plugins.valiXDsetup.secondBG.value
314                         PreviewString=PreviewString+'" font="Regular;22" foregroundColor="#'+config.plugins.valiXDsetup.secondFG.value+'" halign="center" position="872,8" size="152,168" text="Second foreground" valign="center" zPosition="1"/>\n'
315                         PreviewString=PreviewString+'<eLabel font="Regular;22" foregroundColor="#'+'00f0f0f0'+'" halign="center" position="275,45" size="457,30" text="Main element" valign="center" transparent="1" zPosition="2"/>\n'
316                         PreviewString=PreviewString+'<eLabel backgroundColor="#'+config.plugins.valiXDsetup.selBG.value+'" font="Regular;22" foregroundColor="#'+config.plugins.valiXDsetup.selFG.value
317                         PreviewString=PreviewString+'" halign="center" position="275,80" size="457,30" text="Selected element" valign="center" zPosition="2"/>\n</screen>'
318                         self.session.open(UserStylePreview, PreviewString)
319
320
321
322
323
324
325
326 #######################################################################
327
328
329
330 class UserStylePreview(Screen):
331         def __init__(self, session, prvScreen='<screen position="80,150" size="560,310" title="Template">\n</screen>'):
332                 self.skin = prvScreen
333                 Screen.__init__(self, session)
334                 self["actions"] = ActionMap(["OkCancelActions"], {"ok": self.close, "cancel": self.close}, -1)
335
336
337
338
339
340
341