py-menu-tui 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py_menu_tui-0.1.0/PKG-INFO +3 -0
- py_menu_tui-0.1.0/py_menu_tui.egg-info/PKG-INFO +3 -0
- py_menu_tui-0.1.0/py_menu_tui.egg-info/SOURCES.txt +7 -0
- py_menu_tui-0.1.0/py_menu_tui.egg-info/dependency_links.txt +1 -0
- py_menu_tui-0.1.0/py_menu_tui.egg-info/top_level.txt +1 -0
- py_menu_tui-0.1.0/setup.cfg +4 -0
- py_menu_tui-0.1.0/setup.py +6 -0
- py_menu_tui-0.1.0/win_navigation_tui/__init__.py +7 -0
- py_menu_tui-0.1.0/win_navigation_tui/win_nav_tui.py +217 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
win_navigation_tui
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import msvcrt
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SubsectionManager:
|
|
9
|
+
def __init__(self):
|
|
10
|
+
self.subsections = []
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def add(self, size, names: list, functions: list, section: str, uppersection: str):
|
|
14
|
+
self.subsections.append(
|
|
15
|
+
Subsection(size, names, functions, section, uppersection)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Subsection:
|
|
21
|
+
def __init__(self, size, names: list, functions: list, section: str, uppersection: str = ""):
|
|
22
|
+
self.list = ["\x1b[30;47m"]
|
|
23
|
+
self.names = names[::]
|
|
24
|
+
self.uppersection = uppersection
|
|
25
|
+
self.section = section
|
|
26
|
+
self.functions = functions[::]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
for i in range(size - 1):
|
|
30
|
+
self.list.append("")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class UserInterface:
|
|
35
|
+
def __init__(self, size: int):
|
|
36
|
+
self.list = ["\x1b[30;47m"]
|
|
37
|
+
self.pointer = 0
|
|
38
|
+
self._names = []
|
|
39
|
+
self.functions = []
|
|
40
|
+
self.subsection = SubsectionManager()
|
|
41
|
+
self.path=[]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
for i in range(size - 1):
|
|
45
|
+
self.list.append("")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def setup(self, names: list, functions: list):
|
|
49
|
+
if len(names) == 0 or len(functions) == 0 or len(names) != len(functions):
|
|
50
|
+
raise ValueError("names and functions must be non-empty and of equal length")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
self._names = names[::]
|
|
54
|
+
self.functions = functions[::]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _move_pointer(self, bgcolor, key, pointer=0):
|
|
58
|
+
if key == b'w':
|
|
59
|
+
if pointer - 1 < 0:
|
|
60
|
+
return pointer
|
|
61
|
+
bgcolor[pointer], bgcolor[pointer - 1] = bgcolor[pointer - 1], bgcolor[pointer]
|
|
62
|
+
return pointer - 1
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if key == b's':
|
|
66
|
+
if pointer + 1 > len(bgcolor) - 1:
|
|
67
|
+
return pointer
|
|
68
|
+
bgcolor[pointer], bgcolor[pointer + 1] = bgcolor[pointer + 1], bgcolor[pointer]
|
|
69
|
+
return pointer + 1
|
|
70
|
+
else:
|
|
71
|
+
return pointer
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def begin(self, _list: list = None, _names: list = None, _functions: list = None,title:str="Home"):
|
|
75
|
+
if _list is None:
|
|
76
|
+
_list = self.list[::]
|
|
77
|
+
if _names is None:
|
|
78
|
+
_names = self._names
|
|
79
|
+
if _functions is None:
|
|
80
|
+
_functions = self.functions
|
|
81
|
+
self.path.append(title)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
self.pointer = 0
|
|
85
|
+
l = len(_list)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
_list = ["\x1b[30;47m"]
|
|
89
|
+
for i in range(l - 1):
|
|
90
|
+
_list.append("")
|
|
91
|
+
steps = 0
|
|
92
|
+
temp=0
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
while True:
|
|
96
|
+
try:
|
|
97
|
+
os.system("cls")
|
|
98
|
+
for i in self.path:
|
|
99
|
+
sys.stdout.write(f"/{i}")
|
|
100
|
+
sys.stdout.flush()
|
|
101
|
+
|
|
102
|
+
print("\n")
|
|
103
|
+
|
|
104
|
+
col,lines=os.get_terminal_size(1)
|
|
105
|
+
if self.pointer>=lines//2 and self.pointer>temp:
|
|
106
|
+
steps+=1
|
|
107
|
+
temp=self.pointer
|
|
108
|
+
elif self.pointer<temp:
|
|
109
|
+
steps-=1
|
|
110
|
+
temp=self.pointer
|
|
111
|
+
if steps<0:
|
|
112
|
+
steps=0
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if len(_names)<lines-3:
|
|
116
|
+
steps=0
|
|
117
|
+
for counter in range(steps,steps+(lines-4)):
|
|
118
|
+
if counter==len(_names):
|
|
119
|
+
break
|
|
120
|
+
print(f"{_list[counter]} {_names[counter]}\x1b[0m")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
key = msvcrt.getch()
|
|
124
|
+
self.pointer = self._move_pointer(_list, key, self.pointer)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
if key == b'\r' and self.search_subsection(_names[self.pointer]):
|
|
128
|
+
next_section = self.search_subsection(_names[self.pointer])
|
|
129
|
+
print(self.pointer)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
self.begin(next_section.list, next_section.names, next_section.functions,next_section.section)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
self.pointer = 0
|
|
136
|
+
temp=0
|
|
137
|
+
steps=0
|
|
138
|
+
l = len(_list)
|
|
139
|
+
_list = ["\x1b[30;47m"]
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
for i in range(l - 1):
|
|
143
|
+
_list.append("")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
continue
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
if key == b'\r':
|
|
150
|
+
_functions[self.pointer]()
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
if key == b'\x03':
|
|
154
|
+
quit()
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
if key == b'\x1B':
|
|
158
|
+
del(self.path[-1::])
|
|
159
|
+
return
|
|
160
|
+
|
|
161
|
+
except IndexError:
|
|
162
|
+
print("index error")
|
|
163
|
+
self.pointer = 0
|
|
164
|
+
temp = 0
|
|
165
|
+
steps = 0
|
|
166
|
+
l = len(_list)
|
|
167
|
+
_list = ["\x1b[30;47m"]
|
|
168
|
+
for i in range(l - 1):
|
|
169
|
+
_list.append("")
|
|
170
|
+
|
|
171
|
+
def search_subsection(self, names):
|
|
172
|
+
for sub in self.subsection.subsections:
|
|
173
|
+
if names == sub.section:
|
|
174
|
+
return sub
|
|
175
|
+
return False
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def add_sub_section(self, names:list, functions:list, section:str, uppersection:str=""):
|
|
179
|
+
if len(names) - len(functions) != 0:
|
|
180
|
+
raise ValueError("names and functions must be non-empty and of equal length")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
size = len(names)
|
|
184
|
+
self.subsection.add(size, names, functions, section, uppersection)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
if uppersection != "":
|
|
188
|
+
section_obj = self.search_subsection(uppersection)
|
|
189
|
+
section_obj.names.append(section)
|
|
190
|
+
section_obj.list.append("")
|
|
191
|
+
section_obj.functions.append(None)
|
|
192
|
+
else:
|
|
193
|
+
self.list.append("")
|
|
194
|
+
self._names.append(section)
|
|
195
|
+
self.functions.append(None)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def progressbar(progress: int, width: int = 30):
|
|
200
|
+
filled = int(width * progress / 100)
|
|
201
|
+
bar = "█" * filled + "-" * (width - filled)
|
|
202
|
+
sys.stdout.write(f"\r[{bar}] {progress}%")
|
|
203
|
+
sys.stdout.flush()
|
|
204
|
+
def clear():
|
|
205
|
+
os.system("cls")
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def confirm(message:str):
|
|
209
|
+
print(message+"(Y/N)")
|
|
210
|
+
user_input=input("Enter:")
|
|
211
|
+
if user_input=="y" or user_input=="Y":
|
|
212
|
+
return True
|
|
213
|
+
else:
|
|
214
|
+
return False
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|