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