-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
83 lines (63 loc) · 2.13 KB
/
ui.py
File metadata and controls
83 lines (63 loc) · 2.13 KB
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
import copy
# An example output:
# /-----------------------------------\
# | id | title | type |
# |--------|----------------|---------|
# | 0 | Counter strike | fps |
# |--------|----------------|---------|
# | 1 | fo | fps |
# \-----------------------------------/
def print_table(table, title_list=""):
""" Pretty prints a table or prints a simple string. """
if isinstance(table, str):
print(table)
return
table = copy.deepcopy(table)
table.insert(0, title_list)
table = [[str("| " + cell) for cell in row] for row in table]
lenghts = [max(map(len, col)) for col in zip(*table)]
width_format = ''.join('{{:<{}}}'.format(x) for x in lenghts)
table = [width_format.format(*row) for row in table]
table[:] = [x for i in table for x in [i + ' |', '-'*(2+len(table[0]))]]
table.insert(0, "-"*(len(table[0])))
corner = list(table[0])
(corner[0], corner[-1]) = "/", "\\"
table[0] = "".join(corner)
corner = list(table[-1])
(corner[0], corner[-1]) = "\\", "/"
table[-1] = "".join(corner)
row_list = list(table[1])
for i in range(len(table[1])):
if row_list[i] == "|":
for k in range(1, len(table)-1):
row_list2 = list(table[k])
row_list2[i] = "|"
table[k] = "".join(row_list2)
print('\n'.join(table))
# An example output:
# Main menu:
# (1) Store manager
# (2) Human resources manager
# (3) Inventory manager
# (4) Accounting manager
# (5) Selling manager
# (6) Customer relationship management (CRM)
# (0) Exit program
#
# see the function call in main.py
def print_menu(title='Title', list_options=['a', 'b', 'c'], exit_message="Back"):
print("%s:" % (title))
line = 1
for i in list_options:
print("(%s) %s" % (line, i))
line += 1
print("(%s) %s" % (0, exit_message))
# see the function call in main.py
def get_inputs(list_titles, title):
print(title)
record = [input(i) for i in list_titles]
# your code
return record
# see the function call in main.py
def print_error_message(message):
print(message)