-
Notifications
You must be signed in to change notification settings - Fork 70
/
example_widgets.py
63 lines (45 loc) · 1.59 KB
/
example_widgets.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
53
54
55
56
57
58
59
60
61
62
63
from picotui.context import Context
from picotui.screen import Screen
from picotui.widgets import *
from picotui.defs import *
with Context():
Screen.attr_color(C_WHITE, C_BLUE)
Screen.cls()
Screen.attr_reset()
d = Dialog(5, 5, 50, 12)
# Can add a raw string to dialog, will be converted to WLabel
d.add(1, 1, "Label:")
d.add(11, 1, WLabel("it's me!"))
d.add(1, 2, "Entry:")
d.add(11, 2, WTextEntry(4, "foo"))
d.add(1, 3, "Dropdown:")
d.add(11, 3, WDropDown(10, ["Red", "Green", "Yellow"]))
d.add(1, 4, "Combo:")
d.add(11, 4, WComboBox(8, "fo", ["foo", "foobar", "bar", "long string"]))
d.add(1, 5, "Auto complete:")
d.add(15, 5, WAutoComplete(8, "fo", ["foo", "foobar", "bar", "car", "dar"]))
d.add(1, 6, "Password:")
d.add(11, 6, WPasswdEntry(10, ""))
d.add(1, 8, "Multiline:")
d.add(1, 9, WMultiEntry(26, 3, ["Example", "Text"]))
d.add(30, 1, WFrame(18, 6, "Frame"))
d.add(31, 2, WCheckbox("State"))
d.add(31, 3, WRadioButton(["Red", "Green", "Yellow"]))
d.add(30, 8, "List:")
d.add(30, 9, WListBox(16, 4, ["choice%d" % i for i in range(10)]))
d.add(1, 13, "Button:")
b = WButton(9, "Kaboom!")
d.add(10, 13, b)
b.on("click", lambda w: 1/0)
d.add(1, 15, "Dialog buttons:")
b = WButton(8, "OK")
d.add(10, 16, b)
# Instead of having on_click handler, buttons can finish a dialog
# with a given result.
b.finish_dialog = ACTION_OK
b = WButton(8, "Cancel")
d.add(30, 16, b)
b.finish_dialog = ACTION_CANCEL
#d.redraw()
res = d.loop()
print("Result:", res)