moviesearch: add proof of concept search plugin to the movie list
[enigma2-plugins.git] / moviesearch / src / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2 from NTIVirtualKeyBoard import NTIVirtualKeyBoard
3 from Tools.BoundFunction import boundFunction
4 from Screens.MessageBox import MessageBox
5
6 def vkCallback(csel, searchString=None):
7         if not csel: return
8         if not searchString:
9                 return csel.reloadList()
10
11         movieList = csel["list"].list
12         newList = []
13         for movie in movieList:
14                 name = movie[1].getName(movie[0])
15                 if searchString.lower() in name.lower(): # force case-insensitive for now
16                         newList.append(movie)
17         csel["list"].list = newList
18         csel["list"].l.setList(newList)
19
20 def main(session, service, **kwargs):
21         try:
22                 csel = session.current_dialog.csel
23         except Exception:
24                 csel = None
25
26         if csel is not None:
27                 session.openWithCallback(
28                                 boundFunction(vkCallback, csel),
29                                 NTIVirtualKeyBoard,
30                                 title=_("Enter text to search for")
31                 )
32         else:
33                 self.session.open(
34                         MessageBox,
35                         _("Improperly launched plugin.\nAborting!"),
36                         type = MessageBox.TYPE_ERROR
37                 )
38
39
40 def Plugins(**kwargs):
41         return PluginDescriptor(name="MovieSearch", description=_("search..."), where=PluginDescriptor.WHERE_MOVIELIST, fnc=main)
42