use eEnv::resolve() / eEnv.resolve()
[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 os import path, walk
15 from enigma import eEnv
16
17 class SkinSelector(Screen):
18         # for i18n:
19         # _("Choose your Skin")
20         skinlist = []
21         root = eEnv.resolve("${datadir}/enigma2/")
22
23         def __init__(self, session, args = None):
24
25                 Screen.__init__(self, session)
26
27                 self.skinlist = []
28                 self.previewPath = ""
29                 path.walk(self.root, self.find, "")
30
31                 self["key_red"] = StaticText(_("Close"))
32                 self["introduction"] = StaticText(_("Press OK to activate the selected skin."))
33                 self.skinlist.sort()
34                 self["SkinList"] = MenuList(self.skinlist)
35                 self["Preview"] = Pixmap()
36
37                 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "EPGSelectActions"],
38                 {
39                         "ok": self.ok,
40                         "back": self.close,
41                         "red": self.close,
42                         "up": self.up,
43                         "down": self.down,
44                         "left": self.left,
45                         "right": self.right,
46                         "info": self.info,
47                 }, -1)
48
49                 self.onLayoutFinish.append(self.layoutFinished)
50
51         def layoutFinished(self):
52                 tmp = config.skin.primary_skin.value.find('/skin.xml')
53                 if tmp != -1:
54                         tmp = config.skin.primary_skin.value[:tmp]
55                         idx = 0
56                         for skin in self.skinlist:
57                                 if skin == tmp:
58                                         break
59                                 idx += 1
60                         if idx < len(self.skinlist):
61                                 self["SkinList"].moveToIndex(idx)
62                 self.loadPreview()
63
64         def up(self):
65                 self["SkinList"].up()
66                 self.loadPreview()
67
68         def down(self):
69                 self["SkinList"].down()
70                 self.loadPreview()
71
72         def left(self):
73                 self["SkinList"].pageUp()
74                 self.loadPreview()
75
76         def right(self):
77                 self["SkinList"].pageDown()
78                 self.loadPreview()
79
80         def info(self):
81                 aboutbox = self.session.open(MessageBox,_("Enigma2 Skinselector\n\nIf you experience any problems please contact\nstephan@reichholf.net\n\n\xA9 2006 - Stephan Reichholf"), MessageBox.TYPE_INFO)
82                 aboutbox.setTitle(_("About..."))
83
84         def find(self, arg, dirname, names):
85                 for x in names:
86                         if x == "skin.xml":
87                                 if dirname <> self.root:
88                                         subdir = dirname[19:]
89                                         self.skinlist.append(subdir)
90                                 else:
91                                         subdir = "Default Skin"
92                                         self.skinlist.append(subdir)
93
94         def ok(self):
95                 if self["SkinList"].getCurrent() == "Default Skin":
96                         skinfile = "skin.xml"
97                 else:
98                         skinfile = self["SkinList"].getCurrent()+"/skin.xml"
99
100                 print "Skinselector: Selected Skin: "+self.root+skinfile
101                 config.skin.primary_skin.value = skinfile
102                 config.skin.primary_skin.save()
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 now?"))
105
106         def loadPreview(self):
107                 if self["SkinList"].getCurrent() == "Default Skin":
108                         pngpath = self.root+"/prev.png"
109                 else:
110                         pngpath = self.root+self["SkinList"].getCurrent()+"/prev.png"
111
112                 if not path.exists(pngpath):
113                         pngpath = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/SkinSelector/noprev.png")
114
115                 if self.previewPath != pngpath:
116                         self.previewPath = pngpath
117
118                 self["Preview"].instance.setPixmapFromFile(self.previewPath)
119
120         def restartGUI(self, answer):
121                 if answer is True:
122                         self.session.open(TryQuitMainloop, 3)
123
124 def SkinSelMain(session, **kwargs):
125         session.open(SkinSelector)
126
127 def SkinSelSetup(menuid, **kwargs):
128         if menuid == "system":
129                 return [(_("Skin"), SkinSelMain, "skin_selector", None)]
130         else:
131                 return []
132
133 def Plugins(**kwargs):
134         return PluginDescriptor(name="Skinselector", description="Select Your Skin", where = PluginDescriptor.WHERE_MENU, fnc=SkinSelSetup)