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