added config-functions now you can save your setup
[enigma2.git] / lib / python / Screens / Satconfig.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ConfigList import ConfigList
4 from Components.config import *
5 from Components.MenuList import MenuList
6 from Components.NimManager import nimmanager
7
8 class NimSetup(Screen):
9         def createSimpleSetup(self, nim, list, mode):
10
11                 b = config.Nims[nim.slotid].diseqcA
12                 item = b.controlType(b)
13                 if mode == 0:                   #single Sat
14                         list.append( ("Satellite", item) )
15                 else:                                                   # > 1 Sats
16                         list.append( ("Port A", item) )
17                 
18                 if mode >= 1:                   # > 1 Sats
19                         b = config.Nims[nim.slotid].diseqcB
20                         item = b.controlType(b)
21                         list.append( ("Port B", item) )
22                         if mode >= 3:           # > 2 Sats
23                                 b = config.Nims[nim.slotid].diseqcC
24                                 item = b.controlType(b)
25                                 list.append( ("Port C", item) )
26
27                                 b = config.Nims[nim.slotid].diseqcD
28                                 item = b.controlType(b)
29                                 list.append( ("Port D", item) )
30                                 
31         def createSetup(self):
32                 self.list = [ ]
33                 
34                 b = config.Nims[self.nim.slotid].configMode
35                 item = b.controlType(b)
36                 self.list.append( ("Configmode", item) )
37                 
38                 if b.value == 0:                        #simple setup
39                         b = config.Nims[self.nim.slotid].diseqcMode
40                         item = b.controlType(b)
41                         self.list.append( ("Diseqcmode", item) )
42                 
43                         self.createSimpleSetup(self.nim, self.list, b.value)
44                 else:   
45                         print "FIXME: implement advanced mode"
46
47                 self["config"].list = self.list
48                 self["config"].l.setList(self.list)
49                 
50         def newConfig(self):    
51                 if self["config"].getCurrent()[0] == "Diseqcmode":
52                         self.createSetup()
53                 if self["config"].getCurrent()[0] == "Configmode":
54                         self.createSetup()
55                 
56         def keyLeft(self):
57                 self["config"].handleKey(config.key["prevElement"])
58                 self.newConfig()
59
60         def keyRight(self):
61                 self["config"].handleKey(config.key["nextElement"])
62                 self.newConfig()
63
64         def keySave(self):
65                 for x in self["config"].list:
66                         x[1].save()
67                 self.close()
68
69         def keyCancel(self):
70                 for x in self["config"].list:
71                         x[1].cancel()
72                 self.close()
73
74         def __init__(self, session, nim):
75                 Screen.__init__(self, session)
76                 self.nim = nim
77
78                 self["actions"] = ActionMap(["SetupActions"],
79                 {
80                         "ok": self.keySave,
81                         "cancel": self.keyCancel,
82                         "left": self.keyLeft,
83                         "right": self.keyRight
84                 }, -1)
85
86                 self.list = [ ]
87                 self["config"] = ConfigList(self.list)
88                 
89                 self.createSetup()
90
91 class NimSelection(Screen):
92         def __init__(self, session):
93                 Screen.__init__(self, session)
94
95                 self["nimlist"] = MenuList(nimmanager.nimList())
96
97                 self["actions"] = ActionMap(["OkCancelActions"],
98                 {
99                         "ok": self.okbuttonClick ,
100                         "cancel": self.close
101                 }, -1)
102
103         def okbuttonClick(self):
104                 selection = self["nimlist"].getCurrent()
105                 if selection[1].nimType != -1:  #unknown/empty
106                         self.session.open(NimSetup, selection[1])
107