- "Change name" -> "change name",
[vuplus_dvbapp-plugin] / movieretitle / src / plugin.py
index e835c2f..52fa34a 100644 (file)
@@ -1,58 +1,47 @@
+# for localized messages
+from . import _
+
 from Plugins.Plugin import PluginDescriptor
 from Screens.Screen import Screen
 from Screens.MessageBox import MessageBox
 from Screens.LocationBox import MovieLocationBox
 import Screens.Standby
-from Components.config import *
-from Components.ActionMap import ActionMap, NumberActionMap
-from Components.ConfigList import ConfigList, ConfigListScreen
-from Components.Button import Button
-from Components.Label import Label
-from Components.Pixmap import Pixmap
-from enigma import eTimer, eServiceReference, eServiceCenter, iServiceInformation, eConsoleAppContainer
-import os
+from Components.config import config, ConfigText, ConfigSelection, getConfigListEntry
+from Components.ActionMap import ActionMap
+from Components.ConfigList import ConfigListScreen
+from Components.Sources.StaticText import StaticText
+from enigma import eTimer, eServiceCenter, iServiceInformation, eConsoleAppContainer
+from os import path as os_path, rename as os_rename, unlink as os_unlink
 
 def main(session, service, **kwargs):
        session.open(MovieRetitle, service, session.current_dialog, **kwargs)
 
 def Plugins(**kwargs):
-       return PluginDescriptor(name="MovieRetitle", description=_("Change name..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc=main)
+       return PluginDescriptor(name="MovieRetitle", description=_("change name..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc=main)
 
 
 class MovieRetitle(Screen, ConfigListScreen):
-       skin = """
-       <screen name="TitleDescrInput" position="100,150" size="500,200" title="Name and Description Input">
-               <widget name="config" position="10,10" size="480,120" />
-               <widget name="ok" position="70,140" size="140,40" pixmap="skin_default/buttons/green.png" alphatest="on" />
-               <widget name="oktext" position="70,140" size="140,40" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" />
-               <widget name="cancel" position="290,140" size="140,40" pixmap="skin_default/buttons/red.png" alphatest="on" />
-               <widget name="canceltext" position="290,140" size="140,40" valign="center" halign="center" zPosition="2" font="Regular;20" transparent="1" />
-       </screen>"""
-
        def __init__(self, session, service, parent, args = 0):
-               Screen.__init__(self, session)
-               self.session = session
-               self.service = service
-               self.parentscreen = parent
-               Screen.__init__(self, session)
+               Screen.__init__(self, session, parent = parent)
+               self.skinName = [ "MovieRetitle", "Setup" ]
+
                serviceHandler = eServiceCenter.getInstance()
-               info = serviceHandler.info(self.service)
-               self.path = self.service.getPath()
-               if self.path.endswith(".ts") is True:
-                       self.path = self.path[:-3]
-               self.dir = self.dirName(self.path)
-               self.file = self.baseName(self.path)
-               self.name = info.getName(self.service)
+               info = serviceHandler.info(service)
+               path = service.getPath()
+               if path.endswith(".ts") is True:
+                       path = path[:-3]
+               self.path = path
+               self.dir = '/'.join(path.split('/')[:-1]) + '/'
+               self.file = self.baseName(path)
+               self.name = info.getName(service)
                if self.file == self.baseName(self.name):
                        self.title = ""
                else:
                        self.title = self.name
-               self.descr = info.getInfoString(self.service, iServiceInformation.sDescription)
+               self.descr = info.getInfoString(service, iServiceInformation.sDescription)
 
-               self["oktext"] = Label(_("OK"))
-               self["canceltext"] = Label(_("Cancel"))
-               self["ok"] = Pixmap()
-               self["cancel"] = Pixmap()
+               self["key_green"] = StaticText(_("OK"))
+               self["key_red"] = StaticText(_("Cancel"))
 
                self.input_file = ConfigText(default = self.file, fixed_size = False, visible_width = 42)
                self.input_title = ConfigText(default = self.title, fixed_size = False, visible_width = 42)
@@ -62,34 +51,38 @@ class MovieRetitle(Screen, ConfigListScreen):
                        tmp.append(self.dir)
                self.input_dir = ConfigSelection(choices = tmp, default = self.dir)
 
-               self["actions"] = NumberActionMap(["SetupActions"],
+               self["actions"] = ActionMap(["SetupActions"],
                {
                        "ok": self.keySelectOrGo,
                        "save": self.keyGo,
                        "cancel": self.keyCancel,
                }, -2)
 
-               self.list = []
-               ConfigListScreen.__init__(self, self.list)
-               self.createSetup(self["config"])
+               self.locationEl = getConfigListEntry(_("Location"), self.input_dir)
+               l = [
+                       getConfigListEntry(_("Filename"), self.input_file),
+                       getConfigListEntry(_("Title"), self.input_title),
+                       getConfigListEntry(_("Description"), self.input_descr),
+                       self.locationEl
+               ]
 
-       def createSetup(self, configlist):
-               self.list = []
-               self.list.append(getConfigListEntry(_("Filename"), self.input_file))
-               self.list.append(getConfigListEntry(_("Title"), self.input_title))
-               self.list.append(getConfigListEntry(_("Description"), self.input_descr))
-               self.list.append(getConfigListEntry(_("Location"), self.input_dir))
-               configlist.list = self.list
-               configlist.l.setList(self.list)
+               ConfigListScreen.__init__(self, l)
+
+               self.onLayoutFinish.append(self.setCustomTitle)
+               
+       def setCustomTitle(self):
+               self.setTitle(_("Name and Description Input"))
 
        def pathSelected(self, res):
                if res is not None:
-                       if config.movielist.videodirs.value != self.input_dir.choices:
-                               self.input_dir.setChoices(config.movielist.videodirs.value, default=res)
+                       videodirs = config.movielist.videodirs.value
+                       if videodirs != self.input_dir.choices:
+                               self.input_dir.setChoices(videodirs, default=res)
                        self.input_dir.value = res
 
        def keySelectOrGo(self):
-               if self["config"].getCurrent() == self.list[3]:
+               cur = self["config"].getCurrent()
+               if cur is self.locationEl:
                        self.session.openWithCallback(
                                self.pathSelected,
                                MovieLocationBox,
@@ -111,7 +104,7 @@ class MovieRetitle(Screen, ConfigListScreen):
                self.close()
 
        def setTitleDescr(self, file, title, descr):
-               if os.path.exists(file + ".ts.meta"):
+               if os_path.exists(file + ".ts.meta"):
                        metafile = open(file + ".ts.meta", "r")
                        sid = metafile.readline()
                        oldtitle = metafile.readline().rstrip()
@@ -127,14 +120,14 @@ class MovieRetitle(Screen, ConfigListScreen):
                        metafile.close()
 
        def maybeMoveMovieFiles(self, fr, to):
-               if os.path.exists(to+".ts"):
+               if os_path.exists(to+".ts"):
                        self.inter_fr = fr
                        self.inter_to = to
                        self.session.openWithCallback(self.confirmedReplace, MessageBox, _("Target file %s.ts already exist.\nDo you want to replace it?") % (to), MessageBox.TYPE_YESNO)
-               elif os.path.isdir(os.path.dirname(to)):
+               elif os_path.isdir(os_path.dirname(to)):
                        self.moveMovieFiles(fr, to)
                else:
-                       self.session.openWithCallback(self.exitDialog, MessageBox, _("The target directory is not found. The file is not renamed."), MessageBox.TYPE_ERROR) 
+                       self.session.openWithCallback(self.exitDialog, MessageBox, _("The target directory is not found. The file is not renamed."), MessageBox.TYPE_ERROR)
 
        def confirmedReplace(self, answer):
                if answer == True:
@@ -142,15 +135,15 @@ class MovieRetitle(Screen, ConfigListScreen):
 
        def moveMovieFiles(self, fr, to):
                try:
-                       os.rename(fr + ".ts", to + ".ts")
+                       os_rename(fr + ".ts", to + ".ts")
                except OSError:
                        print "Moving in background"
                        global_background_mover.enqueue(self.exitDialog, self.session, fr, to)
                else:
                        print "Moving in foreground"
-                       for suff in [".ts.meta", ".ts.cuts", ".ts.ap", ".eit"]:
-                               if os.path.exists(fr + suff):
-                                       os.rename(fr + suff, to + suff)
+                       for suff in (".ts.meta", ".ts.cuts", ".ts.ap", ".eit"):
+                               if os_path.exists(fr + suff):
+                                       os_rename(fr + suff, to + suff)
                        self.exitDialog()
 
        def exitDialog(self, dummy=None):
@@ -158,8 +151,9 @@ class MovieRetitle(Screen, ConfigListScreen):
                # This will try to get back to an updated movie list.
                # A proper way to do this should be provided in enigma2.
                try:
-                       self.parentscreen.csel.reloadList()
-                       self.parentscreen.close()
+                       parent = self.parent
+                       parent.csel.reloadList()
+                       parent.close()
                except AttributeError:
                        pass
 
@@ -170,9 +164,6 @@ class MovieRetitle(Screen, ConfigListScreen):
                else:
                        return name
 
-       def dirName(self, str):
-               return '/'.join(str.split('/')[:-1]) + '/'
-
        def rejoinName(self, dir, name):
                name = name.strip()
                if name.endswith(".ts") is True:
@@ -244,7 +235,7 @@ class MovieRetitleBackgroundMover:
 
        def enqueue(self, cb, session, fr, to):
                self.currid += 1
-               mess = _("The movie is moved in the background from %s to %s.") % (os.path.dirname(fr), os.path.dirname(to))
+               mess = _("The movie is moved in the background from %s to %s.") % (os_path.dirname(fr), os_path.dirname(to))
                self.message(session, self.currid, cb, mess)
                self.queue.append((session, self.currid, fr, to))
                if not self.running:
@@ -267,7 +258,7 @@ class MovieRetitleBackgroundMover:
 
        def moveMovieFilesBackground(self, ele):
                self.ele = ele
-               self.sufflst = [".ts.meta", ".ts.cuts", ".ts.ap", ".eit", ".ts"]
+               self.sufflst = (".ts.meta", ".ts.cuts", ".ts.ap", ".eit", ".ts")
                self.sufflst2 = self.sufflst
                self.moveNextSuffBG(0)
 
@@ -277,22 +268,22 @@ class MovieRetitleBackgroundMover:
                        to = self.ele[3] + self.sufflst[0]
                        self.sufflst = self.sufflst[1:]
                        print "Moving %s to %s" % (fr, to)
-                       if os.path.exists(fr):
-                               self.container.execute("/bin/cp", ["/bin/cp", fr, to])
+                       if os_path.exists(fr):
+                               self.container.execute("/bin/cp", "/bin/cp", fr, to)
                        else:
                                self.moveNextSuffBG(0)
                elif retval:
                        for suff in self.sufflst2:
-                               if os.path.exists(self.ele[3] + suff) and os.path.exists(self.ele[2] + suff):
-                                       os.unlink(self.ele[3] + suff)
-                       mess = "Failed to move the movie %s to %s in the background" % (self.ele[2], self.ele[3])
+                               if os_path.exists(self.ele[3] + suff) and os_path.exists(self.ele[2] + suff):
+                                       os_unlink(self.ele[3] + suff)
+                       mess = _("Failed to move the movie %s to %s in the background") % (self.ele[2], self.ele[3])
                        self.message(self.ele[0], self.ele[1], None, mess)
                        self.runDone(1)
                else:
                        for suff in self.sufflst2:
-                               if os.path.exists(self.ele[2] + suff) and os.path.exists(self.ele[3] + suff):
-                                       os.unlink(self.ele[2] + suff)
-                       mess = "Successfully moved the movie %s" % (self.ele[2])
+                               if os_path.exists(self.ele[2] + suff) and os_path.exists(self.ele[3] + suff):
+                                       os_unlink(self.ele[2] + suff)
+                       mess = _("Successfully moved the movie %s") % (self.ele[2])
                        self.message(self.ele[0], self.ele[1], None, mess)
                        self.runDone(0)