[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / lib / python / Plugins / Extensions / GraphMultiEPG / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2 from GraphMultiEpg import GraphMultiEPG
3 from Screens.ChannelSelection import BouquetSelector, SilentBouquetSelector
4 from enigma import eServiceCenter, eServiceReference
5 from ServiceReference import ServiceReference
6 from Components.config import config
7
8 Session = None
9 Servicelist = None
10
11 bouquetSel = None
12 epg_bouquet = None
13 dlg_stack = [ ]
14
15 def zapToService(service):
16         if not service is None:
17                 if Servicelist.getRoot() != epg_bouquet: #already in correct bouquet?
18                         Servicelist.clearPath()
19                         if Servicelist.bouquet_root != epg_bouquet:
20                                 Servicelist.enterPath(Servicelist.bouquet_root)
21                         Servicelist.enterPath(epg_bouquet)
22                 Servicelist.setCurrentSelection(service) #select the service in Servicelist
23                 Servicelist.zap()
24
25 def getBouquetServices(bouquet):
26         services = [ ]
27         Servicelist = eServiceCenter.getInstance().list(bouquet)
28         if not Servicelist is None:
29                 while True:
30                         service = Servicelist.getNext()
31                         if not service.valid(): #check if end of list
32                                 break
33                         if service.flags & (eServiceReference.isDirectory | eServiceReference.isMarker): #ignore non playable services
34                                 continue
35                         services.append(ServiceReference(service))
36         return services
37
38 def cleanup():
39         global Session
40         Session = None
41         global Servicelist
42         Servicelist = None
43
44 def closed(ret=False):
45         closedScreen = dlg_stack.pop()
46         global bouquetSel
47         if bouquetSel and closedScreen == bouquetSel:
48                 bouquetSel = None
49         dlgs=len(dlg_stack)
50         if ret and dlgs > 0: # recursive close wished
51                 dlg_stack[dlgs-1].close(dlgs > 1)
52         if dlgs <= 0:
53                 cleanup()
54
55 def openBouquetEPG(bouquet):
56         services = getBouquetServices(bouquet)
57         if len(services):
58                 global epg_bouquet
59                 epg_bouquet = bouquet
60                 dlg_stack.append(Session.openWithCallback(closed, GraphMultiEPG, services, zapToService, changeBouquetCB))
61                 return True
62         return False
63
64 def changeBouquetCB(direction, epg):
65         if bouquetSel:
66                 if direction > 0:
67                         bouquetSel.down()
68                 else:
69                         bouquetSel.up()
70                 bouquet = bouquetSel.getCurrent()
71                 services = getBouquetServices(bouquet)
72                 if len(services):
73                         global epg_bouquet
74                         epg_bouquet = bouquet
75                         epg.setServices(services)
76
77 def openAskBouquet(Session, bouquets, cnt):
78         if cnt > 1: # show bouquet list
79                 global bouquetSel
80                 bouquetSel = Session.openWithCallback(closed, BouquetSelector, bouquets, openBouquetEPG, enableWrapAround=True)
81                 dlg_stack.append(bouquetSel)
82         elif cnt == 1:
83                 if not openBouquetEPG(bouquets[0][1]):
84                         cleanup()
85
86 def openSilent(Servicelist, bouquets, cnt):
87         root = Servicelist.getRoot()
88         if cnt > 1: # create bouquet list
89                 global bouquetSel
90                 current = 0
91                 rootstr = root.toCompareString()
92                 for bouquet in bouquets:
93                         if bouquet[1].toCompareString() == rootstr:
94                                 break
95                         current += 1
96                 if current >= cnt:
97                         current = 0
98                 bouquetSel = SilentBouquetSelector(bouquets, True, current)
99         if cnt >= 1: # open current bouquet
100                 if not openBouquetEPG(root):
101                         cleanup()
102
103 def main(session, servicelist, **kwargs):
104         global Session
105         Session = session
106         global Servicelist
107         Servicelist = servicelist
108         bouquets = Servicelist.getBouquetList()
109         if bouquets is None:
110                 cnt = 0
111         else:
112                 cnt = len(bouquets)
113         if config.usage.multiepg_ask_bouquet.value:
114                 openAskBouquet(session, bouquets, cnt)
115         else:
116                 openSilent(servicelist, bouquets, cnt)
117
118 def Plugins(**kwargs):
119         name = _("Graphical Multi EPG")
120         descr = _("A graphical EPG for all services of an specific bouquet")
121         return [PluginDescriptor(name=name, description=descr, where = PluginDescriptor.WHERE_EVENTINFO, needsRestart = False, fnc=main),
122                 PluginDescriptor(name=name, description=descr, where = PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart = False, fnc=main)]