-
-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathmain.py
More file actions
208 lines (176 loc) · 7.19 KB
/
Copy pathmain.py
File metadata and controls
208 lines (176 loc) · 7.19 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""
🎮 Python Mini Projects — Interactive Launcher Menu
===================================================
A central, interactive CLI menu at the root level to browse,
search, and launch all games, math utilities, and other tools.
"""
import os
import subprocess
import sys
import json
REGISTRY_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "projects_registry.json")
try:
with open(REGISTRY_PATH, "r", encoding="utf-8") as f:
PROJECTS = json.load(f)
except Exception as e:
print(f"Error loading project registry: {e}")
PROJECTS = []
DIFFICULTY_BADGES = {
"beginner": "🟢 Beg",
"intermediate": "🟡 Int",
"advanced": "🔴 Adv",
}
CATEGORY_EMOJIS = {
"games": "🎮",
"math": "🔢",
"utilities": "🔧",
}
def print_header():
print("\n" + "═" * 60)
print(" 🚀 PYTHON MINI PROJECTS — INTERACTIVE LAUNCHER")
print("═" * 60)
def print_footer():
print("═" * 60)
def list_projects_by_category(category_name):
filtered = [p for p in PROJECTS if p.get("category", "") == category_name]
filtered_sorted = sorted(filtered, key=lambda p: p.get("name", ""))
return filtered_sorted
def launch_project(path):
if not os.path.exists(path):
print(f"\n❌ Error: File not found at '{path}'")
input("\nPress Enter to return to menu...")
return
print(f"\n🚀 Launching: {os.path.basename(path)}")
print("─" * 60 + "\n")
try:
# Run with current python executable
subprocess.run([sys.executable, path])
except Exception as e:
print(f"\n❌ Error executing script: {e}")
print("\n" + "─" * 60)
input("ℹ️ Script finished. Press Enter to return to the launcher...")
def main_menu():
while True:
os.system('cls' if os.name == 'nt' else 'clear')
print_header()
print(" Please select a category to browse:")
print("\n [1] 🎮 Games")
print(" [2] 🔢 Math Utilities")
print(" [3] 🔧 General Utilities")
print(" [4] 🔍 Search Projects by Keyword")
print(" [5] 📋 List All Projects")
print(" [6] ❌ Exit")
print_footer()
choice = input("👉 Enter choice (1-6): ").strip()
if choice == "1":
category_menu("games", "Games")
elif choice == "2":
category_menu("math", "Math Utilities")
elif choice == "3":
category_menu("utilities", "General Utilities")
elif choice == "4":
search_menu()
elif choice == "5":
list_all_menu()
elif choice == "6":
print("\n👋 Happy Coding! Goodbye.\n")
break
else:
input("\n⚠️ Invalid selection. Press Enter to try again...")
def category_menu(category_key, category_title):
while True:
os.system('cls' if os.name == 'nt' else 'clear')
print_header()
print(f" 📂 Category: {category_title}")
print("─" * 60)
items = list_projects_by_category(category_key)
for idx, item in enumerate(items, start=1):
difficulty = DIFFICULTY_BADGES.get(item.get("difficulty", "Unknown"), item.get("difficulty", "Unknown"))
print(f" [{idx:2d}] {item.get('emoji', '')} {item.get('name', ''):30s} [{difficulty}]")
print(f" {item.get('description', '')}")
print()
print(f" [B] 🔙 Back to Main Menu")
print_footer()
choice = input("👉 Select project number to launch (or 'b' to go back): ").strip().lower()
if choice == 'b':
break
try:
val = int(choice)
if 1 <= val <= len(items):
launch_project(items[val - 1]["path"])
else:
input("\n⚠️ Number out of range. Press Enter to try again...")
except ValueError:
input("\n⚠️ Invalid input. Please enter a number or 'b'. Press Enter to try again...")
def search_menu():
os.system('cls' if os.name == 'nt' else 'clear')
print_header()
print(" 🔍 Search Projects")
print_footer()
query = input("👉 Enter search keyword (e.g., game, solver, cipher): ").strip().lower()
if not query:
return
results = [
p for p in PROJECTS
if query in p["name"].lower()
or query in p["description"].lower()
or any(query in kw.lower() for kw in p["keywords"])
]
if not results:
input("\n⚠️ No matching projects found. Press Enter to return to main menu...")
return
while True:
os.system('cls' if os.name == 'nt' else 'clear')
print_header()
print(f" 🔍 Search Results for '{query}':")
print("─" * 60)
for idx, item in enumerate(results, start=1):
cat_emoji = CATEGORY_EMOJIS.get(item.get("category", ""), "")
difficulty = DIFFICULTY_BADGES.get(item.get("difficulty", "Unknown"), item.get("difficulty", "Unknown"))
print(f" [{idx:2d}] {cat_emoji} {item.get('name', ''):30s} [{difficulty}]")
print(f" {item.get('description', '')}")
print()
print(f" [B] 🔙 Back to Main Menu")
print_footer()
choice = input("👉 Select project number to launch (or 'b' to go back): ").strip().lower()
if choice == 'b':
break
try:
val = int(choice)
if 1 <= val <= len(results):
launch_project(results[val - 1]["path"])
else:
input("\n⚠️ Number out of range. Press Enter to try again...")
except ValueError:
input("\n⚠️ Invalid input. Please enter a number or 'b'. Press Enter to try again...")
def list_all_menu():
while True:
os.system('cls' if os.name == 'nt' else 'clear')
print_header()
print(" 📋 All Projects")
print("─" * 60)
sorted_all = sorted(PROJECTS, key=lambda p: (p.get("category", ""), p.get("name", "")))
for idx, item in enumerate(sorted_all, start=1):
cat_emoji = CATEGORY_EMOJIS.get(item.get("category", ""), "")
difficulty = DIFFICULTY_BADGES.get(item.get("difficulty", "Unknown"), item.get("difficulty", "Unknown"))
print(f" [{idx:2d}] {cat_emoji} {item.get('name', ''):30s} [{difficulty}]")
print(f" {item.get('description', '')}")
print()
print(f" [B] 🔙 Back to Main Menu")
print_footer()
choice = input("👉 Select project number to launch (or 'b' to go back): ").strip().lower()
if choice == 'b':
break
try:
val = int(choice)
if 1 <= val <= len(sorted_all):
launch_project(sorted_all[val - 1]["path"])
else:
input("\n⚠️ Number out of range. Press Enter to try again...")
except ValueError:
input("\n⚠️ Invalid input. Please enter a number or 'b'. Press Enter to try again...")
if __name__ == "__main__":
try:
main_menu()
except KeyboardInterrupt:
print("\n\n👋 Goodbye!")