ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | from Tkinter import * |
| 4 | |
| 5 | LOG_LEVELS = [ |
| 6 | "NONE", |
| 7 | "ERROR", |
| 8 | "WARN", |
| 9 | "INFO", |
| 10 | "DEBUG", |
| 11 | "TRACE", |
| 12 | "ALL" |
| 13 | ] |
| 14 | |
| 15 | class GuiFrame(Frame): |
| 16 | def __init__(self, notebook): |
| 17 | Frame.__init__(self, notebook) |
| 18 | |
| 19 | self.row = 0 |
| 20 | self.column = 0 |
| 21 | |
| 22 | def addEntryBox(self, label, variable, defaultValue=""): |
| 23 | variable.set(defaultValue) |
| 24 | |
| 25 | Label(self, text=label).grid(row=self.row, sticky=E) |
| 26 | entry = Entry(self, textvariable=variable) |
| 27 | entry.grid(row=self.row, column=1) |
| 28 | |
| 29 | self.row += 1 |
| 30 | |
| 31 | def addDropDown(self, label, variable, values, defaultValue=""): |
| 32 | variable.set(defaultValue) |
| 33 | |
| 34 | Label(self, text=label).grid(row=self.row, sticky=E) |
| 35 | |
| 36 | self.entry = apply(OptionMenu, (self, variable) + tuple(values)) |
| 37 | self.entry.grid(row=self.row, column=1) |
| 38 | |
| 39 | self.row += 1 |
| 40 | |
| 41 | class NfdFrame(GuiFrame): |
| 42 | def __init__(self, notebook): |
| 43 | GuiFrame.__init__(self, notebook) |
| 44 | |
| 45 | self.frameLabel = "NFD" |
| 46 | |
| 47 | # log-level |
| 48 | self.logLevel = StringVar(self) |
| 49 | self.addDropDown("Log level:", self.logLevel, LOG_LEVELS, LOG_LEVELS[3]) |
| 50 | |
| 51 | class NlsrFrame(GuiFrame): |
| 52 | |
| 53 | HYPERBOLIC_STATES = [ |
| 54 | "off", |
| 55 | "on", |
| 56 | "dry-run" |
| 57 | ] |
| 58 | |
| 59 | def __init__(self, notebook): |
| 60 | GuiFrame.__init__(self, notebook) |
| 61 | |
| 62 | self.frameLabel = "NLSR" |
| 63 | |
| 64 | # general: network |
| 65 | self.network = StringVar(self) |
| 66 | self.addEntryBox("Network:", self.network, "/ndn/") |
| 67 | |
| 68 | # general: site |
| 69 | self.site = StringVar(self) |
| 70 | self.addEntryBox("Site:", self.site, "/edu/site") |
| 71 | |
| 72 | # general: router |
| 73 | self.router = StringVar(self) |
| 74 | self.addEntryBox("Router:", self.router, "/%C1.Router/cs/host") |
| 75 | |
| 76 | # general: log-level |
| 77 | self.logLevel = StringVar(self) |
| 78 | self.addDropDown("Log level:", self.logLevel, LOG_LEVELS, LOG_LEVELS[3]) |
| 79 | |
| 80 | # hyperbolic: state |
| 81 | self.hyperbolicState = StringVar(self) |
| 82 | self.addDropDown("Hyperbolic routing:", self.hyperbolicState, |
| 83 | self.HYPERBOLIC_STATES, self.HYPERBOLIC_STATES[0]) |
| 84 | |
| 85 | # hyperbolic: angle |
| 86 | self.angle = StringVar(self) |
| 87 | self.addEntryBox("Angle:", self.angle, "0.0") |
| 88 | |
| 89 | # hyperbolic: radius |
| 90 | self.radius = StringVar(self) |
| 91 | self.addEntryBox("Radius:", self.radius, "0.0") |
| 92 | |
| 93 | # fib: max-faces-per-prefix |
| 94 | self.maxFaces = StringVar(self) |
| 95 | self.addEntryBox("Max faces per prefix:", self.maxFaces, "0") |
| 96 | |
| 97 | |
| 98 | def getValues(self): |
| 99 | return { |
| 100 | "network": self.network.get(), |
| 101 | "site": self.site.get(), |
| 102 | "router": self.router.get(), |
| 103 | "log-level": self.logLevel.get(), |
| 104 | "hyperbolic-state": self.hyperbolicState.get(), |
| 105 | "angle": self.angle.get(), |
| 106 | "radius": self.radius.get(), |
| 107 | "max-faces-per-prefix": self.maxFaces.get() |
| 108 | } |
| 109 | |