- split out meta parser
[enigma2.git] / lib / python / Screens / ChannelSelection.py
1 from Screen import Screen
2 from Components.Button import Button
3 from Components.ServiceList import ServiceList
4 from Components.ActionMap import ActionMap
5
6 from enigma import eServiceReference
7
8 from Screens.Menu import FixedMenu
9
10 import xml.dom.minidom
11
12 class ChannelContextMenu(FixedMenu):
13         def __init__(self, session, csel):
14                 self.csel = csel
15                 
16                 menu = [("back", self.close)]
17                 
18                 if csel.movemode:
19                         menu.append(("disable move mode", self.moveMode))
20                 else:
21                         menu.append(("enable move mode", self.moveMode))
22
23                 if csel.bouquet_mark_edit:
24                         menu.append(("end bouquet edit", self.bouquetMarkEnd))
25                         menu.append(("abort bouquet edit", self.bouquetMarkAbort))
26                 else:
27                         menu.append(("edit bouquet...", self.bouquetMarkStart))
28                 
29                 FixedMenu.__init__(self, session, "Channel Selection", menu)
30                 self.skinName = "Menu"
31
32         def moveMode(self):
33                 self.csel.setMoveMode(self.csel.movemode)
34                 self.close()
35         
36         def bouquetMarkStart(self):
37                 self.csel.startMarkedEdit()
38                 self.close()
39         
40         def bouquetMarkEnd(self):
41                 self.csel.endMarkedEdit(abort=False)
42                 self.close()
43
44         def bouquetMarkAbort(self):
45                 self.csel.endMarkedEdit(abort=True)
46                 self.close()
47  
48 class ChannelSelection(Screen):
49         def __init__(self, session):
50                 Screen.__init__(self, session)
51                 
52                 self.movemode = False
53                 self.bouquet_mark_edit = False
54                 
55                 ## FIXME
56                 self.__marked = [ ]
57                 
58                 self["key_red"] = Button("red")
59                 self["key_green"] = Button("green")
60                 self["key_yellow"] = Button("yellow")
61                 self["key_blue"] = Button("blue")
62                 
63                 self["list"] = ServiceList()
64                 self["list"].setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(type == 1)"""))
65                 
66                 #self["okbutton"] = Button("ok", [self.channelSelected])
67                 
68                 class ChannelActionMap(ActionMap):
69                         def action(self, contexts, action):
70                                 if action[:7] == "bouquet":
71                                         print "setting root to " + action[8:]
72                                         self.csel["list"].setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
73                                 else:
74                                         ActionMap.action(self, contexts, action)
75
76                 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions"], 
77                         {
78                                 "cancel": self.close,
79                                 "ok": self.channelSelected,
80                                 "mark": self.doMark,
81                                 "contextMenu": self.doContext
82                         })
83                 self["actions"].csel = self
84
85         #  marked edit mode
86         
87         def startMarkedEdit(self):
88                 self.bouquet_mark_edit = True
89                 self.clearMarks()
90                 
91                 # TODO
92                 marked = self.__marked
93                 
94                 l = self["list"]
95                 for x in marked:
96                         print "mark: " + str(x)
97                         l.addMarked(x)
98                 
99         def endMarkedEdit(self, abort):
100                 self.bouquet_mark_edit = True
101                 new_marked = self["list"].getMarked()
102                 self.__marked = new_marked
103                 self.clearMarks()
104                 self.bouquet_mark_edit = False
105
106         def clearMarks(self):
107                 self["list"].clearMarks()
108         
109         def doMark(self):
110                 if not self.bouquet_mark_edit:
111                         return
112                 
113                 ref = self["list"].getCurrent()
114                 if self["list"].isMarked(ref):
115                         self["list"].removeMarked(ref)
116                 else:
117                         self["list"].addMarked(ref)
118         
119         # ...
120         def channelSelected(self):
121                 self.session.nav.playService(self["list"].getCurrent())
122                 self.close()
123
124         #called from infoBar
125         def zap(self):
126                 self.session.nav.playService(self["list"].getCurrent())
127
128         def moveUp(self):
129                 self["list"].moveUp()
130
131         def moveDown(self):
132                 self["list"].moveDown()
133
134         def doContext(self):
135                 self.session.open(ChannelContextMenu, self)
136
137         def setMoveMode(self, mode):
138                 self.movemode = mode
139