This repository was archived by the owner on Mar 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (62 loc) · 2.17 KB
/
Copy pathmain.py
File metadata and controls
88 lines (62 loc) · 2.17 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
84
85
86
87
88
"""Main interface module for simple user interaction.
This module allows the user to interact with the program through a simple
command line interface. It provides functions to generate a maze, search
it and display the results in several ways.
Author:
-------
- Paulo Sánchez (@erlete)
"""
import os
from utils.interface.interface_menu import InterfaceMenu
from utils.interface.menu import MenuItem
# Configuration constants:
INDEX_OFFSET = 1
# Object instantiation:
MENU = InterfaceMenu()
MENU.add_item(
MenuItem("Generate maze", MENU.generate_maze),
MenuItem("Depth-first search", MENU.df_search),
MenuItem("Breadth-first search", MENU.bf_search),
MenuItem("Greedy best-first search", MENU.gbf_search),
MenuItem("Radial search", MENU.r_search),
MenuItem("Display ASCII", MENU.display_ascii),
MenuItem("Display image", MENU.display_image),
MenuItem("Save image", MENU.save_image),
MenuItem("Exit interface")
)
# Mainloop:
active = True
while active:
os.system("clear")
MENU.display(index_offset=INDEX_OFFSET)
try:
option = input(" · Select an option: ")
print()
# Non-digit entry check:
if option.isdigit():
option = int(option)
# Out of bounds entry check:
if INDEX_OFFSET <= option <= len(MENU):
item = MENU.get_by_index(option - INDEX_OFFSET)
os.system("clear")
print(f" Executing \"{item}\" ".center(90, '–') + '\n')
# Existing callback function check:
if item.callback_function is not None:
MENU.execute(item)
else:
active = False
else:
print("Invalid index value, try again...\n")
else:
print("Not an index value, try again...\n")
# Forced exit:
except KeyboardInterrupt:
active = False
# Unclassified exception report:
except Exception as exception:
print(f"Unclassified error. Report: {exception}\n")
finally:
if active:
input(" Enter to continue... ".center(90, '–')) # Display stop.
else:
exit()