# you can overide this for fancy default handling
def load(self):
- if self.saved_value is None:
+ sv = self.saved_value
+ if sv is None:
self.value = self.default
else:
- self.value = self.fromstring(self.saved_value)
+ self.value = self.fromstring(sv)
def tostring(self, value):
return str(value)
self.load()
def isChanged(self):
- if self.saved_value is None and self.value == self.default:
+ sv = self.saved_value
+ if sv is None and self.value == self.default:
return False
- return self.tostring(self.value) != self.saved_value
+ return self.tostring(self.value) != sv
def changed(self):
for x in self.notifiers:
return [int(x) for x in value.split(self.seperator)]
class ConfigIP(ConfigSequence):
- def __init__(self, default):
+ def __init__(self, default, auto_jump = False):
ConfigSequence.__init__(self, seperator = ".", limits = [(0,255),(0,255),(0,255),(0,255)], default = default)
-
- def getHTML(self, id):
- # we definitely don't want leading zeros
- return '.'.join(["%d" % d for d in self.value])
-
+ self.block_len = []
+ for x in self.limits:
+ self.block_len.append(len(str(x[1])))
+ self.marked_block = 0
+ self.overwrite = True
+ self.auto_jump = auto_jump
+
+ def handleKey(self, key):
+ if key == KEY_LEFT:
+ if self.marked_block > 0:
+ self.marked_block -= 1
+ self.overwrite = True
+
+ if key == KEY_RIGHT:
+ if self.marked_block < len(self.limits)-1:
+ self.marked_block += 1
+ self.overwrite = True
+
+ if key == KEY_HOME:
+ self.marked_block = 0
+ self.overwrite = True
+
+ if key == KEY_END:
+ self.marked_block = len(self.limits)-1
+ self.overwrite = True
+
+ if key in KEY_NUMBERS:
+ number = getKeyNumber(key)
+ oldvalue = self._value[self.marked_block]
+
+ if self.overwrite:
+ self._value[self.marked_block] = number
+ self.overwrite = False
+ else:
+ oldvalue *= 10
+ newvalue = oldvalue + number
+ if self.auto_jump and newvalue > self.limits[self.marked_block][1] and self.marked_block < len(self.limits)-1:
+ self.handleKey(KEY_RIGHT)
+ self.handleKey(key)
+ return
+ else:
+ self._value[self.marked_block] = newvalue
+
+ if len(str(self._value[self.marked_block])) >= self.block_len[self.marked_block]:
+ self.handleKey(KEY_RIGHT)
+
+ self.validate()
+ self.changed()
+
def genText(self):
value = ""
- mPos = self.marked_pos
- num = 0;
+ block_strlen = []
for i in self._value:
+ block_strlen.append(len(str(i)))
if len(value):
value += self.seperator
- if mPos >= len(value) - 1:
- mPos += 1
- value += (" " * (len(str(self.limits[num][1]))-len(str(i))))
value += str(i)
- num += 1
- return (value, mPos)
+ leftPos = sum(block_strlen[:(self.marked_block)])+self.marked_block
+ rightPos = sum(block_strlen[:(self.marked_block+1)])+self.marked_block
+ mBlock = range(leftPos, rightPos)
+ return (value, mBlock)
+
+ def getMulti(self, selected):
+ (value, mBlock) = self.genText()
+ if self.enabled:
+ return ("mtext"[1-selected:], value, mBlock)
+ else:
+ return ("text", value)
+
+ def getHTML(self, id):
+ # we definitely don't want leading zeros
+ return '.'.join(["%d" % d for d in self.value])
class ConfigMAC(ConfigSequence):
def __init__(self, default):
class ConfigPassword(ConfigText):
def __init__(self, default = "", fixed_size = False, visible_width = False, censor = "*"):
- ConfigText.__init__(self, default = "", fixed_size = fixed_size, visible_width = visible_width)
+ ConfigText.__init__(self, default = default, fixed_size = fixed_size, visible_width = visible_width)
self.censor_char = censor
self.hidden = True
return eval(val)
def load(self):
- if self.saved_value is None:
+ sv = self.saved_value
+ if sv is None:
tmp = self.default
else:
- tmp = self.fromstring(self.saved_value)
+ tmp = self.fromstring(sv)
self.locations = [[x, None, False, False] for x in tmp]
self.refreshMountpoints()
for x in self.locations:
self.saved_value = self.tostring([x[0] for x in self.locations])
def isChanged(self):
- if self.saved_value is None and self.locations == []:
+ sv = self.saved_value
+ if val is None and self.locations == []:
return False
- return self.tostring([x[0] for x in self.locations]) != self.saved_value
+ return self.tostring([x[0] for x in self.locations]) != sv
def mountpointsChanged(self, action, dev):
print "Mounts changed: ", action, dev
self[int(key)].saved_value = val
saved_value = property(getSavedValue, setSavedValue)
-
+
def append(self, item):
i = str(len(self))
list.append(self, item)
def getSavedValue(self):
res = {}
for (key, val) in self.items():
- if val.saved_value is not None:
- res[str(key)] = val.saved_value
+ sv = val.saved_value
+ if sv is not None:
+ res[str(key)] = sv
return res
def setSavedValue(self, values):
def getSavedValue(self):
res = self.content.stored_values
for (key, val) in self.content.items.items():
- if val.saved_value is not None:
- res[key] = val.saved_value
+ sv = val.saved_value
+ if sv is not None:
+ res[key] = sv
elif key in res:
del res[key]
-
return res
def setSavedValue(self, values):