blob: a0b33abdf0035ccdbd70ef7b4e62c75c2d7f97eb [file] [log] [blame]
#!/usr/bin/env python
from Tkinter import *
LOG_LEVELS = [
"NONE",
"ERROR",
"WARN",
"INFO",
"DEBUG",
"TRACE",
"ALL"
]
class GuiFrame(Frame):
def __init__(self, notebook, prefValues, appId):
Frame.__init__(self, notebook)
self.prefValues = prefValues
self.appId = appId
self.row = 0
self.column = 0
def addEntryBox(self, label, variable, defaultValue=""):
variable.set(defaultValue)
Label(self, text=label).grid(row=self.row, sticky=E)
entry = Entry(self, textvariable=variable)
entry.grid(row=self.row, column=1)
self.row += 1
def addDropDown(self, label, variable, values, defaultValue=""):
variable.set(defaultValue)
Label(self, text=label).grid(row=self.row, sticky=E)
self.entry = apply(OptionMenu, (self, variable) + tuple(values))
self.entry.grid(row=self.row, column=1)
self.row += 1
def getPreferredOrDefaultValue(self, key, defaultValue):
if self.appId in self.prefValues:
return self.prefValues[self.appId][key]
else:
return defaultValue
class NfdFrame(GuiFrame):
def __init__(self, notebook, prefValues):
GuiFrame.__init__(self, notebook, prefValues, "nfd")
self.frameLabel = "NFD"
# log-level
self.logLevel = StringVar(self)
self.addDropDown("Log level:",
self.logLevel,
LOG_LEVELS,
self.getPreferredOrDefaultValue("log-level", LOG_LEVELS[3]))
def getValues(self):
return {
"log-level": self.logLevel.get()
}
class NlsrFrame(GuiFrame):
HYPERBOLIC_STATES = [
"off",
"on",
"dry-run"
]
def __init__(self, notebook, prefValues):
GuiFrame.__init__(self, notebook, prefValues, "nlsr")
self.frameLabel = "NLSR"
# general: network
self.network = StringVar(self)
self.addEntryBox("Network:",
self.network,
self.getPreferredOrDefaultValue("network", "/ndn"))
# general: site
self.site = StringVar(self)
self.addEntryBox("Site:", self.site, self.getPreferredOrDefaultValue("site", "/edu/site"))
# general: router
self.router = StringVar(self)
self.addEntryBox("Router:",
self.router,
self.getPreferredOrDefaultValue("router", "/%C1.Router/cs/host"))
# general: log-level
self.logLevel = StringVar(self)
self.addDropDown("Log level:",
self.logLevel,
LOG_LEVELS,
self.getPreferredOrDefaultValue("log-level", LOG_LEVELS[3]))
# hyperbolic: state
self.hyperbolicState = StringVar(self)
self.addDropDown("Hyperbolic routing:",
self.hyperbolicState,
self.HYPERBOLIC_STATES,
self.getPreferredOrDefaultValue("hyperbolic-state", self.HYPERBOLIC_STATES[0]))
# hyperbolic: angle
self.angle = StringVar(self)
self.addEntryBox("Angle:", self.angle, self.getPreferredOrDefaultValue("angle", "0.0"))
# hyperbolic: radius
self.radius = StringVar(self)
self.addEntryBox("Radius:", self.radius, self.getPreferredOrDefaultValue("radius", "0.0"))
# fib: max-faces-per-prefix
self.maxFaces = StringVar(self)
self.addEntryBox("Max faces per prefix:",
self.maxFaces,
self.getPreferredOrDefaultValue("max-faces-per-prefix", "0"))
def getValues(self):
return {
"network": self.network.get(),
"site": self.site.get(),
"router": self.router.get(),
"log-level": self.logLevel.get(),
"hyperbolic-state": self.hyperbolicState.get(),
"angle": self.angle.get(),
"radius": self.radius.get(),
"max-faces-per-prefix": self.maxFaces.get()
}