-
Notifications
You must be signed in to change notification settings - Fork 109
/
EXAMPLE-annotation.py
52 lines (37 loc) · 1.37 KB
/
EXAMPLE-annotation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
import npyscreen
# This example shows how to display the contents of
# a dictionary to a user.
class KeyValueLine(npyscreen.AnnotateTextboxBase):
ANNOTATE_WIDTH = 20
def getAnnotationAndColor(self):
if self.value:
return (self.value[0][0:self.ANNOTATE_WIDTH-2], self.annotation_color)
else:
return ('', self.annotation_color)
def display_value(self, vl):
if vl:
return self.safe_string(str(vl[1]))
else:
return ''
class KeyValueMultiline(npyscreen.MultiLine):
_contained_widgets = KeyValueLine
def when_parent_changes_value(self):
self.values = self.parent.value.items()
def display_value(self, vl):
# pass the real object to subwidgets
return vl
class MyForm(npyscreen.Form):
def create(self):
self.wgdisplay = self.add(KeyValueMultiline)
class MyTestApp(npyscreen.NPSAppManaged):
def onStart(self):
mainform = self.addForm("MAIN", MyForm)
test_dict= {}
for i in range(10000):
test_dict[str(i)] = 'test %s' % i
# The following line is the one you want to replace, I suspect.
#mainform.set_value(globals().copy())
mainform.set_value(test_dict)
if __name__ == "__main__":
MyTestApp().run()