-class configElement:
-
- def getIndexbyEntry(self, data):
- cnt = 0;
- tcnt = -1; #for defaultval
- for x in self.vals:
- if int(x[1]) == int(data):
- return cnt
- if int(x[1]) == int(self.defaultValue):
- tcnt = cnt
- cnt += 1
- if tcnt != -1:
- return tcnt
- return 0 #prevent bigger then array
-
- def datafromFile(self, control, data):
- if control == ConfigSlider:
- return int(data)
- elif control == configSelection:
- return int(data)
- elif control == configDateTime:
- return int(data)
- elif control == configText:
- return str(data)
- elif control == configSequence:
- list = [ ]
- part = data.split(self.vals[0])
- for x in part:
- list.append(int(x))
- return list
- elif control == configSatlist:
- return self.getIndexbyEntry(data)
- else:
- return ""
-
- def datatoFile(self, control, data):
- if control == ConfigSlider:
- return str(data)
- elif control == configSelection:
- return str(data)
- elif control == configDateTime:
- return str(data)
- elif control == configText:
- return str(data.strip())
-
- elif control == configSequence:
- print data
- try:
- value = ((len(data) * ("%d" + self.vals[0]))[0:-1]) % tuple(data)
- except:
- value = str(data)
-# just in case you don't understand the above, here an equivalent:
-# value = ""
-# for i in data:
-# if value !="":
-# value += self.vals[0]
-# value += str(i)
- return value
- elif control == configSatlist:
- return str(self.vals[self.value][1]);
- else:
- return ""
-
- def loadData(self):
- #print "load:" + self.configPath
- try:
- value = self.datafromFile(self.controlType, configfile.getKey(self.configPath))
- except:
- value = ""
+ def getMulti(self, selected):
+ self.checkValues()
+ return ("slider", self.value, self.max)
+
+ def fromstring(self, value):
+ return int(value)
+
+# a satlist. in fact, it's a ConfigSelection.
+class ConfigSatlist(ConfigSelection):
+ def __init__(self, list, default = None):
+ if default is not None:
+ default = str(default)
+ ConfigSelection.__init__(self, choices = [(str(orbpos), desc) for (orbpos, desc, flags) in list], default = default)
+
+ def getOrbitalPosition(self):
+ if self.value == "":
+ return None
+ return int(self.value)
+
+ orbital_position = property(getOrbitalPosition)
+
+class ConfigSet(ConfigElement):
+ def __init__(self, choices, default = []):
+ ConfigElement.__init__(self)
+ self.choices = []
+ self.description = {}
+ if isinstance(choices, list):
+ choices.sort()
+ for x in choices:
+ if isinstance(x, tuple):
+ self.choices.append(x[0])
+ self.description[x[0]] = str(x[1])
+ else:
+ self.choices.append(x)
+ self.description[x] = str(x)
+ else:
+ assert False, "ConfigSet choices must be a list!"
+ if len(self.choices) == 0:
+ self.choices = [""]
+ self.description[""] = ""
+ if default is None:
+ default = []
+ self.pos = -1
+ default.sort()
+ self.default = default
+ self.value = default+[]
+
+ def toggleChoice(self, choice):
+ if choice in self.value:
+ self.value.remove(choice)
+ else:
+ self.value.append(choice)
+ self.value.sort()
+
+ def handleKey(self, key):
+ if key in KEY_NUMBERS + [KEY_DELETE, KEY_BACKSPACE]:
+ if self.pos != -1:
+ self.toggleChoice(self.choices[self.pos])
+ elif key == KEY_LEFT:
+ self.pos -= 1
+ if self.pos < -1:
+ self.pos = len(self.choices)-1
+ elif key == KEY_RIGHT:
+ self.pos += 1
+ if self.pos >= len(self.choices):
+ self.pos = -1
+ elif key in [KEY_HOME, KEY_END]:
+ self.pos = -1
+
+ def genString(self, lst):
+ res = ""
+ for x in lst:
+ res += self.description[x]+" "
+ return res
+
+ def getText(self):
+ return self.genString(self.value)
+
+ def getMulti(self, selected):
+ if not selected or self.pos == -1:
+ return ("text", self.genString(self.value))
+ else:
+ tmp = self.value+[]
+ ch = self.choices[self.pos]
+ mem = ch in self.value
+ if not mem:
+ tmp.append(ch)
+ tmp.sort()
+ ind = tmp.index(ch)
+ val1 = self.genString(tmp[:ind])
+ val2 = " "+self.genString(tmp[ind+1:])
+ if mem:
+ chstr = " "+self.description[ch]+" "
+ else:
+ chstr = "("+self.description[ch]+")"
+ return ("mtext", val1+chstr+val2, range(len(val1),len(val1)+len(chstr)))
+
+ def onDeselect(self, session):
+ self.pos = -1
+ self.changed()
+
+ def tostring(self, value):
+ return str(value)
+
+ def fromstring(self, val):
+ return eval(val)
+
+class ConfigLocations(ConfigElement):
+ def __init__(self, default = [], visible_width = False):
+ ConfigElement.__init__(self)
+ self.visible_width = visible_width
+ self.pos = -1
+ self.default = default
+ self.locations = []
+ self.mountpoints = []
+ harddiskmanager.on_partition_list_change.append(self.mountpointsChanged)
+
+ def setValue(self, value):
+ loc = [x[0] for x in self.locations if x[3]]
+ add = [x for x in value if not x in loc]
+ diff = add + [x for x in loc if not x in value]
+ self.locations = [x for x in self.locations if not x[0] in diff] + [[x, self.getMountpoint(x), True, True] for x in add]
+ self.locations.sort(key = lambda x: x[0])
+ self.changed()
+
+ def getValue(self):
+ self.checkChangedMountpoints()
+ for x in self.locations:
+ x[3] = x[2]
+ return [x[0] for x in self.locations if x[3]]
+
+ value = property(getValue, setValue)