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