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