1 from Plugins.Plugin import PluginDescriptor
2 from Screens.Screen import Screen
3 from Screens.ChoiceBox import ChoiceBox
4 from Components.Label import Label
5 from Components.MenuList import MenuList
6 from Components.ActionMap import ActionMap
7 from Components.config import config,ConfigSubsection,ConfigSelection, getConfigListEntry
8 from Components.ConfigList import ConfigListScreen
10 from os import path as os_path, listdir as os_listdir, system as os_system, remove as os_remove
11 ###############################################################################
12 config.plugins.logomanager = ConfigSubsection()
13 config.plugins.logomanager.path = ConfigSelection([("/media/cf/bootlogos/",_("CF Drive")),("/media/hdd/bootlogos/",_("Harddisk"))],default="/media/hdd/bootlogos/")
16 from mimetypes import add_type
17 add_type("image/mvi", ".mvi")
22 def filescan_open(list, session, **kwargs):
23 print "filescan_open", list,kwargs
24 session.open(LogoManagerScreen,file=list[0].path)
26 def start_from_filescan(**kwargs):
27 from Components.Scanner import Scanner, ScanPath
28 print "start_from_filescan",kwargs
30 Scanner(mimetypes="image/mvi",
33 ScanPath(path = "", with_subdirs = False),
35 name = "Logo Manager",
36 description = "manage logos to display at boottime",
37 openfnc = filescan_open,
41 def main(session,**kwargs):
42 if os_path.isdir(config.plugins.logomanager.path.value) is not True:
43 session.open(LogoManagerConfigScreen)
45 session.open(LogoManagerScreen)
47 def Plugins(path,**kwargs):
53 description="manage logos to display at boottime",
54 where = PluginDescriptor.WHERE_PLUGINMENU,
59 PluginDescriptor(name="Logo Manager", where = PluginDescriptor.WHERE_FILESCAN, fnc = start_from_filescan)
61 ###############################################################################
62 class LogoManagerScreen(Screen):
64 <screen flags="wfNoBorder" position="60,450" size="600,29" title="Logo Manager" >
65 <widget name="filelist" position="0,0" size="600,30" />
69 ("bootlogo","/boot/bootlogo.mvi")
70 ,("wait","/boot/bootlogo_wait.mvi")
71 ,("backdrop","/boot/backdrop.mvi")
72 ,("radio","/usr/share/enigma2/radio.mvi")
75 def __init__(self, session, file = None):
76 self.session = session
77 self.skin = LogoManagerScreen.skin
78 Screen.__init__(self, session)
79 self["filelist"] = MenuList([])
80 self["filelist"].onSelectionChanged.append(self.showSelected)
81 self["actions"] = ActionMap(["WizardActions", "DirectionActions","MenuActions","ShortcutActions","GlobalActions"],
83 "ok": self.showSelected,
85 "menu": self.openMenu,
88 ## stop current service to free the videodevice
89 self.current_service = self.session.nav.getCurrentlyPlayingServiceReference()
90 self.session.nav.stopService()
94 self.makeBootWritable()
96 self.setlist_to_avaiable()
97 self.onShown.append(self.showSelected)
98 elif os_path.isfile(file):
99 e = lambda: self.reloadPictures([file])
100 self.onShown.append(e)
101 d = lambda: self.showMVI(file)
102 self.onShown.append(d)
104 def check_backup(self):
105 """ if a copy of the original file is not found in the plugindir, backup them """
107 for target in self.targets:
108 file = target[1].split("/")[-1]
109 if os_path.isfile(plugin_path+file) is not True:
110 print "backing up original ",target[0]," from ",file
111 os_system("cp '%s' '%s'" %(target[1],plugin_path+"/"+file))
113 def restoreOriginal(self):
114 """ restoring original mvis from the backuped mvi in the plugindir"""
116 for target in self.targets:
117 file = target[1].split("/")[-1]
118 if os_path.isfile(plugin_path+"/"+file) is True:
119 print "restoring original ",target[0]," from ",plugin_path+"/"+file,"to",target[1]
120 os_system("cp '%s' '%s'" %(plugin_path+"/"+file,target[1]))
124 self.makeBootReadonly()
125 self.session.nav.playService(self.current_service)
128 def showSelected(self):
129 """ show the currently selected MVI of the list """
130 sel = self["filelist"].getCurrent()
135 """ opens up the Main Menu """
137 menu.append(("install selected Logo as ...",self.action_install))
138 menu.append(("show active Logos",self.setlist_to_current))
139 menu.append(("show available Logos",self.setlist_to_avaiable))
140 menu.append(("reset all Logos to default",self.restoreOriginal))
141 menu.append(("open configuration",self.openConfig))
142 self.session.openWithCallback(self.selectedMenu,ChoiceBox,_("please select a option"),menu)
144 def openConfig(self):
145 self.session.open(LogoManagerConfigScreen)
147 def selectedMenu(self,choice):
148 if choice is not None:
151 def setlist_to_current(self):
152 """ fills the list with the target MVIs"""
155 for i in self.targets:
156 filelist.append(i[1])
157 self.reloadPictures(filelist)
160 def setlist_to_avaiable(self):
161 """ fills the list with all found new MVIs"""
163 for i in os_listdir(config.plugins.logomanager.path.value):
164 if i.endswith(".mvi"):
165 filelist.append(config.plugins.logomanager.path.value+i)
167 self.reloadPictures(filelist)
170 def action_install(self):
171 """ choicebox, to select target to install an mvi to"""
172 self.session.openWithCallback(self.selectedTarget,ChoiceBox,_("select Target for logo"),self.targets)
174 def selectedTarget(self,choice):
175 if choice is not None:
176 self.installMVI(choice,self["filelist"].getCurrent()[1])
178 def reloadPictures(self,filelist):
179 """ build the menulist with givven files """
182 list.append((i.split("/")[-1],i))
183 self["filelist"].l.setList(list)
186 def showMVI(self,mvifile):
188 print "playing MVI",mvifile
189 os_system("/usr/bin/showiframe '%s'" % mvifile)
191 def installMVI(self,target,sourcefile):
192 """ installs a mvi by overwriting the target with a source mvi """
193 print "installing %s as %s on %s" %(sourcefile,target[0],target[1])
194 if os_path.isfile(target[1]):
196 os_system("cp '%s' '%s'"%(sourcefile,target[1]))
198 def makeBootWritable(self):
199 """ because /boot isnt writeable by default, we will change that here """
200 os_system("mount -o rw,remount /boot")
202 def makeBootReadonly(self):
203 """ make /boot writeprotected back again """
204 os_system("mount -o r,remount /boot")
206 class LogoManagerConfigScreen(ConfigListScreen,Screen):
208 <screen position="100,100" size="550,400" title="LogoManager Setup" >
209 <widget name="config" position="0,0" size="550,360" scrollbarMode="showOnDemand" />
210 <widget name="buttonred" position="10,360" size="100,40" backgroundColor="red" valign="center" halign="center" zPosition="2" foregroundColor="white" font="Regular;18"/>
211 <widget name="buttongreen" position="120,360" size="100,40" backgroundColor="green" valign="center" halign="center" zPosition="2" foregroundColor="white" font="Regular;18"/>
213 def __init__(self, session, args = 0):
214 self.session = session
215 Screen.__init__(self, session)
217 self.list.append(getConfigListEntry(_("Directory to scan for Logos"), config.plugins.logomanager.path))
218 ConfigListScreen.__init__(self, self.list)
219 self["buttonred"] = Label(_("cancel"))
220 self["buttongreen"] = Label(_("ok"))
221 self["setupActions"] = ActionMap(["SetupActions"],
226 "cancel": self.cancel,
232 for x in self["config"].list:
238 for x in self["config"].list: