0d1489aa800b01d1e29362a2b2679a30676be479
[enigma2.git] / lib / python / Components / config.py
1 #  temp stuff :)
2 class configBoolean:
3         def __init__(self, parent):
4                 self.parent = parent
5                 
6         def checkValues(self):
7                 if self.parent.value < 0:
8                         self.parent.value = 0   
9
10                 if(self.parent.value >= (len(self.parent.vals) - 1)):
11                         self.parent.value = len(self.parent.vals) - 1
12
13         def cancel(self):
14                 print "cancel"
15
16         def save(self):
17                 print "save"
18
19         def handleKey(self, key):
20                 if key == 1:
21                         self.parent.value = self.parent.value - 1
22                 if key == 2:
23                         self.parent.value = self.parent.value + 1
24                 
25                 self.checkValues()                      
26
27                 self.parent.change()    
28
29         def __call__(self):                     #needed by configlist
30                 self.checkValues()                      
31         
32                 return ("text", self.parent.vals[self.parent.value])
33
34 class configValue:
35         def __init__(self, obj):
36                 self.obj = obj
37                 
38         def __str__(self):
39                 return self.obj
40
41 def configEntry(obj):
42         # das hier ist ein zugriff auf die registry...
43         if obj == "HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/SDTV/FLASHES/GREEN":
44                 return ("SDTV green flashes", configBoolean(obj))
45         elif obj == "HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/HDTV/FLASHES/GREEN":
46                 return ("HDTV reen flashes", configBoolean(obj))
47         else:
48                 return ("invalid", "")
49
50 class Config:
51         def __init__(self):
52                 pass
53                 
54 config = Config();
55
56 class ConfigSlider:
57         def __init__(self, parent):
58                 self.parent = parent
59
60         def cancel(self):
61                 print "slider - cancel"
62
63         def save(self):
64                 print "slider - save"
65
66         def checkValues(self):
67                 if self.parent.value < 0:
68                         self.parent.value = 0   
69
70                 if self.parent.value > 10:
71                         self.parent.value = 10  
72
73         def handleKey(self, key):
74                 if key == 1:
75                         self.parent.value = self.parent.value - 1
76                 if key == 2:
77                         self.parent.value = self.parent.value + 1
78                                         
79                 self.checkValues()      
80                 self.parent.change()    
81
82         def __call__(self):                     #needed by configlist
83                 self.checkValues()      
84                 return ("slider", self.parent.value * 10)
85
86 class ConfigSubsection:
87         def __init__(self):
88                 pass
89
90 class configElement:
91         def __init__(self, configPath, control, defaultValue, vals):
92                 self.configPath = configPath
93 #               self.value = 0  #read from registry else use default
94                 self.value = defaultValue       #read from registry else use default
95                 self.defaultValue = defaultValue
96                 self.controlType = control
97                 self.vals = vals
98                 self.notifierList = [ ]
99         def addNotifier(self, notifier):
100                 self.notifierList.append(notifier);
101                 notifier(self);
102         def change(self):
103                 for notifier in self.notifierList:
104                         notifier(self)
105         def reload(self):
106                 self.value = self.defaultValue  #HACK :-)