7 self.file = open("config")
11 def getKey(self, key, dataType):
12 self.openFile() #good idea? (open every time we need it?) else we have to seek
14 line = self.file.readline()
17 if line.startswith(key):
21 return dataType(line[x + 1:])
27 def __init__(self, parent):
30 def checkValues(self):
31 if self.parent.value < 0:
34 if(self.parent.value >= (len(self.parent.vals) - 1)):
35 self.parent.value = len(self.parent.vals) - 1
43 def handleKey(self, key):
45 self.parent.value = self.parent.value - 1
47 self.parent.value = self.parent.value + 1
53 def __call__(self): #needed by configlist
55 return ("text", self.parent.vals[self.parent.value])
58 def __init__(self, obj):
68 def saveLine(self, file, element):
69 #FIXME can handle INTs only
70 line = element.configPath + "=" + str(element.value) + "\n"
74 fileHandle = open("config", "w")
76 for groupElement in self.__dict__.items():
77 for element in groupElement[1].__dict__.items():
78 self.saveLine(fileHandle, element[1])
86 configfile = configFile()
89 def __init__(self, parent):
98 def checkValues(self):
99 if self.parent.value < 0:
100 self.parent.value = 0
102 if self.parent.value > 10:
103 self.parent.value = 10
105 def handleKey(self, key):
107 self.parent.value = self.parent.value - 1
109 self.parent.value = self.parent.value + 1
114 def __call__(self): #needed by configlist
116 return ("slider", self.parent.value * 10)
118 class ConfigSubsection:
123 def dataType(self, control):
124 if control == ConfigSlider:
126 elif control == configBoolean:
133 value = configfile.getKey(self.configPath, self.dataType(self.controlType))
138 print "value not found - using default"
139 self.value = self.defaultValue
144 def __init__(self, configPath, control, defaultValue, vals):
145 self.configPath = configPath
146 self.defaultValue = defaultValue
147 self.controlType = control
149 self.notifierList = [ ]
151 def addNotifier(self, notifier):
152 self.notifierList.append(notifier);
155 for notifier in self.notifierList: