diff options
| author | nasrlol <nsrddyn@gmail.com> | 2024-12-03 02:02:04 +0100 |
|---|---|---|
| committer | nasrlol <nsrddyn@gmail.com> | 2024-12-03 02:02:04 +0100 |
| commit | 1a3c5ac8cbbf6e3fa72983156ff279b57785852a (patch) | |
| tree | fe0ecd90b0113284624e1740a4b7fae3c944b46a | |
| parent | 88567c71a6f9d78870e4c0ced326ae24f4b965aa (diff) | |
made the cli application
| -rw-r--r-- | .qtc_clangd/compile_commands.json | 1 | ||||
| -rw-r--r-- | source/main_cli.py | 110 | ||||
| -rw-r--r-- | source/main_qt.py (renamed from source/main.py) | 0 |
3 files changed, 111 insertions, 0 deletions
diff --git a/.qtc_clangd/compile_commands.json b/.qtc_clangd/compile_commands.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/.qtc_clangd/compile_commands.json | |||
| @@ -0,0 +1 @@ | |||
| [] \ No newline at end of file | |||
diff --git a/source/main_cli.py b/source/main_cli.py new file mode 100644 index 0000000..53f49aa --- /dev/null +++ b/source/main_cli.py | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | import hardware_driver as lcd # Simulated library for LCD hardware control | ||
| 2 | import features as fe # Simulated library for app-specific features | ||
| 3 | import curses # Library for terminal UI | ||
| 4 | import sys | ||
| 5 | import time | ||
| 6 | |||
| 7 | # Initialize feature and LCD objects | ||
| 8 | F = fe.feat() # Instance of the feature class | ||
| 9 | L = lcd.LCD() # Instance of the LCD driver class | ||
| 10 | |||
| 11 | # Define a list of actions, linking functions from the `features` library | ||
| 12 | actions = [ | ||
| 13 | F.temperature, # Function to display temperature | ||
| 14 | F.save_notes, # Function to save notes | ||
| 15 | F.recognize_speech, # Function to recognize speech | ||
| 16 | F.pomodoro, # Function for the Pomodoro timer | ||
| 17 | F.display_uptime, # Function to display system uptime | ||
| 18 | F.custom_greeting, # Function for a custom greeting | ||
| 19 | F.command_center, # Function to launch a command center | ||
| 20 | ] | ||
| 21 | |||
| 22 | |||
| 23 | # Menu drawing function | ||
| 24 | def draw_menu(stdscr): | ||
| 25 | """ | ||
| 26 | This function creates a text-based menu using curses. | ||
| 27 | """ | ||
| 28 | # Turn off the cursor and enable keypad input for better UX | ||
| 29 | curses.curs_set(0) | ||
| 30 | stdscr.keypad(True) | ||
| 31 | |||
| 32 | # Define button names | ||
| 33 | buttons = [ | ||
| 34 | "Display Temperature", | ||
| 35 | "Save Notes", | ||
| 36 | "Recognize Speech", | ||
| 37 | "Pomodoro Timer", | ||
| 38 | "Show Uptime", | ||
| 39 | "Custom Greeting", | ||
| 40 | "Command Center", | ||
| 41 | ] | ||
| 42 | |||
| 43 | current_selection = 0 # Track which button is selected | ||
| 44 | |||
| 45 | while True: | ||
| 46 | # Clear the screen before redrawing | ||
| 47 | stdscr.clear() | ||
| 48 | |||
| 49 | # Display buttons with proper alignment | ||
| 50 | h, w = stdscr.getmaxyx() # Get screen height and width | ||
| 51 | for idx, button in enumerate(buttons): | ||
| 52 | x = w // 2 - len(button) // 2 # Center-align text horizontally | ||
| 53 | y = h // 2 - len(buttons) // 2 + idx # Stack buttons vertically | ||
| 54 | |||
| 55 | # Highlight the currently selected button | ||
| 56 | if idx == current_selection: | ||
| 57 | stdscr.attron(curses.A_REVERSE) # Reverse color for highlight | ||
| 58 | stdscr.addstr(y, x, button) | ||
| 59 | stdscr.attroff(curses.A_REVERSE) # Turn off highlight | ||
| 60 | else: | ||
| 61 | stdscr.addstr(y, x, button) | ||
| 62 | |||
| 63 | stdscr.refresh() # Refresh the screen to show changes | ||
| 64 | |||
| 65 | # Wait for user input | ||
| 66 | key = stdscr.getch() | ||
| 67 | |||
| 68 | # Handle up arrow key to move selection up | ||
| 69 | if key == curses.KEY_UP and current_selection > 0: | ||
| 70 | current_selection -= 1 | ||
| 71 | |||
| 72 | # Handle down arrow key to move selection down | ||
| 73 | elif key == curses.KEY_DOWN and current_selection < len(buttons) - 1: | ||
| 74 | current_selection += 1 | ||
| 75 | |||
| 76 | # Handle Enter key to execute the selected action | ||
| 77 | elif key == curses.KEY_ENTER or key in [10, 13]: | ||
| 78 | stdscr.clear() # Clear the screen | ||
| 79 | try: | ||
| 80 | # Execute the action corresponding to the selected button | ||
| 81 | result = actions[current_selection]() | ||
| 82 | if isinstance(result, str): # If action returns a string, display it | ||
| 83 | stdscr.addstr(h // 2, w // 2 - len(result) // 2, result) | ||
| 84 | else: # For non-string results, display a generic message | ||
| 85 | stdscr.addstr(h // 2, w // 2 - 10, "Action executed successfully.") | ||
| 86 | except Exception as e: | ||
| 87 | # Handle any errors gracefully and display them | ||
| 88 | error_message = f"Error: {e}" | ||
| 89 | stdscr.addstr(h // 2, w // 2 - len(error_message) // 2, error_message) | ||
| 90 | |||
| 91 | # Prompt user to return to the menu | ||
| 92 | stdscr.addstr(h // 2 + 2, w // 2 - 10, "Press any key to return.") | ||
| 93 | stdscr.refresh() | ||
| 94 | stdscr.getch() # Wait for any key press to return to the menu | ||
| 95 | |||
| 96 | # Handle Escape key to exit the application | ||
| 97 | elif key == 27: | ||
| 98 | break # Exit the while loop and terminate the program | ||
| 99 | |||
| 100 | |||
| 101 | def main(): | ||
| 102 | """ | ||
| 103 | The main function wraps the curses functionality and runs the application. | ||
| 104 | """ | ||
| 105 | curses.wrapper(draw_menu) # Handles initialization and cleanup of curses | ||
| 106 | |||
| 107 | |||
| 108 | # Run the application if this script is executed directly | ||
| 109 | if __name__ == "__main__": | ||
| 110 | main() | ||
diff --git a/source/main.py b/source/main_qt.py index 5a37a88..5a37a88 100644 --- a/source/main.py +++ b/source/main_qt.py | |||
