namezap: initial checkin
[enigma2-plugins.git] / namezap / src / plugin.py
1 # Plugin definition
2 from Plugins.Plugin import PluginDescriptor
3
4 from enigma import eServiceCenter, eServiceReference
5 from Components.Label import Label
6 from Screens import InfoBarGenerics
7 from Screens.InfoBar import InfoBar
8 from Components.config import config
9
10 NumberZap = InfoBarGenerics.NumberZap
11 class NameZap(NumberZap):
12         skin = """<screen name="NameZap" position="center,center" size="300,60" title="Channel">
13                         <widget name="channel" position="5,15" size="100,25" font="Regular;23" />
14                         <widget name="name" position="105,15" size="190,25" halign="right" font="Regular;23" />
15                 </screen>"""
16
17         def __init__(self, *args, **kwargs):
18                 NumberZap.__init__(self, *args, **kwargs)
19                 self["name"] = Label("")
20                 self.serviceHandler = eServiceCenter.getInstance()
21                 self.updateServiceName(int(self.field))
22
23         def keyNumberGlobal(self, number):
24                 NumberZap.keyNumberGlobal(self, number)
25                 self.updateServiceName(int(self.field))
26
27         def searchNumberHelper(self, serviceHandler, num, bouquet):
28                 servicelist = self.serviceHandler.list(bouquet)
29                 if not servicelist is None:
30                         while num:
31                                 serviceIterator = servicelist.getNext()
32                                 if not serviceIterator.valid(): #check end of list
33                                         break
34                                 playable = not (serviceIterator.flags & (eServiceReference.isMarker|eServiceReference.isDirectory))
35                                 if playable:
36                                         num -= 1;
37                         if not num: #found service with searched number ?
38                                 return serviceIterator, 0
39                 return None, num
40
41         def updateServiceName(self, number):
42                 bouquet = InfoBar.instance.servicelist.bouquet_root
43                 service = None
44                 serviceHandler = self.serviceHandler
45                 if not config.usage.multibouquet.value:
46                         service, number = self.searchNumberHelper(serviceHandler, number, bouquet)
47                 else:
48                         bouquetlist = serviceHandler.list(bouquet)
49                         if not bouquetlist is None:
50                                 while number:
51                                         bouquet = bouquetlist.getNext()
52                                         if not bouquet.valid(): #check end of list
53                                                 break
54                                         if bouquet.flags & eServiceReference.isDirectory:
55                                                 service, number = self.searchNumberHelper(serviceHandler, number, bouquet)
56                 if service is not None:
57                         info = serviceHandler.info(service)
58                         self["name"].setText(info.getName(service).replace('\xc2\x86', '').replace('\xc2\x87', ''))
59                 else:
60                         self["name"].setText("??? (%s)" % (self.field,))
61
62 def autostart(reason, *args, **kwargs):
63         if reason == 0:
64                 InfoBarGenerics.NumberZap = NameZap
65
66 # TODO: allow to disable this :-)
67
68 def Plugins(**kwargs):
69         return [
70                 PluginDescriptor(
71                         where=PluginDescriptor.WHERE_AUTOSTART,
72                         fnc=autostart,
73                         needsRestart=False,
74                 ),
75         ]