+ def setValue(self, val):
+ self.text = str(val)
+
+ value = property(getValue, setValue)
+ _value = property(getValue, setValue)
+
+ def conform(self):
+ pos = len(self.text) - self.marked_pos
+ self.text = self.text.lstrip("0")
+ if self.text == "":
+ self.text = "0"
+ if pos > len(self.text):
+ self.marked_pos = 0
+ else:
+ self.marked_pos = len(self.text) - pos
+
+ def handleKey(self, key):
+ if key in KEY_NUMBERS or key == KEY_ASCII:
+ if key == KEY_ASCII:
+ ascii = getPrevAsciiCode()
+ if not (48 <= ascii <= 57):
+ return
+ else:
+ ascii = getKeyNumber(key) + 48
+ newChar = unichr(ascii)
+ if self.allmarked:
+ self.deleteAllChars()
+ self.allmarked = False
+ self.insertChar(newChar, self.marked_pos, False)
+ self.marked_pos += 1
+ else:
+ ConfigText.handleKey(self, key)
+ self.conform()
+
+ def onSelect(self, session):
+ self.allmarked = (self.value != "")
+
+ def onDeselect(self, session):
+ self.marked_pos = 0
+ self.offset = 0
+
+# a slider.
+class ConfigSlider(ConfigElement):
+ def __init__(self, default = 0, increment = 1, limits = (0, 100)):
+ ConfigElement.__init__(self)
+ self.value = self.default = default
+ self.min = limits[0]
+ self.max = limits[1]
+ self.increment = increment
+
+ def checkValues(self):
+ if self.value < self.min:
+ self.value = self.min
+
+ if self.value > self.max:
+ self.value = self.max
+
+ def handleKey(self, key):
+ if key == KEY_LEFT:
+ self.value -= self.increment
+ elif key == KEY_RIGHT:
+ self.value += self.increment
+ elif key == KEY_HOME:
+ self.value = self.min
+ elif key == KEY_END:
+ self.value = self.max
+ else:
+ return
+ self.checkValues()
+
+ def getText(self):
+ return "%d / %d" % (self.value, self.max)
+
+ 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()