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