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