-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.py
106 lines (84 loc) · 3.25 KB
/
console.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# This is the henriette console. It displays all basic information of the system
# and allows full control over all systems.
import urwid
import urwid.widget
def exit_on_q(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
def menu_button(caption, callback):
button = urwid.Button(caption)
urwid.connect_signal(button, 'click', callback)
return urwid.AttrMap(button, None, focus_map='reversed')
def sub_menu(caption, choices):
contents = menu(caption, choices)
def open_menu(button):
return top.open_box(contents)
return menu_button([caption, u'...'], open_menu)
def menu(title, choices):
body = [urwid.Text(title), urwid.Divider()]
body.extend(choices)
return urwid.ListBox(urwid.SimpleFocusListWalker(body))
def item_chosen(button):
response = urwid.Text([u'You chose ', button.label, u'\n'])
done = menu_button(u'Ok', exit_program)
top.open_box(urwid.Filler(urwid.Pile([response, done])))
def exit_program(button):
raise urwid.ExitMainLoop()
menu_top = menu(u'Henriette Main Menu', [
sub_menu(u'Applications', [
sub_menu(u'Accessories', [
menu_button(u'Text Editor', item_chosen),
menu_button(u'Terminal', item_chosen),
]),
]),
sub_menu(u'System', [
sub_menu(u'Preferences', [
menu_button(u'Appearance', item_chosen),
]),
menu_button(u'Lock Screen', item_chosen),
]),
])
class CascadingBoxes(urwid.WidgetPlaceholder):
max_box_levels = 4
def __init__(self, box):
super(CascadingBoxes, self).__init__(urwid.AttrMap(urwid.SolidFill(' '),'bg'))
self.box_level = 0
self.open_box(box)
def open_box(self, box):
self.original_widget = urwid.Overlay(urwid.LineBox(box),
self.original_widget,
align='center', width=('relative', 80),
valign='middle', height=('relative', 80),
min_width=24, min_height=8,
left=self.box_level * 3,
right=(self.max_box_levels - self.box_level - 1) * 3,
top=self.box_level * 2,
bottom=(self.max_box_levels - self.box_level - 1) * 2)
self.box_level += 1
def keypress(self, size, key):
if key == 'esc' and self.box_level > 1:
self.original_widget = self.original_widget[0]
self.box_level -= 1
else:
return super(CascadingBoxes, self).keypress(size, key)
# Main program
top = CascadingBoxes(menu_top)
palette = [
('banner', 'black', 'light gray'),
('streak', 'black', 'dark red'),
('bg', 'black', 'dark blue'),]
# header
header_txt = urwid.Text(('banner', u" Henriette Operating System Console"), align='center')
map_header_text = urwid.AttrMap(header_txt, 'streak')
header = urwid.Filler(map_header_text, 'top')
# body
background = urwid.AttrMap(urwid.SolidFill(' '),'bg')
body = urwid.Overlay(top, background, 'center', ('relative', 100), 'middle', 10)
# footer
footer_txt = urwid.Text(('streak', u" Rudsen 2016"), align='center')
map_footer_txt = urwid.AttrMap(footer_txt, 'streak')
#interior = urwid.Filler(urwid.Pile([map1, map2]))
#window = urwid.LineBox(interior)
frame = urwid.Frame(body, map_header_text, map_footer_txt)
loop = urwid.MainLoop(frame, palette, unhandled_input=exit_on_q)
loop.run()