b0418de0fffb487136ee199f40b4ef317013320d
[vuplus_dvbapp] / 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.MessageBox import MessageBox
6 from Components.ActionMap import NumberActionMap
7 from Components.Pixmap import Pixmap
8 from Components.MenuList import MenuList
9 from Plugins.Plugin import PluginDescriptor
10 from Components.config import config
11 from Tools.Directories import SCOPE_SKIN
12 from Components.config import config
13
14 from os import path, walk
15 from enigma import quitMainloop
16
17 class SkinSelector(Screen):
18         # for i18n:
19         # _("Choose your Skin")
20         skin = """
21                 <screen position="75,138" size="600,320" title="Choose your Skin" >
22                         <widget name="SkinList" position="10,10" size="275,300" scrollbarMode="showOnDemand" />
23                         <widget name="Preview" position="305,45" size="280,210" alphatest="on"/>
24                 </screen>
25                 """
26
27         skinlist = []
28         root = "/usr/share/enigma2/"
29
30         def __init__(self, session, args = None):
31
32                 self.skin = SkinSelector.skin
33                 Screen.__init__(self, session)
34
35                 self.skinlist = []
36                 self.session = session
37                 self.previewPath = ""
38
39                 path.walk(self.root, self.find, "")
40
41                 self.skinlist.sort()
42                 self["SkinList"] = MenuList(self.skinlist)
43                 self["Preview"] = Pixmap()
44
45                 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "EPGSelectActions"],
46                 {
47                         "ok": self.ok,
48                         "back": self.close,
49                         "up": self.up,
50                         "down": self.down,
51                         "left": self.left,
52                         "right": self.right,
53                         "info": self.info,
54                 }, -1)
55                 
56                 self.onLayoutFinish.append(self.loadPreview)
57
58         def up(self):
59                 self["SkinList"].up()
60                 self.loadPreview()
61
62         def down(self):
63                 self["SkinList"].down()
64                 self.loadPreview()
65
66         def left(self):
67                 self["SkinList"].pageUp()
68                 self.loadPreview()
69
70         def right(self):
71                 self["SkinList"].pageDown()
72                 self.loadPreview()
73
74         def info(self):
75                 aboutbox = self.session.open(MessageBox,_("Enigma2 Skinselector v0.5 BETA\n\nIf you experience any problems please contact\nstephan@reichholf.net\n\n\xA9 2006 - Stephan Reichholf"), MessageBox.TYPE_INFO)
76                 aboutbox.setTitle(_("About..."))
77
78         def find(self, arg, dirname, names):
79                 for x in names:
80                         if x == "skin.xml":
81                                 if dirname <> self.root:
82                                         subdir = dirname[19:]
83                                         self.skinlist.append(subdir)
84                                 else:
85                                         subdir = "Default Skin"
86                                         self.skinlist.append(subdir)
87
88         def ok(self):
89                 if self["SkinList"].getCurrent() == "Default Skin":
90                         skinfile = "skin.xml"
91                 else:
92                         skinfile = self["SkinList"].getCurrent()+"/skin.xml"
93
94                 print "Skinselector: Selected Skin: "+self.root+skinfile
95                 config.skin.primary_skin.value = skinfile
96                 config.skin.primary_skin.save()
97                 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)
98                 restartbox.setTitle(_("Restart GUI now?"))
99
100         def loadPreview(self):
101                 if self["SkinList"].getCurrent() == "Default Skin":
102                         pngpath = self.root+"/prev.png"
103                 else:
104                         pngpath = self.root+self["SkinList"].getCurrent()+"/prev.png"
105
106                 if not path.exists(pngpath):
107                         # FIXME: don't use hardcoded path
108                         pngpath = "/usr/lib/enigma2/python/Plugins/SystemPlugins/SkinSelector/noprev.png"
109
110                 if self.previewPath != pngpath:
111                         self.previewPath = pngpath
112
113                 self["Preview"].instance.setPixmapFromFile(self.previewPath)
114
115         def restartGUI(self, answer):
116                 if answer is True:
117                         quitMainloop(3)
118
119 def SkinSelMain(session, **kwargs):
120         session.open(SkinSelector)
121
122 def SkinSelSetup(menuid):
123         if menuid == "system":
124                 return [("Skin...", SkinSelMain)]
125         else:
126                 return []
127
128 def Plugins(**kwargs):
129         return PluginDescriptor(name="Skinselector", description="Select Your Skin", where = PluginDescriptor.WHERE_SETUP, fnc=SkinSelSetup)