Upload files to "Modules"
This commit is contained in:
32
Modules/common_ui.py
Normal file
32
Modules/common_ui.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import os
|
||||||
|
import platform
|
||||||
|
from Assets.ascii_text_prompts import ascii_art, full_ascii_art, infinitei
|
||||||
|
from Assets.random_tip import get_random_tip_with_color
|
||||||
|
|
||||||
|
def clear_screen():
|
||||||
|
# Check the system platform and use the appropriate command
|
||||||
|
if platform.system().lower() == "windows":
|
||||||
|
os.system('cls') # Windows command to clear the screen
|
||||||
|
else:
|
||||||
|
os.system('clear') # Unix-based (Linux/macOS) command to clear the screen
|
||||||
|
|
||||||
|
|
||||||
|
def header(is_main_menu=False):
|
||||||
|
"""
|
||||||
|
Displays the header with optional full application details.
|
||||||
|
:param is_main_menu: Boolean to indicate whether to display full details.
|
||||||
|
"""
|
||||||
|
clear_screen()
|
||||||
|
if is_main_menu:
|
||||||
|
print(center_text(full_ascii_art)) # Full application name in ASCII art
|
||||||
|
print(center_text(infinitei)) # "Created By Me"
|
||||||
|
else:
|
||||||
|
print(center_text(ascii_art)) # Minimal header
|
||||||
|
print(center_text(get_random_tip_with_color()) + "\n")
|
||||||
|
|
||||||
|
def center_text(text):
|
||||||
|
terminal_width = os.get_terminal_size().columns
|
||||||
|
centered_lines = []
|
||||||
|
for line in text.splitlines():
|
||||||
|
centered_lines.append(line.center(terminal_width))
|
||||||
|
return "\n".join(centered_lines)
|
56
Modules/search_for_word.py
Normal file
56
Modules/search_for_word.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import os
|
||||||
|
import ast
|
||||||
|
from colorama import Fore, Style
|
||||||
|
from Modules.submenu import build_submenu
|
||||||
|
|
||||||
|
def search_for_word_in_file(file_path, search_term):
|
||||||
|
"""
|
||||||
|
Searches for a word in the titles and content of functions in a specified file.
|
||||||
|
Returns a list of matching results with the file name.
|
||||||
|
"""
|
||||||
|
results = []
|
||||||
|
with open(file_path, "r") as file:
|
||||||
|
try:
|
||||||
|
tree = ast.parse(file.read())
|
||||||
|
for node in ast.walk(tree):
|
||||||
|
if isinstance(node, ast.FunctionDef): # Look for function definitions
|
||||||
|
for child in ast.iter_child_nodes(node):
|
||||||
|
if isinstance(child, ast.Expr) and isinstance(child.value, ast.Str):
|
||||||
|
# Extract docstring or title-like expressions
|
||||||
|
docstring = child.value.s
|
||||||
|
if search_term.lower() in docstring.lower():
|
||||||
|
results.append(f"{file_path} -> {node.name}: {docstring.strip()}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error reading {file_path}: {e}")
|
||||||
|
return results
|
||||||
|
|
||||||
|
def search_for_word_in_directory(directory, search_term):
|
||||||
|
"""
|
||||||
|
Searches through all `.py` files in a directory for a specific term.
|
||||||
|
"""
|
||||||
|
matches = []
|
||||||
|
for root, _, files in os.walk(directory):
|
||||||
|
for file in files:
|
||||||
|
if file.endswith(".py"):
|
||||||
|
file_path = os.path.join(root, file)
|
||||||
|
matches.extend(search_for_word_in_file(file_path, search_term))
|
||||||
|
return matches
|
||||||
|
|
||||||
|
def create_search_submenu(search_results):
|
||||||
|
"""
|
||||||
|
Creates a dynamic submenu for search results.
|
||||||
|
"""
|
||||||
|
actions = {}
|
||||||
|
for idx, result in enumerate(search_results, start=1):
|
||||||
|
file_name, function_info = result.split(" -> ", 1)
|
||||||
|
actions[str(idx)] = {
|
||||||
|
"description": f"{file_name}: {function_info.split(':')[0]}",
|
||||||
|
"function": lambda: print(f"\nViewing: {result}\n"), # Placeholder action
|
||||||
|
}
|
||||||
|
|
||||||
|
actions["ALL"] = {
|
||||||
|
"description": "Display All Results",
|
||||||
|
"function": lambda: print("\n".join(search_results))
|
||||||
|
}
|
||||||
|
|
||||||
|
build_submenu("Search Results", actions)
|
@ -1,7 +1,6 @@
|
|||||||
import sys # For exiting the program
|
import sys # For exiting the program
|
||||||
|
from Modules.common_ui import *
|
||||||
from Modules.wrappers import *
|
from Modules.wrappers import *
|
||||||
from Modules.Submenus.analyst_notebook import analyst_notebook_submenu
|
|
||||||
from Modules.Submenus.about import about_submenu
|
|
||||||
|
|
||||||
|
|
||||||
# Global action status to persist across all submenus and their nested submenus
|
# Global action status to persist across all submenus and their nested submenus
|
||||||
|
@ -1,30 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
|
|
||||||
from Assets.ascii_text_prompts import ascii_art, full_ascii_art, infinitei
|
|
||||||
from Assets.random_tip import get_random_tip_with_color
|
|
||||||
from Modules.global_commands import *
|
from Modules.global_commands import *
|
||||||
|
from Modules.search_for_word import search_for_word_in_directory, create_search_submenu
|
||||||
|
from Modules.common_ui import *
|
||||||
|
|
||||||
def clear_screen():
|
|
||||||
# Check the system platform and use the appropriate command
|
|
||||||
if platform.system().lower() == "windows":
|
|
||||||
os.system('cls') # Windows command to clear the screen
|
|
||||||
else:
|
|
||||||
os.system('clear') # Unix-based (Linux/macOS) command to clear the screen
|
|
||||||
|
|
||||||
def header(is_main_menu=False):
|
|
||||||
"""
|
|
||||||
Displays the header with optional full application details.
|
|
||||||
:param is_main_menu: Boolean to indicate whether to display full details.
|
|
||||||
"""
|
|
||||||
clear_screen()
|
|
||||||
if is_main_menu:
|
|
||||||
print(center_text(full_ascii_art)) # Full application name in ASCII art
|
|
||||||
print(center_text(infinitei)) # "Created By Me"
|
|
||||||
else:
|
|
||||||
print(center_text(ascii_art)) # Minimal header
|
|
||||||
print(center_text(get_random_tip_with_color()) + "\n")
|
|
||||||
|
|
||||||
def display_menu(menu_options):
|
def display_menu(menu_options):
|
||||||
while True:
|
while True:
|
||||||
@ -32,7 +13,8 @@ def display_menu(menu_options):
|
|||||||
for key, value in menu_options.items():
|
for key, value in menu_options.items():
|
||||||
print(f"[{key}] {value['name'].upper()}")
|
print(f"[{key}] {value['name'].upper()}")
|
||||||
print("[0] Logout")
|
print("[0] Logout")
|
||||||
print("[NOTE] Analyst Notebook | [ABOUT] About Page\n") # Add global command options
|
print("[NOTE] Analyst Notebook | [ABOUT] About Page")
|
||||||
|
print("[SEARCH] Search for a Term\n") # Add a global search option
|
||||||
|
|
||||||
choice = input("Enter your choice: ").strip().lower()
|
choice = input("Enter your choice: ").strip().lower()
|
||||||
|
|
||||||
@ -41,6 +23,18 @@ def display_menu(menu_options):
|
|||||||
global_command_handler(choice) # Call the global command handler
|
global_command_handler(choice) # Call the global command handler
|
||||||
continue # Restart the loop after handling global commands
|
continue # Restart the loop after handling global commands
|
||||||
|
|
||||||
|
# Handle search
|
||||||
|
if choice == "search":
|
||||||
|
term = input("Enter the term to search for: ").strip()
|
||||||
|
search_results = search_for_word_in_directory(".", term) # Search in the current directory
|
||||||
|
if search_results:
|
||||||
|
print(f"\n{Fore.GREEN}Search Results for '{term}':{Style.RESET_ALL}")
|
||||||
|
create_search_submenu(search_results) # Open dynamic submenu for results
|
||||||
|
else:
|
||||||
|
print(f"{Fore.RED}No results found for '{term}'.{Style.RESET_ALL}")
|
||||||
|
input("Press Enter to continue...")
|
||||||
|
continue
|
||||||
|
|
||||||
# Match the choice to a menu option
|
# Match the choice to a menu option
|
||||||
if choice in menu_options:
|
if choice in menu_options:
|
||||||
menu_options[choice]["submenu"]() # Call the submenu without arguments
|
menu_options[choice]["submenu"]() # Call the submenu without arguments
|
||||||
@ -50,19 +44,10 @@ def display_menu(menu_options):
|
|||||||
else:
|
else:
|
||||||
print("Invalid choice. Please try again.")
|
print("Invalid choice. Please try again.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def print_info(title, content):
|
def print_info(title, content):
|
||||||
header()
|
header()
|
||||||
print("=" * 40)
|
print("=" * 40)
|
||||||
print(f"{title.center(40)}")
|
print(f"{title.center(40)}")
|
||||||
print("=" * 40)
|
print("=" * 40)
|
||||||
print(content)
|
print(content)
|
||||||
input("\nPress Enter to return to the menu...")
|
input("\nPress Enter to return to the menu...")
|
||||||
|
|
||||||
def center_text(text):
|
|
||||||
terminal_width = os.get_terminal_size().columns
|
|
||||||
centered_lines = []
|
|
||||||
for line in text.splitlines():
|
|
||||||
centered_lines.append(line.center(terminal_width))
|
|
||||||
return "\n".join(centered_lines)
|
|
Reference in New Issue
Block a user