Merge pull request #115 from mx3L/topic_ehttpstream_headers
[openblackhole/openblackhole-enigma2.git] / lib / python / Plugins / SystemPlugins / SkinSelector / plugin.py
1 # -*- coding: iso-8859-1 -*-
2 # (c) 2006 Stephan Reichholf
3 # This Software is Free, use it where you want, when you want for whatever you want and modify it if you want but don't remove my copyright!
4 from Screens.Screen import Screen
5 from Screens.Standby import TryQuitMainloop
6 from Screens.MessageBox import MessageBox
7 from Components.ActionMap import NumberActionMap
8 from Components.Pixmap import Pixmap
9 from Components.Sources.StaticText import StaticText
10 from Components.MenuList import MenuList
11 from Plugins.Plugin import PluginDescriptor
12 from Components.config import config
13 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
14 from enigma import eEnv
15 import os
16
17 SKINXML = "skin.xml"
18 DEFAULTSKIN = "<Default Skin>"
19
20 class SkinSelector(Screen):
21
22         skinlist = []
23         root = os.path.join(eEnv.resolve("${datadir}"),"enigma2")
24
25         def __init__(self, session, args = None):
26
27                 Screen.__init__(self, session)
28
29                 self.setTitle(_("Select your Skin"))
30
31                 self.skinlist = []
32                 self.previewPath = ""
33                 if os.path.exists(os.path.join(self.root, SKINXML)):
34                         self.skinlist.append(DEFAULTSKIN)
35                 for root, dirs, files in os.walk(self.root, followlinks=True):
36                         for subdir in dirs:
37                                 dir = os.path.join(root,subdir)
38                                 if os.path.exists(os.path.join(dir,SKINXML)):
39                                         self.skinlist.append(subdir)
40                         dirs = []
41
42                 self["key_red"] = StaticText(_("Close"))
43                 self["introduction"] = StaticText(_("Press OK to activate the selected skin."))
44                 self.skinlist.sort()
45                 self["SkinList"] = MenuList(self.skinlist)
46                 self["Preview"] = Pixmap()
47
48                 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "EPGSelectActions"],
49                 {
50                         "ok": self.ok,
51                         "back": self.close,
52                         "red": self.close,
53                         "up": self.up,
54                         "down": self.down,
55                         "left": self.left,
56                         "right": self.right,
57                         "info": self.info,
58                 }, -1)
59
60                 self.onLayoutFinish.append(self.layoutFinished)
61
62         def layoutFinished(self):
63                 tmp = config.skin.primary_skin.value.find("/"+SKINXML)
64                 if tmp != -1:
65                         tmp = config.skin.primary_skin.value[:tmp]
66                         idx = 0
67                         for skin in self.skinlist:
68                                 if skin == tmp:
69                                         break
70                                 idx += 1
71                         if idx < len(self.skinlist):
72                                 self["SkinList"].moveToIndex(idx)
73                 self.loadPreview()
74
75         def up(self):
76                 self["SkinList"].up()
77                 self.loadPreview()
78
79         def down(self):
80                 self["SkinList"].down()
81                 self.loadPreview()
82
83         def left(self):
84                 self["SkinList"].pageUp()
85                 self.loadPreview()
86
87         def right(self):
88                 self["SkinList"].pageDown()
89                 self.loadPreview()
90
91         def info(self):
92                 aboutbox = self.session.open(MessageBox,_("Enigma2 skin selector"), MessageBox.TYPE_INFO)
93                 aboutbox.setTitle(_("About..."))
94
95         def ok(self):
96                 if self["SkinList"].getCurrent() == DEFAULTSKIN:
97                         self.skinfile = "."
98                 else:
99                         self.skinfile = self["SkinList"].getCurrent()
100                 self.skinfile = os.path.join(self.skinfile, SKINXML)
101
102                 print "Skinselector: Selected Skin: "+self.root+self.skinfile
103                 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)
104                 restartbox.setTitle(_("Restart GUI"))
105
106         def loadPreview(self):
107                 if self["SkinList"].getCurrent() == DEFAULTSKIN:
108                         pngpath = "."
109                 else:
110                         pngpath = self["SkinList"].getCurrent()
111                 pngpath = os.path.join(os.path.join(self.root, pngpath), "prev.png")
112
113                 if not os.path.exists(pngpath):
114                         pngpath = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/SkinSelector/noprev.png")
115
116                 if self.previewPath != pngpath:
117                         self.previewPath = pngpath
118
119                 self["Preview"].instance.setPixmapFromFile(self.previewPath)
120
121         def restartGUI(self, answer):
122                 if answer is True:
123                         config.skin.primary_skin.value = self.skinfile
124                         config.skin.primary_skin.save()
125                         self.session.open(TryQuitMainloop, 3)
126
127 def SkinSelMain(session, **kwargs):
128         session.open(SkinSelector)
129
130 def SkinSelSetup(menuid, **kwargs):
131         if menuid == "system":
132                 return [(_("Skin selector"), SkinSelMain, "skin_selector", None)]
133         else:
134                 return []
135
136 def Plugins(**kwargs):
137         return PluginDescriptor(name="Skin selector", description= _("Select your Skin"), where = PluginDescriptor.WHERE_MENU, needsRestart = False, fnc=SkinSelSetup)