-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu_entry.py
More file actions
executable file
·58 lines (42 loc) · 1.49 KB
/
menu_entry.py
File metadata and controls
executable file
·58 lines (42 loc) · 1.49 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
#!/usr/bin/env python
# encoding: utf-8
__all__ = ["MenuEntry"]
class MenuEntry(object):
"""
Simple menu object with key, description and callback function
"""
def __init__(self, key, description, callback_function, *args, **kwargs):
"""
Class for menu entries
Args:
key(str): key of the menu entry, input of key will trigger the callback_function
description(str): descriptive text of the menu entry
callback_function(function): call back function to envole if menu entry is triggered
"""
self.key = key
self.description = description
self.callback = callback_function
self.args = args
self.kwargs = kwargs
def callback_function(self, userInput):
"""
"""
if "userInput" in self.kwargs:
self.kwargs['userInput'] = userInput
if self.args and self.kwargs:
self.callback(self.args, self.kwargs)
elif self.args:
self.callback(self.args)
elif self.kwargs:
self.callback(self.kwargs)
else:
self.callback()
def display(self):
"""
Function which returns as string to display the menu entry
Retruns
"""
return "[ {:2} ] - {}".format(self.key, self.description)
if __name__ == "__main__":
import doctest
doctest.testmod()