1 from Plugins.Plugin import PluginDescriptor
2 from Components.config import config, ConfigSubList, ConfigSubsection, ConfigInteger, ConfigYesNo, ConfigText, getConfigListEntry
3 from Components.FileList import FileList
4 from Components.ConfigList import ConfigListScreen
5 from Screens.Console import Console
6 from Screens.ChoiceBox import ChoiceBox
7 from Screens.InputBox import InputBox
8 from Screens.MessageBox import MessageBox
9 from Components.Label import Label
10 from Screens.Screen import Screen
11 from Components.ActionMap import ActionMap
12 from Components.Scanner import openFile
13 from os.path import isdir as os_path_isdir
14 from mimetypes import guess_type
16 ##################################
17 pname = _("Filebrowser")
18 pdesc = _("manage local Files")
20 config.plugins.filebrowser = ConfigSubsection()
21 config.plugins.filebrowser.savedirs = ConfigYesNo(default = True)
22 config.plugins.filebrowser.add_mainmenu_entry = ConfigYesNo(default = True)
23 config.plugins.filebrowser.add_extensionmenu_entry = ConfigYesNo(default = True)
24 config.plugins.filebrowser.path_left = ConfigText(default = "/")
25 config.plugins.filebrowser.path_right = ConfigText(default = "/")
28 ##################################
29 class FilebrowserConfigScreen(ConfigListScreen,Screen):
31 <screen position="100,100" size="550,400" title="" >
32 <widget name="config" position="0,0" size="550,360" scrollbarMode="showOnDemand" />
33 <widget name="buttonred" position="10,360" size="100,40" valign="center" halign="center" zPosition="1" transparent="1" foregroundColor="white" font="Regular;18"/>
34 <widget name="buttongreen" position="120,360" size="100,40" valign="center" halign="center" zPosition="1" transparent="1" foregroundColor="white" font="Regular;18"/>
35 <ePixmap name="pred" position="10,360" size="100,40" zPosition="0" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on"/>
36 <ePixmap name="pgreen" position="120,360" size="100,40" zPosition="0" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on"/>
38 def __init__(self, session):
39 self.session = session
40 Screen.__init__(self, session)
42 self.list.append(getConfigListEntry(_("add Plugin to Mainmenu"), config.plugins.filebrowser.add_mainmenu_entry))
43 self.list.append(getConfigListEntry(_("add Plugin to Extensionmenu"), config.plugins.filebrowser.add_extensionmenu_entry))
44 self.list.append(getConfigListEntry(_("save Filesystemposition on exit"), config.plugins.filebrowser.savedirs))
45 self.list.append(getConfigListEntry(_("Filesystemposition list left"), config.plugins.filebrowser.path_left))
46 self.list.append(getConfigListEntry(_("Filesystemposition list right"), config.plugins.filebrowser.path_right))
48 ConfigListScreen.__init__(self, self.list)
49 self["buttonred"] = Label(_("cancel"))
50 self["buttongreen"] = Label(_("ok"))
51 self["setupActions"] = ActionMap(["SetupActions"],
56 "cancel": self.cancel,
59 self.onLayoutFinish.append(self.onLayout)
62 self.setTitle(pname+" "+_("Settings"))
66 for x in self["config"].list:
72 for x in self["config"].list:
77 ##################################
78 class FilebrowserScreen(Screen):
80 <screen position="110,83" size="530,430" title="">
81 <widget name="list_left" position="0,0" size="265,380" scrollbarMode="showOnDemand" />
82 <widget name="list_right" position="265,0" size="265,380" scrollbarMode="showOnDemand" />
84 <widget name="red" position="10,390" size="120,30" valign="center" halign="center" zPosition="1" transparent="1" foregroundColor="white" font="Regular;18"/>
85 <widget name="green" position="140,390" size="120,30" valign="center" halign="center" zPosition="1" transparent="1" foregroundColor="white" font="Regular;18"/>
86 <widget name="yellow" position="270,390" size="120,30" valign="center" halign="center" zPosition="1" transparent="1" foregroundColor="white" font="Regular;18"/>
87 <widget name="blue" position="400,390" size="120,30" valign="center" halign="center" zPosition="1" transparent="1" foregroundColor="white" font="Regular;18"/>
89 <ePixmap name="pred" position="10,390" size="120,30" zPosition="0" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on"/>
90 <ePixmap name="pgreen" position="140,390" size="120,30" zPosition="0" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on"/>
91 <ePixmap name="pyellow" position="270,390" size="120,30" zPosition="0" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on"/>
92 <ePixmap name="pblue" position="400,390" size="120,30" zPosition="0" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on"/>
95 def __init__(self, session,path_left=None):
97 if os_path_isdir(config.plugins.filebrowser.path_left.value) and config.plugins.filebrowser.savedirs.value:
98 path_left = config.plugins.filebrowser.path_left.value
102 if os_path_isdir(config.plugins.filebrowser.path_right.value) and config.plugins.filebrowser.savedirs.value:
103 path_right = config.plugins.filebrowser.path_right.value
107 self.session = session
108 Screen.__init__(self, session)
110 self["list_left"] = FileList(path_left, matchingPattern = "^.*")
111 self["list_right"] = FileList(path_right, matchingPattern = "^.*")
112 self["red"] = Label(_("delete"))
113 self["green"] = Label(_("move"))
114 self["yellow"] = Label(_("copy"))
115 self["blue"] = Label(_("rename"))
118 self["actions"] = ActionMap(["ChannelSelectBaseActions","WizardActions", "DirectionActions","MenuActions","NumberActions","ColorActions"],
123 "nextMarker": self.listRight,
124 "prevMarker": self.listLeft,
128 "right": self.goRight,
130 "green": self.goGreen,
131 "yellow": self.goYellow,
135 self.onLayoutFinish.append(self.listLeft)
138 if self["list_left"].getCurrentDirectory() and config.plugins.filebrowser.savedirs.value:
139 config.plugins.filebrowser.path_left.value = self["list_left"].getCurrentDirectory()
140 config.plugins.filebrowser.path_left.save()
142 if self["list_right"].getCurrentDirectory() and config.plugins.filebrowser.savedirs.value:
143 config.plugins.filebrowser.path_right.value = self["list_right"].getCurrentDirectory()
144 config.plugins.filebrowser.path_right.save()
149 if self.SOURCELIST.canDescent(): # isDir
150 self.SOURCELIST.descent()
151 if self.SOURCELIST.getCurrentDirectory(): #??? when is it none
152 self.setTitle(self.SOURCELIST.getCurrentDirectory())
157 self.session.open(FilebrowserConfigScreen)
160 self.SOURCELIST.pageUp()
163 self.SOURCELIST.pageDown()
169 self.SOURCELIST.down()
171 # copy ###################
173 filename = self.SOURCELIST.getFilename()
174 sourceDir = self.SOURCELIST.getCurrentDirectory()
175 targetDir = self.TARGETLIST.getCurrentDirectory()
176 self.session.openWithCallback(self.doCopy,ChoiceBox, title = _("copy file")+"?\n%s\nfrom\n%s\n%s"%(filename,sourceDir,targetDir),list=[(_("yes"), True ),(_("no"), False )])
178 def doCopy(self,result):
179 if result is not None:
181 filename = self.SOURCELIST.getFilename()
182 sourceDir = self.SOURCELIST.getCurrentDirectory()
183 targetDir = self.TARGETLIST.getCurrentDirectory()
184 self.session.openWithCallback(self.doCopyCB,Console, title = _("copying file ..."), cmdlist = ["cp \""+sourceDir+filename+"\" \""+targetDir+"\""])
189 # delete ###################
191 filename = self.SOURCELIST.getFilename()
192 sourceDir = self.SOURCELIST.getCurrentDirectory()
193 self.session.openWithCallback(self.doDelete,ChoiceBox, title = _("delete file")+"?\n%s\nfrom dir\n%s"%(filename,sourceDir),list=[(_("yes"), True ),(_("no"), False )])
195 def doDelete(self,result):
196 if result is not None:
198 filename = self.SOURCELIST.getFilename()
199 sourceDir = self.SOURCELIST.getCurrentDirectory()
200 self.session.openWithCallback(self.doDeleteCB,Console, title = _("deleting file ..."), cmdlist = ["rm \""+sourceDir+filename+"\""])
202 def doDeleteCB(self):
205 # move ###################
207 filename = self.SOURCELIST.getFilename()
208 sourceDir = self.SOURCELIST.getCurrentDirectory()
209 targetDir = self.TARGETLIST.getCurrentDirectory()
210 self.session.openWithCallback(self.doMove,ChoiceBox, title = _("move file")+"?\n%s\nfrom dir\n%s\nto dir\n%s"%(filename,sourceDir,targetDir),list=[(_("yes"), True ),(_("no"), False )])
212 def doMove(self,result):
213 if result is not None:
215 filename = self.SOURCELIST.getFilename()
216 sourceDir = self.SOURCELIST.getCurrentDirectory()
217 targetDir = self.TARGETLIST.getCurrentDirectory()
218 self.session.openWithCallback(self.doMoveCB,Console, title = _("moving file ..."), cmdlist = ["mv \""+sourceDir+filename+"\" \""+targetDir+"\""])
223 # move ###################
225 filename = self.SOURCELIST.getFilename()
226 sourceDir = self.SOURCELIST.getCurrentDirectory()
227 self.session.openWithCallback(self.doRename,InputBox,text=filename, title = filename, windowTitle=_("rename file"))
229 def doRename(self,newname):
231 filename = self.SOURCELIST.getFilename()
232 sourceDir = self.SOURCELIST.getCurrentDirectory()
233 self.session.openWithCallback(self.doRenameCB,Console, title = _("renaming file ..."), cmdlist = ["mv \""+sourceDir+filename+"\" \""+sourceDir+newname+"\""])
235 def doRenameCB(self):
240 self.SOURCELIST.refresh()
241 self.TARGETLIST.refresh()
244 self["list_left"].selectionEnabled(0)
245 self["list_right"].selectionEnabled(1)
246 self.SOURCELIST = self["list_right"]
247 self.TARGETLIST = self["list_left"]
248 self.setTitle(self.SOURCELIST.getCurrentDirectory())
251 self["list_left"].selectionEnabled(1)
252 self["list_right"].selectionEnabled(0)
253 self.SOURCELIST = self["list_left"]
254 self.TARGETLIST = self["list_right"]
255 self.setTitle(self.SOURCELIST.getCurrentDirectory())
257 def onFileAction(self):
259 x = openFile(self.session,guess_type(self.SOURCELIST.getFilename())[0],self.SOURCELIST.getCurrentDirectory()+self.SOURCELIST.getFilename())
260 print "RESULT OPEN FILE",x
263 # File "/home/tmbinc/opendreambox/1.5/dm8000/experimental/build/tmp/work/enigma2-2.6git20090627-r1/image/usr/lib/enigma2/python/Components/Scanner.py", line 43, in handleFile
264 # TypeError: 'in <string>' requires string as left operand
265 self.session.open(MessageBox,_("no Viewer installed for this mimetype!"), type = MessageBox.TYPE_ERROR, timeout = 5, close_on_any_key = True)
269 ##################################
271 def filescan_open(list, session, **kwargs):
272 path = "/".join(list[0].path.split("/")[:-1])+"/"
273 session.open(FilebrowserScreen,path_left=path)
275 def start_from_filescan(**kwargs):
276 from Components.Scanner import Scanner, ScanPath
278 Scanner(mimetypes=None,
281 ScanPath(path = "", with_subdirs = False),
285 openfnc = filescan_open,
288 def start_from_mainmenu(menuid, **kwargs):
289 #starting from main menu
290 if menuid == "mainmenu":
291 return [(pname, start_from_pluginmenu, "filecommand", 46)]
294 def start_from_pluginmenu(session,**kwargs):
295 session.open(FilebrowserScreen)
297 def Plugins(path,**kwargs):
298 desc_mainmenu = PluginDescriptor(name=pname, description=pdesc, where = PluginDescriptor.WHERE_MENU, fnc = start_from_mainmenu)
299 desc_pluginmenu = PluginDescriptor(name=pname, description=pdesc, where = PluginDescriptor.WHERE_PLUGINMENU, fnc = start_from_pluginmenu)
300 desc_extensionmenu = PluginDescriptor(name=pname, description=pdesc, where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = start_from_pluginmenu)
301 desc_filescan = PluginDescriptor(name=pname, where = PluginDescriptor.WHERE_FILESCAN, fnc = start_from_filescan)
303 list.append(desc_pluginmenu)
304 #buggie list.append(desc_filescan)
305 if config.plugins.filebrowser.add_extensionmenu_entry.value:
306 list.append(desc_extensionmenu)
307 if config.plugins.filebrowser.add_mainmenu_entry.value:
308 list.append(desc_mainmenu)