[Ai.HD and Vali.XD controllers] GH fix
[enigma2-plugins.git] / aihdcontroler / src / plugin.py
1 #######################################################################
2 #
3 #
4 #    Ai-HD-Skins Control for Dreambox/Enigma-2
5 #    Coded by Vali (c)2009-2011
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.vhd  = ConfigSubsection()
44 config.plugins.vhd.Style = ConfigSelection(default="dmm", choices = [
45                                 ("dmm", _("DMM-Board")),
46                                 ("shadow", _("Shadow")),
47                                 ("beyonddreams", _("BeyondDreams-HD")),
48                                 ("whiteline", _("WhiteLine")),
49                                 ("liga", _("LigaLine")),
50                                 ("dc", _("Concinnity")),
51                                 ("bluesofdream", _("BluesOfDream-HD"))
52                                 ])
53 config.plugins.vhd.ChannSelector = ConfigSelection(default="full", choices = [
54                                 ("full", _("Full")),
55                                 ("vert", _("Full vertikal")),
56                                 ("pig", _("mini TV")),
57                                 ("simple", _("Simple"))
58                                 ])
59 config.plugins.vhd.OledStyle = ConfigSelection(default="full", choices = [
60                                 ("full", _("Full")),
61                                 ("simple", _("Simple"))
62                                 ])
63
64
65
66 def main(session, **kwargs):
67         session.open(AIHDsetup)
68
69
70
71 def Plugins(**kwargs):
72         return PluginDescriptor(name="Ai.HD Controler", description=_("Configuration tool for All.In HD skins"), where = PluginDescriptor.WHERE_PLUGINMENU, icon="plugin.png", fnc=main)
73
74
75
76 #######################################################################
77
78
79
80
81 class AIHDsetup(ConfigListScreen, Screen):
82         skin = """
83                 <screen name="AIHDsetup" position="center,center" size="600,340" title="Ai.HD Controler">
84                         <eLabel font="Regular;20" foregroundColor="#00ff4A3C" halign="center" position="20,308" size="120,26" text="Cancel"/>
85                         <eLabel font="Regular;20" foregroundColor="#0056C856" halign="center" position="165,308" size="120,26" text="Save"/>
86                         <widget name="config" position="5,5" scrollbarMode="showOnDemand" size="590,300"/>
87                 </screen>"""
88
89         def __init__(self, session):
90                 self.release = ".release20110505"
91                 Screen.__init__(self, session)
92                 self.session = session
93                 self.datei = "/usr/share/enigma2/Ai.HD/skin.xml"
94                 self.daten = "/usr/lib/enigma2/python/Plugins/Extensions/AiHDcontroler/data/"
95                 self.komponente = "/usr/lib/enigma2/python/Plugins/Extensions/AiHDcontroler/comp/"
96                 list = []
97                 list.append(getConfigListEntry(_("Infobar and window style:"), config.plugins.vhd.Style))
98                 list.append(getConfigListEntry(_("Channel and EPG selectors style:"), config.plugins.vhd.ChannSelector))
99                 list.append(getConfigListEntry(_("OLED display style:"), config.plugins.vhd.OledStyle))
100                 ConfigListScreen.__init__(self, list)
101                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], 
102                                                                         {
103                                                                         "red": self.exit, 
104                                                                         "green": self.save,
105                                                                         "cancel": self.exit
106                                                                         }, -1)
107                 self.onLayoutFinish.append(self.UpdateComponents)
108
109         def UpdateComponents(self):
110                 if not fileExists(self.datei + self.release):
111                         system("tar -xzvf " + self.komponente + "AiHD.tar.gz" + " -C /")
112                         system('cp ' + self.komponente + 'vhdRendVolumeText.py /usr/lib/enigma2/python/Components/Renderer/vhdRendVolumeText.py')
113                         system('cp ' + self.komponente + 'vhdRendChNumber.py /usr/lib/enigma2/python/Components/Renderer/vhdRendChNumber.py')
114                         system('cp ' + self.komponente + 'vhdRendVideoSize.py /usr/lib/enigma2/python/Components/Renderer/vhdRendVideoSize.py')
115                         system('cp ' + self.komponente + 'vhdRendMovieDirSize.py /usr/lib/enigma2/python/Components/Renderer/vhdRendMovieDirSize.py')
116                         system('cp ' + self.komponente + 'vhdRendMaxTemp.py /usr/lib/enigma2/python/Components/Renderer/vhdRendMaxTemp.py')
117                         system('cp ' + self.komponente + 'vhdRendNextEvent.py /usr/lib/enigma2/python/Components/Renderer/vhdRendNextEvent.py')
118                         system('cp ' + self.komponente + 'vhdConvSmartInfo.py /usr/lib/enigma2/python/Components/Converter/vhdConvSmartInfo.py')
119                         system('cp ' + self.komponente + 'vhdConvClockToText.py /usr/lib/enigma2/python/Components/Converter/vhdConvClockToText.py')
120                         system('cp ' + self.komponente + 'valiRefString.py /usr/lib/enigma2/python/Components/Converter/valiRefString.py')
121                         system("touch " + self.datei + self.release)
122
123         def save(self):
124                 if not fileExists(self.datei + self.release):
125                         for x in self["config"].list:
126                                 x[1].cancel()
127                         self.close()
128                         return
129                 for x in self["config"].list:
130                         x[1].save()
131                 try:
132                         skin_lines = []
133                         head_file = self.daten + "head.xml"
134                         skFile = open(head_file, "r")
135                         head_lines = skFile.readlines()
136                         skFile.close()
137                         for x in head_lines:
138                                 skin_lines.append(x)
139                         skn_file = self.daten + "skin-" + config.plugins.vhd.Style.value + ".xml"
140                         skFile = open(skn_file, "r")
141                         file_lines = skFile.readlines()
142                         skFile.close()
143                         for x in file_lines:
144                                 skin_lines.append(x)
145                         oled_file = self.daten + "oled-" + config.plugins.vhd.OledStyle.value + ".xml"
146                         skFile = open(oled_file, "r")
147                         oled_lines = skFile.readlines()
148                         skFile.close()
149                         for x in oled_lines:
150                                 skin_lines.append(x)
151                         skn_file = self.daten + "channelselector-"
152                         if config.plugins.vhd.ChannSelector.value=="pig":
153                                 skn_file = skn_file + "pig.xml"
154                         elif config.plugins.vhd.ChannSelector.value=="simple":
155                                 skn_file = skn_file + "simple.xml"
156                         elif config.plugins.vhd.ChannSelector.value=="vert":
157                                 skn_file = skn_file + "vert.xml"
158                         else:
159                                 skn_file = skn_file + "full.xml"
160                         skFile = open(skn_file, "r")
161                         file_lines = skFile.readlines()
162                         skFile.close()
163                         for x in file_lines:
164                                 skin_lines.append(x)
165                         base_file = self.daten + "main.xml"
166                         skFile = open(base_file, "r")
167                         file_lines = skFile.readlines()
168                         skFile.close()
169                         for x in file_lines:
170                                 skin_lines.append(x)
171                         xFile = open(self.datei, "w")
172                         for xx in skin_lines:
173                                 xFile.writelines(xx)
174                         xFile.close()
175                 except:
176                         self.session.open(MessageBox, _("Error by processing the skin file !!!"), MessageBox.TYPE_ERROR)
177                 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)
178                 restartbox.setTitle(_("Restart GUI now?"))
179
180         def restartGUI(self, answer):
181                 if answer is True:
182                         self.session.open(TryQuitMainloop, 3)
183                 else:
184                         self.close()
185
186         def exit(self):
187                 for x in self["config"].list:
188                         x[1].cancel()
189                 self.close()
190
191
192
193
194
195
196