### Kascmenu Engine Quick Start Commands Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/INSTALL.md After installation, use these commands to check the installation, initialize a new project, navigate into the project directory, and run the application. ```bash kcm doctor kcm init my_app cd my_app python app.py kcm run ``` -------------------------------- ### Complete Application Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/App.md A comprehensive example demonstrating the setup and execution of a kascmenu-engine application with a menu, custom theme, and the run method. ```python from kcmpy import App, Rect from kcmpy.cui.widgets import Box, Text from kcmpy.cui.menu import Menu, MenuItem from kcmpy.core.theme import Themes, set_theme # Create root component menu = Menu( Rect(10, 5, 40, 10), title="Settings", items=[ MenuItem("Option 1", lambda: print("Selected 1"), "1"), MenuItem("Option 2", lambda: print("Selected 2"), "2"), MenuItem("Exit", lambda: app.stop(), "q"), ] ) # Create and run app app = App(menu, inline=False, animated=False) # Apply theme set_theme(Themes.dark()) # Start app.run() print("Application closed") ``` -------------------------------- ### Complete Menu Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Menu.md Demonstrates the creation and execution of a full-featured menu with multiple items and callbacks. Ensure kcmpy is installed and accessible. ```python from kcmpy import App, Rect from kcmpy.cui.menu import Menu, MenuItem def on_new_game(): print("Starting new game...") def on_load_game(): print("Loading game...") def on_settings(): print("Opening settings...") def on_quit(): app.stop() # Create menu menu = Menu( Rect(15, 5, 50, 12), title="Main Menu", items=[ MenuItem("New Game", on_new_game, "n"), MenuItem("Load Game", on_load_game, "l"), MenuItem("Settings", on_settings, "s"), MenuItem("Quit", on_quit, "q"), ] ) # Run app = App(menu, inline=False, animated=False) app.run() ``` -------------------------------- ### Inno Setup Script for KCM Chat Installer Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/BUILD_GUIDE.md An Inno Setup script to create a Windows installer for KCM Chat, including the client and server executables and creating shortcuts. ```iss [Setup] AppName=KCM Chat AppVersion=0.1.0 DefaultDirName={pf}\KCM Chat OutputBaseFilename=kcm_chat_setup [Files] Source: "dist\kcm_chat.exe"; DestDir: "{app}" Source: "dist\kcm_chat_server.exe"; DestDir: "{app}" [Icons] Name: "{group}\KCM Chat"; Filename: "{app}\kcm_chat.exe" Name: "{group}\KCM Chat Server"; Filename: "{app}\kcm_chat_server.exe" ``` -------------------------------- ### Install KCM.js Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/kcmjs/README.md Install the KCM.js framework using npm. ```bash npm install ``` -------------------------------- ### Install KCM JavaScript Version Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/README.md Navigate to the kcmjs directory, install dependencies using npm, and run an example JavaScript file. ```bash cd kcmjs npm install node example.js ``` -------------------------------- ### App run() Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/App.md Example of how to initialize and run an App with a Menu component. The application exits when the 'q' key is pressed or Ctrl+C is used. ```python from kcmpy import App, Rect from kcmpy.cui.menu import Menu, MenuItem menu = Menu(Rect(1, 1, 40, 6), title="Main Menu", items=[ MenuItem("Start", lambda: print("Started")), MenuItem("Exit", lambda: app.stop(), "q"), ]) app = App(menu, inline=True, animated=False) app.run() ``` -------------------------------- ### Complete Progress Demo Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Progress.md A comprehensive example showcasing the integration of ProgressBar, Spinner, MultiProgressBar, and StatusIndicator within an App. ```python from kcmpy import App, Rect from kcmpy.cui.progress import ProgressBar, Spinner, MultiProgressBar, StatusIndicator from kcmpy.cui.widgets import Box import time # Create container box = Box(Rect(5, 2, 70, 18), title="Progress Demo") # Status indicator status = StatusIndicator(Rect(7, 3, 40, 1), 'loading', 'Starting...') box.add_child(status) # Single progress bar progress = ProgressBar(Rect(7, 5, 40, 1), label="Main Task") progress.show_percentage = True box.add_child(progress) # Spinner spinner = Spinner(Rect(7, 7, 40, 1), "Loading data", style='dots') box.add_child(spinner) # Multiple bars multi = MultiProgressBar(Rect(7, 9, 40, 4)) multi.add_bar("File 1", 0.0) multi.add_bar("File 2", 0.0) multi.add_bar("File 3", 0.0) box.add_child(multi) # Create app app = App(box, animated=True) # Simulate progress import threading def simulate(): for i in range(101): progress.set_value(i / 100.0) multi.set_bar(0, (i * 0.7) / 100.0) multi.set_bar(1, (i * 0.5) / 100.0) multi.set_bar(2, (i * 0.3) / 100.0) if i == 50: status.set_status('info', 'Halfway there...') elif i == 100: status.set_status('success', 'Complete!') time.sleep(0.05) app.stop() thread = threading.Thread(target=simulate, daemon=True) thread.start() app.run() ``` -------------------------------- ### Set and Get Configuration Values Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Config.md Demonstrates basic usage of setting and getting configuration values, and saving them to disk. Load configuration later by creating a new Config instance with the same name. ```python config = Config("myapp") # Set values config.set("username", "alice") config.set("theme", "dark") config.set("notifications_enabled", True) # Save to disk config.save() # Later... config = Config("myapp") # Loads from disk username = config.get("username") # "alice" theme = config.get("theme") # "dark" ``` -------------------------------- ### App render() Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/App.md Example showing how to manually trigger a render after updating component data, ensuring the UI reflects the latest changes. ```python app.root.update_data(new_data) app.render() # Force immediate redraw ``` -------------------------------- ### Basic Config Usage Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Config.md Demonstrates the fundamental steps of creating a Config object and initializing it. ```python from kcmpy.core.config import Config # Create/load config config = Config("myapp") ``` -------------------------------- ### Install Dependencies Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/kcmjs/CHAT_README.md Navigate to the kcmjs directory and install project dependencies using npm. ```bash cd kcmjs npm install ``` -------------------------------- ### Basic Kascmenu Engine App Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/INSTALL.md A minimal example demonstrating how to create a basic application with a menu using the Kascmenu Engine. This snippet shows the core components for initializing an app and running it. ```python from kcmpy import App, Rect from kcmpy.cui.menu import Menu, MenuItem menu = Menu( Rect(1, 1, 40, 6), title="Main Menu", items=[ MenuItem("Item 1", lambda: print("1"), "1"), MenuItem("Exit", lambda: app.stop(), "q"), ] ) app = App(menu, inline=True) app.run() ``` -------------------------------- ### Simple Menu Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/kcmjs/README.md Demonstrates creating and running a simple menu-based application using KCM.js. ```javascript import { App } from './core/app.js'; import { Rect } from './core/component.js'; import { Menu, MenuItem } from './cui/menu.js'; const menu = new Menu( new Rect(10, 5, 40, 8), { title: 'Main Menu', items: [ new MenuItem('New Project', () => console.log('Created!'), 'n'), new MenuItem('Open Project', () => console.log('Opened!'), 'o'), new MenuItem('Exit', () => process.exit(0), 'q') ] } ); const app = new App(menu, { inline: false, animated: false }); app.run(); ``` -------------------------------- ### Button Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/InputWidgets.md Shows how to create a Button with a label and a callback function. The example sets the button to focused state to visually indicate it can receive input. ```python def on_click(): print("Button pressed!") button = Button( Rect(20, 10, 12, 1), label="Click Me", callback=on_click ) button.focused = True # Show focus state ``` -------------------------------- ### Run KCM.js Examples Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/kcmjs/README.md Execute various examples provided by KCM.js to test different functionalities. ```bash npm run example # Basic demo npm run example:menu # Menu demo npm run example:widgets # All widgets demo npm run chat # WebSocket chat client ``` -------------------------------- ### Add Screen Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Screen.md Demonstrates how to register new screens with the ScreenManager. Ensure screens are initialized with appropriate dimensions before adding. ```python manager = ScreenManager(app) home_screen = HomeScreen(Rect(1, 1, 80, 24)) manager.add_screen("home", home_screen) settings_screen = SettingsScreen(Rect(1, 1, 80, 24)) manager.add_screen("settings", settings_screen) ``` -------------------------------- ### Install KCM Framework Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/INDEX.md Install the KCM framework using pip. Ensure you replace '/path/to/kascmenu-engine' with the actual path to the project. ```bash pip install -e /path/to/kascmenu-engine ``` -------------------------------- ### Complete Multi-Screen Application Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Screen.md A comprehensive example demonstrating the creation of a multi-screen application using Kascmenu Engine. It includes defining multiple screens (Home, Game, Settings), a ScreenManager, and the application's main loop. ```python from kcmpy import App, Rect from kcmpy.core.screen import Screen, ScreenManager from kcmpy.cui.menu import Menu, MenuItem from kcmpy.cui.widgets import Box, Text # Define screens class HomeScreen(Screen): def __init__(self, rect): super().__init__(rect, "home") # Add menu menu = Menu( Rect(20, 5, 40, 10), title="Main Menu", items=[ MenuItem("Start Game", self.start_game, "1"), MenuItem("Settings", self.open_settings, "2"), MenuItem("Quit", self.quit_app, "q"), ] ) self.add_child(menu) self.menu = menu def start_game(self): self.screen_manager.switch_to("game") def open_settings(self): self.screen_manager.push("settings") def quit_app(self): self.screen_manager.app.stop() class GameScreen(Screen): def __init__(self, rect): super().__init__(rect, "game") # Game content label = Text(Rect(20, 10, 40, 1), "Game running... Press q to return") self.add_child(label) def on_enter(self): print("Game started!") def on_exit(self): print("Game stopped") class SettingsScreen(Screen): def __init__(self, rect): super().__init__(rect, "settings") box = Box(Rect(15, 5, 50, 12), title="Settings") label1 = Text(Rect(17, 6, 46, 1), "Sound: Enabled") box.add_child(label1) label2 = Text(Rect(17, 8, 46, 1), "Difficulty: Hard") box.add_child(label2) label3 = Text(Rect(17, 10, 46, 1), "Press q to close") box.add_child(label3) self.add_child(box) # Create app app = App(Component(Rect(1, 1, 80, 24))) manager = ScreenManager(app) # Register screens manager.add_screen("home", HomeScreen(Rect(1, 1, 80, 24))) manager.add_screen("game", GameScreen(Rect(1, 1, 80, 24))) manager.add_screen("settings", SettingsScreen(Rect(1, 1, 80, 24))) # Start with home manager.switch_to("home") app.run() ``` -------------------------------- ### Install Kascmenu Engine from Source Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/INSTALL.md Install the Kascmenu Engine by cloning the repository and installing it in development mode using pip. This is useful for contributing to the project or using the latest unreleased code. ```bash git clone https://github.com/kasper-studios/kascmenu-engine.git cd kascmenu-engine pip install -e . ``` ```bash pip install -e .[all] ``` -------------------------------- ### Install WebSocket Chat Demo Dependencies Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/README.md Install the necessary Python dependencies for the WebSocket chat demo by running pip install with the requirements.txt file. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install Kascmenu Engine from Local Wheel File Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/INSTALL.md Build the Kascmenu Engine package into a wheel file and then install it locally. This method is useful for offline installations or testing specific package versions. ```bash python setup.py sdist bdist_wheel pip install dist/kascmpy-0.1.0-py3-none-any.whl ``` -------------------------------- ### Direct EventBus Usage Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Events.md A complete example demonstrating the creation of an EventBus, subscribing a handler for key press events, and emitting events to test the subscription. ```python from kcmpy import EventBus, Event, EventType # Create bus bus = EventBus() # Subscribe def handle_input(event): key = event.data.get('key', '') if key == 'q': print("Quit") elif key == '\x1b[A': print("Up pressed") bus.subscribe(EventType.KEY_PRESS, handle_input) # Emit events bus.emit(Event(EventType.KEY_PRESS, {'key': 'q'})) bus.emit(Event(EventType.KEY_PRESS, {'key': '\x1b[A'})) ``` -------------------------------- ### Combined Layout Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Layouts.md An example showcasing the integration of VBox, HBox, Grid, Box, and Text components to build a complex UI layout. ```python from kcmpy import App, Rect from kcmpy.cui.layout import VBox, HBox, Grid from kcmpy.cui.widgets import Box, Text # Create main vertical layout main = VBox(Rect(1, 1, 80, 24), spacing=1) # Header (fixed height) header = Box(Rect(0, 0, 0, 0), title="MyApp", border_style='double') main.add(header, height=3) # Content area with horizontal split content_hbox = HBox(Rect(0, 0, 0, 0), spacing=2) # Sidebar (fixed width) sidebar = Box(Rect(0, 0, 0, 0), title="Menu") content_hbox.add(sidebar, width=20) # Main area with grid grid = Grid(Rect(0, 0, 0, 0), rows=2, cols=2, spacing=1) for i in range(4): widget = Box(Rect(0, 0, 0, 0), title=f"Widget {i+1}") grid.add(widget, row=i//2, col=i%2) content_hbox.add(grid) main.add(content_hbox) # Footer (fixed height) footer = Text(Rect(0, 0, 0, 0), "Ready | q=Quit") main.add(footer, height=1) # Run app = App(main) app.run() ``` -------------------------------- ### Animated Application Setup Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/configuration.md Creates an application with animated widgets like progress bars and spinners, enabling smooth animations. ```python from kcmpy import App, Rect from kcmpy.cui.progress import ProgressBar, Spinner # Create widgets with animations progress = ProgressBar(Rect(10, 10, 40, 1)) spinner = Spinner(Rect(10, 12, 40, 1), style='dots') main = Box(Rect(1, 1, 80, 24)) main.add_child(progress) main.add_child(spinner) # Use animated=True for smooth animations app = App(main, inline=False, animated=True) app.run() ``` -------------------------------- ### Install KCM Python Version Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/README.md Install the KCM Python framework from source in development mode, with or without additional dependencies. Includes a command to check the installation. ```bash pip install -e . # Or with additional dependencies pip install -e .[all] # Check installation kcm doctor ``` -------------------------------- ### App clear_screen() Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/App.md Example of calling the clear_screen method, which can be used for custom screen clearing logic. ```python app.clear_screen() ``` -------------------------------- ### Fullscreen Application Setup Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/configuration.md Configures a fullscreen application with a custom layout and dark theme. ```python from kcmpy import App, Rect, set_theme, Themes from kcmpy.cui.layout import VBox # Create layout main = VBox(Rect(1, 1, 80, 24), spacing=1) main.add(header_widget, height=3) main.add(content_widget) main.add(footer_widget, height=1) # Set theme set_theme(Themes.dark()) # Run app = App(main, inline=False, animated=False) app.run() ``` -------------------------------- ### Start WebSocket Chat Demo Server Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/README.md Start the WebSocket chat server by executing the chat_server.py script. The server will be accessible at http://localhost:5000. ```bash python chat_server.py ``` -------------------------------- ### App stop() Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/App.md Example demonstrating how to call the stop method, typically from a callback function to terminate the application. ```python app = App(root_component) # In a menu callback: def on_exit(): app.stop() ``` -------------------------------- ### Install Nuitka and Cython on Linux/macOS Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/BUILD_GUIDE.md Install Nuitka for compiling Python applications. Cython is required for Python 3.12+. Install ccache for better optimization on Linux. ```bash pip3 install nuitka # Cython required for Python 3.12+ pip3 install cython # Additional for Linux (better optimization) sudo apt-get install ccache # Ubuntu/Debian sudo dnf install ccache # Fedora ``` -------------------------------- ### Config File Methods Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/configuration.md Demonstrates methods for loading, saving, getting, setting, deleting, and updating configuration values. ```python config.load() # Load from disk config.save() # Save to disk config.get("key") # Get value (dot notation: "a.b.c") config.set("key", value) # Set value config.delete("key") # Delete value config.get_all() # Get all data config.update(dict) # Merge dict ``` -------------------------------- ### Multi-Screen Application Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/README.md Demonstrates how to set up and manage multiple screens within an application using the Screen and ScreenManager classes. This is useful for creating applications with distinct views or states. ```python from kcmpy import App, Component, Rect from kcmpy.core.screen import Screen, ScreenManager class HomeScreen(Screen): def __init__(self, rect): super().__init__(rect, "home") # Add content def on_enter(self): print("Home screen started") class SettingsScreen(Screen): def __init__(self, rect): super().__init__(rect, "settings") # Add content app = App(Component(Rect(1, 1, 80, 24))) manager = ScreenManager(app) manager.add_screen("home", HomeScreen(Rect(1, 1, 80, 24))) manager.add_screen("settings", SettingsScreen(Rect(1, 1, 80, 24))) manager.switch_to("home") app.run() ``` -------------------------------- ### Python Component Hierarchy Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Component.md Demonstrates creating a component hierarchy using VBox, Box, and Text components. This example shows how to add children to components and run the application. ```python from kcmpy import App, Component, Rect from kcmpy.cui.layout import VBox from kcmpy.cui.widgets import Box, Text # Create hierarchy root = VBox(Rect(1, 1, 80, 24), spacing=1) # Add child (Box) box1 = Box(Rect(2, 2, 40, 5), title="Section 1") root.add_child(box1) # Add grandchild (Text in Box) text = Text(Rect(3, 3, 38, 3), "Hello World") box1.add_child(text) # Run app = App(root) app.run() ``` -------------------------------- ### MessageDialog Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Screen.md Demonstrates how to create and display a MessageDialog. Includes setting a callback for when the dialog is closed. ```python def on_ok(result): print("Message shown!") dialog = MessageDialog( Rect(1, 1, 80, 24), title="Information", message="This is a message dialog" ) dialog.on_close = on_ok manager.push(dialog.name) # Won't work - need to register first ``` -------------------------------- ### Install Nuitka and Cython on Windows Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/BUILD_GUIDE.md Install Nuitka for compiling Python applications. Cython is required for Python 3.12+. ```bash pip install nuitka # Cython required for Python 3.12+ pip install cython ``` -------------------------------- ### MenuItem Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Menu.md Illustrates the creation of a MenuItem instance with a label, a callback function, and a keyboard shortcut. ```python def on_start(): print("Starting application...") item = MenuItem("Start Application", on_start, "s") # User presses 's' or navigates to this item and presses Enter ``` -------------------------------- ### Complete kcmpy Application Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/DataDisplay.md A comprehensive example demonstrating the integration of Table, Chart, and TreeView components within a VBox layout in a kcmpy application. This shows how to instantiate, configure, and add these components to a layout, and then run the application. ```python from kcmpy import App, Rect from kcmpy.cui.table import Table, Chart, TreeView, TreeNode from kcmpy.cui.layout import VBox # Create layout layout = VBox(Rect(1, 1, 80, 24), spacing=1) # Table table = Table(Rect(0, 0, 0, 0), headers=["ID", "Name", "Status"]) table.add_row([1, "Alice", "Active"]) table.add_row([2, "Bob", "Inactive"]) table.add_row([3, "Charlie", "Active"]) layout.add(table, height=6) # Chart chart = Chart(Rect(0, 0, 0, 0), title="Q1 Performance") chart.set_data([ ("Week 1", 100), ("Week 2", 150), ("Week 3", 120), ("Week 4", 180), ]) layout.add(chart, height=7) # Tree tree = TreeView(Rect(0, 0, 0, 0)) root = TreeNode("Projects") proj1 = TreeNode("Project A") proj1.add_child(TreeNode("Task 1")) proj1.add_child(TreeNode("Task 2")) root.add_child(proj1) proj2 = TreeNode("Project B") proj2.add_child(TreeNode("Task 3")) root.add_child(proj2) tree.add_node(root) layout.add(tree) app = App(layout) app.run() ``` -------------------------------- ### Kascmenu Engine App with Screens Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/INSTALL.md Example showing how to integrate screens into a Kascmenu Engine application. This involves defining a custom Screen class and managing screens using ScreenManager. ```python from kcmpy import App, Rect from kcmpy.core.screen import Screen, ScreenManager class MainScreen(Screen): def __init__(self, rect): super().__init__(rect, "main") # Your code app = App(...) screens = ScreenManager(app) screens.add_screen("main", MainScreen(...)) screens.switch_to("main") app.run() ``` -------------------------------- ### RadioGroup Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/InputWidgets.md Demonstrates how to create and use a RadioGroup. It includes setting up options, defining a callback for selection changes, and accessing the selected option. ```python def on_selection_changed(index): print(f"Selected: {options[index]}") options = ["Option 1", "Option 2", "Option 3"] radio = RadioGroup( Rect(10, 5, 20, 4), options=options ) radio.on_change = on_selection_changed radio.focused = True # Get selected option selected = radio.options[radio.selected_index] ``` -------------------------------- ### Custom ColorScheme Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Theme.md Demonstrates how to create a custom ColorScheme instance by overriding default values. ```python custom_scheme = ColorScheme( primary='bright_magenta', secondary='magenta', success='bright_green', text='white', border='bright_magenta', focus='bright_magenta', ) ``` -------------------------------- ### Stack Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Layouts.md Demonstrates adding a background and an overlay to a Stack, with the overlay drawn on top due to a higher z-index. ```python stack = Stack(Rect(1, 1, 80, 24)) # Background (z=0) background = Box(Rect(0, 0, 0, 0), title="Background") stack.add(background, z_index=0) # Overlay (z=1, drawn on top) overlay = Box(Rect(0, 0, 0, 0), title="Overlay") stack.add(overlay, z_index=1) ``` -------------------------------- ### Install Kascmenu Engine from PyPI Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/INSTALL.md Install the Kascmenu Engine package from the Python Package Index (PyPI). Use optional extras for specific functionalities like chat, notifications, or build support. ```bash pip install kascmpy ``` ```bash pip install kascmpy[chat] ``` ```bash pip install kascmpy[notifications] ``` ```bash pip install kascmpy[build] ``` ```bash pip install kascmpy[all] ``` ```bash pip install kascmpy[dev] ``` -------------------------------- ### Verify Kascmenu Engine Installation Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/INSTALL.md Check the installed version of Kascmenu Engine and verify the command-line interface (CLI) is working correctly. ```bash python -c "import kcmpy; print(kcmpy.__version__)" kcm doctor ``` -------------------------------- ### Menu add_item Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Menu.md Demonstrates adding multiple MenuItem instances to a Menu object. ```python menu = Menu(Rect(10, 5, 40, 10), title="Options") menu.add_item(MenuItem("Option 1", on_option1, "1")) menu.add_item(MenuItem("Option 2", on_option2, "2")) ``` -------------------------------- ### Switch Screen Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Screen.md Shows how to transition to a different screen. By default, this clears the modal screen stack. Use this for primary navigation. ```python manager.switch_to("settings") # Switch to settings screen ``` -------------------------------- ### Anchor Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Layouts.md Demonstrates adding widgets to an Anchor layout at different positions like top-left, center, and bottom-right with offsets. ```python anchor = Anchor(Rect(1, 1, 80, 24)) # Top left corner title = Text(Rect(0, 0, 30, 1), "Title") anchor.add(title, 'top-left', offset_x=1, offset_y=0) # Center dialog = Box(Rect(0, 0, 40, 10), title="Dialog") anchor.add(dialog, 'center') # Bottom right footer = Text(Rect(0, 0, 20, 1), "Footer") anchor.add(footer, 'bottom-right', offset_x=-1) ``` -------------------------------- ### Push Screen Example (Modal) Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Screen.md Demonstrates pushing a screen onto the stack, typically used for modal dialogs or overlays. This pauses the current screen and activates the new one. ```python manager.push("confirm_dialog") # Show confirmation dialog over current ``` -------------------------------- ### EventBus Multi-Subscriber Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Events.md Use the `EventBus` to allow multiple subscribers to listen to specific event types. Subscribers are called immediately when an event is emitted. This example demonstrates logging, shortcut handling, and menu interaction for key press events. ```python from kcmpy import EventBus, Event, EventType bus = EventBus() def logger(event): """Log all key presses""" print(f"LOG: {event.data.get('key')}") def shortcut_handler(event): """Handle keyboard shortcuts""" key = event.data.get('key', '') if key == 'q': print("Quitting...") return menu_handler = ... # component # All three listen to KEY_PRESS bus.subscribe(EventType.KEY_PRESS, logger) bus.subscribe(EventType.KEY_PRESS, shortcut_handler) bus.subscribe(EventType.KEY_PRESS, menu_handler.handle_event) # When key pressed, all three are called bus.emit(Event(EventType.KEY_PRESS, {'key': 'a'})) ``` -------------------------------- ### Spinner Constructor and Styles Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Progress.md Shows how to create Spinner instances with different animation styles. The style parameter controls the visual appearance of the spinner. ```python # Default dots spinner spinner1 = Spinner(Rect(10, 5, 30, 1), "Loading...") # Arrow spinner spinner2 = Spinner(Rect(10, 6, 30, 1), "Processing", style='arrow') # Simple dots spinner3 = Spinner(Rect(10, 7, 30, 1), "Waiting", style='dots_simple') ``` -------------------------------- ### App Integration with ScreenManager Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/App.md Example showing how to integrate the App class with ScreenManager for managing multiple screens within an application. ```python from kcmpy.core.screen import ScreenManager, Screen app = App(Component(Rect(1, 1, 80, 24))) screen_manager = ScreenManager(app) screen_manager.add_screen("home", HomeScreen(app.root.rect)) screen_manager.switch_to("home") app.run() ``` -------------------------------- ### Start WebSocket Chat Demo Client Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/README.md Run the WebSocket chat client by executing the chat_client.py script. This client allows real-time messaging within the console. ```bash python chat_client.py ``` -------------------------------- ### Troubleshoot Compilation Errors Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/BUILD_GUIDE.md Ensure all project dependencies are installed from requirements.txt. If errors persist, try compiling without optimizations. ```bash pip install -r requirements.txt python -m nuitka --standalone --onefile chat_client.py ``` -------------------------------- ### Style Examples Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Renderer.md Demonstrates creating Style objects for different text appearances, such as bold blue text on a white background, red warning text, and underlined cyan text. ```python from kcmpy import Style # Blue text on white background, bold style = Style(fg='blue', bg='white', bold=True) # Red warning text warning = Style(fg='bright_red', bold=True) # Cyan with underline highlight = Style(fg='cyan', underline=True) ``` -------------------------------- ### Get All Configuration Data Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Config.md Retrieves a copy of the entire configuration data as a dictionary. This is useful for inspecting all current settings. ```python all_config = config.get_all() print(all_config) ``` -------------------------------- ### Widget Demo Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/kcmjs/README.md Showcases the integration and usage of various KCM.js widgets like ProgressBar, Spinner, StatusIndicator, TextInput, and Button. ```javascript import { App } from './core/app.js'; import { Component, Rect } from './core/component.js'; import { ProgressBar, Spinner, StatusIndicator } from './cui/progress.js'; import { TextInput, Button } from './cui/input.js'; const root = new Component(new Rect(1, 1, 80, 30)); // Add widgets const progress = new ProgressBar(new Rect(5, 5, 40, 1)); progress.setProgress(75); root.addChild(progress); const spinner = new Spinner(new Rect(5, 7, 40, 1), { style: 'dots', text: 'Loading...' }); root.addChild(spinner); const status = new StatusIndicator(new Rect(5, 9, 40, 1), 'success', 'Operation completed'); root.addChild(status); const input = new TextInput(new Rect(5, 11, 40, 2), { label: 'Name:', placeholder: 'Enter name' }); input.focused = true; root.addChild(input); const app = new App(root, { inline: false, animated: true }); app.run(); ``` -------------------------------- ### MultiProgressBar Constructor and Usage Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Progress.md Demonstrates initializing a MultiProgressBar and adding individual progress bars with labels. It also shows how to update bars by their index or label. ```python multi = MultiProgressBar(Rect(10, 5, 60, 5)) multi.add_bar("Download", 0.0) multi.add_bar("Install", 0.0) multi.add_bar("Configure", 0.0) # Update multi.set_bar(0, 0.5) # Update first bar multi.set_bar_by_label("Install", 0.75) # Update by label ``` -------------------------------- ### Get Terminal Size Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Renderer.md Retrieves the current terminal dimensions. Defaults to (80, 24) if detection fails. ```python renderer = Renderer() w, h = renderer.get_terminal_size() print(f"Terminal: {w}x{h}") ``` -------------------------------- ### Menu handle_event Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Menu.md Simulates handling an 'Up arrow' key press event within a Menu to navigate to the previous item. ```python event = Event(EventType.KEY_PRESS, {'key': '\x1b[A'}) # Up arrow menu.handle_event(event) ``` -------------------------------- ### Component-based Architecture Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/ARCHITECTURE.md Illustrates the component-based architecture by showing how to create a custom screen that adds child widgets. This promotes composition over inheritance, component reusability, and logic isolation. ```python class MyScreen(Screen): def __init__(self, rect): super().__init__(rect) self.add_child(widget1) self.add_child(widget2) ``` -------------------------------- ### Text Widget Examples Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Widgets.md Illustrates creating Text widgets for single-line, multi-line, and styled text. Supports newlines and basic styling. Requires importing Text, Rect, and Style. ```python from kcmpy import Text, Rect, Style # Simple text label = Text(Rect(10, 5, 30, 1), "Welcome to MyApp") # Multi-line text help_text = Text( Rect(1, 1, 80, 5), """Usage: q - Quit Up/Down - Navigate Enter - Select""" ) # Styled text help_text.style = Style(fg='cyan', italic=True) ``` -------------------------------- ### Add Rows to Table Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/DataDisplay.md Demonstrates how to add multiple data rows to a Table instance. Column widths are automatically recalculated. ```python table = Table(Rect(5, 2, 70, 15), headers=["Name", "Email", "Status"]) table.add_row(["Alice Smith", "alice@example.com", "Active"]) table.add_row(["Bob Jones", "bob@example.com", "Inactive"]) table.add_row(["Charlie Brown", "charlie@example.com", "Active"]) ``` -------------------------------- ### KEY_PRESS Event Data Examples Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Events.md Illustrates how to create Event objects for key press events, including regular characters and special keys like the Up arrow. ```python event = Event(EventType.KEY_PRESS, {'key': 'a'}) event = Event(EventType.KEY_PRESS, {'key': '\x1b[A'}) # Up arrow event = Event(EventType.KEY_PRESS, {'key': '\r'}) # Enter ``` -------------------------------- ### Menu Styling Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Menu.md Shows how to customize the appearance of a menu, including normal and selected item styles, title, and shortcut key colors. Requires a Style class definition. ```python menu = Menu(Rect(10, 5, 40, 10), title="Menu") # Change colors menu.style_normal = Style(fg='white') menu.style_selected = Style(fg='black', bg='cyan', bold=True) menu.style_title = Style(fg='yellow', bold=True) menu.style_key = Style(fg='green') # Shortcut key color menu.add_item(MenuItem("Item 1", callback, "1")) ``` -------------------------------- ### Pop Screen Example (Close Modal) Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Screen.md Illustrates closing the current screen (e.g., a modal dialog) and returning to the previous screen in the stack. This resumes the underlying screen. ```python # In dialog callback manager.pop() # Close dialog ``` -------------------------------- ### Default Configuration Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/kcmjs/CHAT_README.md Example JSON structure for chat client settings, including server URL, user nickname, and notification preferences. Settings are auto-saved to ~/.kcm/kcm_chat.json. ```json { "server": { "url": "http://localhost:5000" }, "user": { "nickname": "User" }, "notifications": { "messages": true, "joins": true, "leaves": false } } ``` -------------------------------- ### Install Cython for Python 3.12+ Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/BUILD_GUIDE.md Install Cython, which is a requirement for Nuitka when using Python 3.12 and later versions. ```bash pip install cython>=3.0.0 ``` -------------------------------- ### Create New Project with KCM Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/README.md Create a new KCM project interactively or directly using the 'kcm init' command, then navigate to the project directory and run the application. ```bash # Interactive mode kcm # Or directly kcm init my_app cd my_app python app.py ``` -------------------------------- ### Form Example with Input Widgets Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/InputWidgets.md Demonstrates creating a form layout using various input widgets like TextInput, Checkbox, RadioGroup, and Button. It shows how to add widgets to a Box and run the application. ```python from kcmpy import App, Rect from kcmpy.cui.input import TextInput, Checkbox, RadioGroup, Button from kcmpy.cui.widgets import Box, Text # Create form box form = Box(Rect(10, 3, 50, 16), title="User Settings") # Name input name_input = TextInput( Rect(12, 4, 45, 1), label="Name", placeholder="Enter name" ) name_input.focused = True form.add_child(name_input) # Email input email_input = TextInput( Rect(12, 6, 45, 1), label="Email", placeholder="Enter email" ) form.add_child(email_input) # Subscribe checkbox subscribe = Checkbox( Rect(12, 8, 30, 1), label="Subscribe to newsletter" ) form.add_child(subscribe) # Theme selection theme_radio = RadioGroup( Rect(12, 10, 30, 3), options=["Light", "Dark", "Auto"] ) theme_radio.selected_index = 0 form.add_child(theme_radio) # Save button def save_settings(): print(f"Name: {name_input.value}") print(f"Email: {email_input.value}") print(f"Subscribe: {subscribe.checked}") print(f"Theme: {theme_radio.options[theme_radio.selected_index]}") app.stop() save_btn = Button(Rect(20, 14, 10, 1), "Save", save_settings) form.add_child(save_btn) app = App(form, inline=False) app.run() ``` -------------------------------- ### Create and Apply Custom Theme Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Theme.md Demonstrates creating a custom theme with a specific color scheme and setting it as the global theme. UI elements created after setting the theme will inherit its colors. ```python from kcmpy import Theme, ColorScheme, set_theme, App, Rect from kcmpy.cui.menu import Menu, MenuItem # Create custom theme my_colors = ColorScheme( primary='bright_magenta', secondary='magenta', success='bright_green', warning='bright_yellow', error='bright_red', text='white', text_dim='bright_black', border='magenta', focus='bright_magenta', selection='bright_white' ) my_theme = Theme("MyCustom", my_colors) # Set global theme set_theme(my_theme) # Create UI (will use theme colors) menu = Menu( Rect(15, 5, 50, 10), title="Menu", items=[ MenuItem("Option 1", lambda: print("1"), "1"), MenuItem("Option 2", lambda: print("2"), "2"), MenuItem("Exit", lambda: app.stop(), "q"), ] ) app = App(menu, inline=False) app.run() ``` -------------------------------- ### Screen Manager as Router Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/ARCHITECTURE.md Demonstrates using the Screen Manager to add and switch between different screens. This facilitates explicit transitions, lifecycle management, and modal window handling via push/pop operations. ```python screens.add_screen("settings", settings_screen) screens.add_screen("chat", chat_screen) screens.switch_to("chat") ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/INSTALL.md Recommended practice for managing project dependencies. This snippet shows how to create a virtual environment and activate it on Linux/macOS and Windows. ```bash # Create venv python -m venv venv # Activate source venv/bin/activate # Linux/macOS venv\Scripts\activate # Windows # Install KCM pip install kascmpy ``` -------------------------------- ### Troubleshoot 'No module named 'kcmpy'' Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/INSTALL.md This error indicates that the Kascmenu Engine package is not installed. Install it using pip, either from PyPI or from source. ```bash pip install kascmpy # or pip install -e . # from source ``` -------------------------------- ### Simple Menu Example in Python Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/README.md A basic KCM Python application demonstrating how to create and run a simple menu with navigation items and an exit option. Requires importing App, Rect, Menu, and MenuItem. ```python from kcmpy import App, Rect from kcmpy.cui.menu import Menu, MenuItem menu = Menu( Rect(1, 1, 40, 6), title="Main Menu", items=[ MenuItem("New Project", lambda: print("Created!"), "n"), MenuItem("Exit", lambda: app.stop(), "q"), ] ) app = App(menu, inline=True) app.run() ``` -------------------------------- ### get_terminal_size() Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Renderer.md Get current terminal dimensions. ```APIDOC ## get_terminal_size() ### Description Get current terminal dimensions. ### Method ```python def get_terminal_size(self) -> Tuple[int, int] ``` ### Returns (width, height) tuple. Defaults to (80, 24) if detection fails. ### Example ```python renderer = Renderer() w, h = renderer.get_terminal_size() print(f"Terminal: {w}x{h}") ``` ``` -------------------------------- ### Applying Predefined and Custom Themes Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Theme.md Shows how to apply a predefined theme (e.g., dark) or a custom-created theme using the `set_theme` function. ```python from kcmpy import Themes, set_theme # Apply dark theme set_theme(Themes.dark()) # Apply custom theme from kcmpy import Theme, ColorScheme custom = Theme("MyTheme", ColorScheme( primary='bright_green', secondary='green', text='white', )) set_theme(custom) ``` -------------------------------- ### Get Current Theme Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Theme.md Retrieves the currently active global theme instance. ```python def get_theme() -> Theme ``` -------------------------------- ### Multi-Screen Application with Config Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/configuration.md Sets up a multi-screen application, loading theme from config and managing screens. ```python from kcmpy.core.config import Config from kcmpy.core.screen import ScreenManager # Load configuration config = Config("myapp") theme_name = config.get("theme", "default") # Setup app app = App(Component(Rect(1, 1, 80, 24))) manager = ScreenManager(app) # Register screens manager.add_screen("home", HomeScreen(Rect(1, 1, 80, 24))) manager.add_screen("game", GameScreen(Rect(1, 1, 80, 24))) manager.switch_to("home") app.run() # Save settings on exit config.set("last_screen", "home") config.save() ``` -------------------------------- ### StatusIndicator Usage Example Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Progress.md Demonstrates how to create and update a StatusIndicator. Use set_status() to change its state and message. ```python indicator = StatusIndicator(Rect(10, 5, 40, 1), 'info', 'Ready') # Update status indicator.set_status('loading', 'Processing...') # Later... indicator.set_status('success', 'Operation completed!') # Error indicator.set_status('error', 'Something went wrong') ``` -------------------------------- ### run() Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/App.md Starts the application's main event loop. This method is blocking and runs until the application is explicitly stopped. ```APIDOC ## run() ### Description Starts the application's main event loop. This method is blocking and runs until the application is explicitly stopped. It initializes raw input mode, hides the cursor, and enters the event loop, processing keyboard input and rendering updates. ### Method run ### Endpoint N/A (Method) ### Parameters None ### Example: ```python from kcmpy import App, Rect from kcmpy.cui.menu import Menu, MenuItem menu = Menu(Rect(1, 1, 40, 6), title="Main Menu", items=[ MenuItem("Start", lambda: print("Started")), MenuItem("Exit", lambda: app.stop(), "q") ]) app = App(menu) app.run() ``` ``` -------------------------------- ### Speed up Compilation on Linux Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/BUILD_GUIDE.md Install ccache on Linux systems to significantly speed up subsequent Nuitka compilations by leveraging caching. ```bash # Linux sudo apt-get install ccache ``` -------------------------------- ### App Constructor Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/App.md Initializes a new App instance. The root component is mandatory, while inline and animated are optional booleans to control rendering behavior. ```APIDOC ## App Constructor ### Description Initializes a new App instance. The root component is mandatory, while inline and animated are optional booleans to control rendering behavior. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method __init__ ### Endpoint N/A (Constructor) ### Parameters #### Parameters - **root** (Component) - Required - Root component to render (typically a Screen or layout container) - **inline** (bool) - Optional - If True, renders in place with leading space; if False, renders fullscreen. Defaults to True. - **animated** (bool) - Optional - If True, clears and redraws full screen on each update (for animations); if False, incremental updates. Defaults to False. ``` -------------------------------- ### Get Current Screen Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/_autodocs/api-reference/Screen.md Retrieves the currently active screen instance from the ScreenManager. Returns None if no screen is currently active. ```python def get_current(self) -> Optional[Screen] ``` -------------------------------- ### Troubleshoot Dependency Issues Source: https://github.com/kasper-studios/kascmenu-engine/blob/main/INSTALL.md To resolve dependency conflicts or ensure all optional dependencies are installed, reinstall the Kascmenu Engine package with the '[all]' extra. ```bash pip install --force-reinstall kascmpy[all] ```