Tear down and rebuild the main window. Args: groups: the groups of counters to display
(self, groups)
| 215 | return groups |
| 216 | |
| 217 | def RebuildMainWindow(self, groups): |
| 218 | """Tear down and rebuild the main window. |
| 219 | |
| 220 | Args: |
| 221 | groups: the groups of counters to display |
| 222 | """ |
| 223 | # Remove elements in the current ui |
| 224 | self.ui_counters.clear() |
| 225 | for child in self.root.children.values(): |
| 226 | child.destroy() |
| 227 | |
| 228 | # Build new ui |
| 229 | index = 0 |
| 230 | sorted_groups = groups.keys() |
| 231 | sorted_groups.sort() |
| 232 | for counter_name in sorted_groups: |
| 233 | counter_objs = groups[counter_name] |
| 234 | if self.name_filter.match(counter_name): |
| 235 | name = Tkinter.Label(self.root, width=50, anchor=Tkinter.W, |
| 236 | text=counter_name) |
| 237 | name.grid(row=index, column=0, padx=1, pady=1) |
| 238 | count = len(counter_objs) |
| 239 | for i in range(count): |
| 240 | counter = counter_objs[i] |
| 241 | name = counter.Name() |
| 242 | var = Tkinter.StringVar() |
| 243 | if self.name_filter.match(name): |
| 244 | value = Tkinter.Label(self.root, width=15, anchor=Tkinter.W, |
| 245 | textvariable=var) |
| 246 | value.grid(row=index, column=(1 + i), padx=1, pady=1) |
| 247 | |
| 248 | # If we know how to interpret the prefix of this counter then |
| 249 | # add an appropriate formatting to the variable |
| 250 | if (":" in name) and (name[0] in COUNTER_LABELS): |
| 251 | format = COUNTER_LABELS[name[0]] |
| 252 | else: |
| 253 | format = "%i" |
| 254 | ui_counter = UiCounter(var, format) |
| 255 | self.ui_counters[name] = ui_counter |
| 256 | ui_counter.Set(counter.Value()) |
| 257 | index += 1 |
| 258 | self.root.update() |
| 259 | |
| 260 | def OpenWindow(self): |
| 261 | """Create and display the root window.""" |
no test coverage detected