### Run PyCodium CLI Commands Source: https://context7.com/jan-mue/pycodium/llms.txt Command-line interface for launching PyCodium. Supports opening files or folders directly from the terminal. Requires uvx for installation and execution. ```bash # Install and run with uvx (recommended) uvx pycodium # Run with a specific file uvx pycodium /path/to/file.py # Run with a folder as project root uvx pycodium /path/to/project # Check version uvx pycodium --version # Output: 0.3.1 ``` -------------------------------- ### Initialize Native Application Menu (Python) Source: https://context7.com/jan-mue/pycodium/llms.txt Initializes the native application menu for macOS, Windows, and Linux. This function is typically called during application startup and sets up menu items for file operations, editing, and application information. It requires `AppHandle` and `WebviewWindow` objects. ```python from pytauri import AppHandle from pytauri.webview import WebviewWindow from pycodium.menu import init_menu # Mock Manager class for demonstration purposes class Manager: @staticmethod def get_webview_window(app_handle: AppHandle, label: str) -> WebviewWindow | None: # In a real app, this would retrieve the window object print(f"Getting window with label: {label}") # return WebviewWindow(app_handle, label) # Example return return None # Return None if window not found for example # Menu initialization (called during app startup) def app_setup(app_handle: AppHandle) -> None: # Assuming Manager is accessible and can get the window window = Manager.get_webview_window(app_handle, "main") if window: init_menu(app_handle, window) else: print("Main webview window not found, menu not initialized.") # Menu structure created: # PyCodium # - About PyCodium # - Services # - Hide PyCodium (Cmd+H) # - Hide Others # - Show All # - Quit PyCodium (Cmd+Q) # File # - Open File... (Cmd+O) # - Open Folder... (Cmd+Shift+O) # - Save (Cmd+S) # - Save As... (Cmd+Shift+S) # - Close Tab (Cmd+W) # - Close Window # Edit # - Undo/Redo/Cut/Copy/Paste/Select All # View ``` -------------------------------- ### Configure Reflex App with Tailwind CSS Theming Source: https://context7.com/jan-mue/pycodium/llms.txt This configuration file sets up a Reflex application with custom theming for Tailwind CSS, aiming for a VS Code-like appearance. It defines specific color variables for various UI elements and enables Tailwind CSS v3 plugin, while disabling telemetry and the 'Built with Reflex' badge. ```python import reflex as rx from reflex.plugins.shared_tailwind import TailwindConfig # Custom Tailwind theme for VS Code-like appearance tailwind_config: TailwindConfig = { "darkMode": "class", "theme": { "extend": { "colors": { "pycodium": { "bg": "var(--pycodium-bg)", "sidebar-bg": "var(--pycodium-sidebar-bg)", "activity-bar": "var(--pycodium-activity-bar)", "editor-bg": "var(--pycodium-editor-bg)", "statusbar-bg": "var(--pycodium-statusbar-bg)", "highlight": "var(--pycodium-highlight)", "text": "var(--pycodium-text)", "icon": "var(--pycodium-icon)", }, }, }, }, "plugins": ["tailwindcss-animate"], } config = rx.Config( app_name="pycodium", telemetry_enabled=False, show_built_with_reflex=False, plugins=[rx.plugins.TailwindV3Plugin(tailwind_config)], ) ``` -------------------------------- ### Manage Backend Server Processes and Ports Source: https://context7.com/jan-mue/pycodium/llms.txt Utilities for managing backend server processes, including waiting for a port to become available, identifying the process using a specific port, and gracefully terminating a process listening on a port. These functions are crucial for ensuring backend services are ready before client interactions and for clean shutdown procedures. ```python from pycodium.utils.processes import ( wait_for_port, get_process_on_port, terminate_or_kill_process_on_port, ) # Wait for backend server to be ready wait_for_port(8000, timeout=5) # Raises TimeoutError if port not available within timeout # Find process using a specific port proc = get_process_on_port(8000) if proc: print(f"PID: {proc.pid}, Name: {proc.name()}") # Gracefully terminate process on port (SIGTERM then SIGKILL) terminate_or_kill_process_on_port(8000, timeout=1) # Sends SIGTERM, waits 1 second, then SIGKILL if still running ``` -------------------------------- ### Handle Tauri Menu Events with Reflex Source: https://context7.com/jan-mue/pycodium/llms.txt This React component bridges Tauri menu events to Reflex state handlers, enabling native file dialogs and other menu actions. It utilizes @tauri-apps/plugin-dialog for cross-platform compatibility and passes selected file/folder paths or triggers save/close actions via specified Reflex event handlers. ```python import reflex as rx from pycodium.components.menu_events import tauri_menu_handler from pycodium.state import EditorState # Usage in main page component def index() -> rx.Component: return rx.el.div( tauri_menu_handler( on_file_selected=EditorState.menu_open_file, on_folder_selected=EditorState.menu_open_folder, on_save=EditorState.menu_save, on_save_as=EditorState.menu_save_as, on_close_tab=EditorState.menu_close_tab, ), # ... rest of UI ) # The component handles: # 1. Opens native OS file/folder picker dialogs # 2. Passes selected paths to Reflex event handlers # 3. Uses @tauri-apps/plugin-dialog for cross-platform dialogs ``` -------------------------------- ### EditorState.open_file - Opening Files in Python Source: https://context7.com/jan-mue/pycodium/llms.txt Method to open files within the PyCodium editor. It handles creating new tabs, activating existing ones, detecting file encoding, and identifying the programming language using Pygments. It also initiates real-time file watching. ```python import reflex as rx from pycodium.state import EditorState # The open_file method is called with a relative path from project root # File path format: "project_name/path/to/file.py" # Example: File explorer item triggering open_file def file_item(file_path: str) -> rx.Component: return rx.el.div( rx.icon("file", size=16), rx.el.span(file_path), on_click=lambda: EditorState.open_file(file_path), class_name="cursor-pointer hover:bg-white/5", ) # Internal flow when open_file is called: # 1. Checks if file is already open in a tab # 2. If not, reads file content asynchronously # 3. Detects encoding (UTF-8, UTF-16, Latin-1, etc.) # 4. Detects programming language via Pygments # 5. Creates EditorTab and activates it # 6. Starts file watcher for live content updates ``` -------------------------------- ### FilePath Model for File Tree with Lazy Loading (Python) Source: https://context7.com/jan-mue/pycodium/llms.txt Defines a Pydantic BaseModel for representing nodes in a file tree, supporting lazy loading of directory contents. It includes attributes for name, children, directory status, and loading status. The `build_tree` function demonstrates how to construct this model from a given path, sorting directories before files. ```python from pydantic import BaseModel from pathlib import Path class FilePath(BaseModel): """File tree node supporting lazy loading.""" name: str # File or folder name sub_paths: list["FilePath"] = [] # Children (for directories) is_dir: bool = True # True if directory loaded: bool = False # True if children have been fetched # Example: Building a file tree def build_tree(path: Path) -> FilePath: children = [] for item in path.iterdir(): children.append(FilePath( name=item.name, is_dir=item.is_dir(), loaded=not item.is_dir(), # Files are always "loaded" )) # Sort: directories first, then alphabetically children.sort(key=lambda x: (not x.is_dir, x.name.lower())) return FilePath(name=path.name, sub_paths=children, loaded=True) ``` -------------------------------- ### File Encoding Detection and Decoding (Python) Source: https://context7.com/jan-mue/pycodium/llms.txt Utility functions to automatically detect the encoding of raw byte data and decode it into a string. It prioritizes BOM detection, source file encoding declarations, and then uses `charset_normalizer` or a default encoding. Supports a wide range of encodings. ```python from pycodium.utils.detect_encoding import decode, get_encoding # Assume 'raw_bytes' is loaded from a file # Example: with open("file.py", "rb") as f: # raw_bytes = f.read() raw_bytes = b'\xef\xbb\xbfprint("Hello")' # Example with UTF-8 BOM # For Python files, UTF-8 is the default per PEP 3120 content, encoding = decode(raw_bytes, default_encoding="utf-8") print(f"Detected encoding: {encoding}") print(f"Decoded content: {content}") # Encoding detection priority: # 1. BOM detection (UTF-8 BOM, UTF-16, UTF-32) # 2. Source file encoding declaration (# coding: utf-8) # 3. charset_normalizer detection # 4. Default encoding (if provided) # 5. Fallback: UTF-8 guessed, then Latin-1 # Supported encodings include: ENCODINGS = [ "utf-8", "iso8859-1", "iso8859-15", "ascii", "koi8-r", "cp1251", "koi8-u", "latin-1", "utf-16", # ... and more ISO-8859 variants ] ``` -------------------------------- ### Monaco Editor Component for Code Editing (Python) Source: https://context7.com/jan-mue/pycodium/llms.txt A Python function that wraps the Monaco editor, providing syntax-highlighted code editing capabilities. It configures the editor with initial content, language, theme, and various options. The `on_change` event handler allows for capturing content updates. ```python import reflex as rx from pycodium.components.monaco import monaco # Assuming EditorState and tab_id are defined elsewhere # class EditorState: # @staticmethod # def update_tab_content(tab_id, content): # pass # tab_id = "some_tab_id" # Monaco editor component with full configuration def editor_view() -> rx.Component: return monaco( value="print('Hello, World!')", # Current content language="python", # Syntax highlighting path="example.py", # Virtual file path theme="vs-dark", # Color theme options={ "selectOnLineNumbers": True, "roundedSelection": False, "readOnly": False, "cursorStyle": "line", "automaticLayout": True, "minimap": {"enabled": True}, "scrollBeyondLastLine": False, "lineNumbers": "on", }, on_change=lambda content: print(f"Content changed: {content}"), # Placeholder for actual update ) ``` -------------------------------- ### EditorState - Core State Management in Python Source: https://context7.com/jan-mue/pycodium/llms.txt The central state class in PyCodium, managing IDE functionality like tabs, file tree, and sidebar. It uses Reflex for reactive UI updates and provides access to various state variables. ```python import reflex as rx from pycodium.state import EditorState # EditorState provides these key state variables: # - sidebar_visible: bool - Toggle sidebar visibility # - active_sidebar_tab: str - Current sidebar view ("explorer", "search", etc.) # - tabs: list[EditorTab] - Open editor tabs # - active_tab_id: str | None - Currently focused tab # - project_root: Path - Current project directory # - file_tree: FilePath | None - Lazy-loaded directory structure # - expanded_folders: set[str] - Expanded folder paths in explorer # Example: Creating a custom component that uses EditorState def my_component() -> rx.Component: return rx.el.div( rx.cond( EditorState.sidebar_visible, rx.el.span("Sidebar is open"), rx.el.span("Sidebar is closed"), ), rx.el.button("Toggle Sidebar", on_click=EditorState.toggle_sidebar), rx.el.div(f"Active tab: {EditorState.active_tab_id}"), rx.el.div(f"Project: {EditorState.project_root}"), ) ``` -------------------------------- ### EditorTab - Data Model for Editor Tabs in Python Source: https://context7.com/jan-mue/pycodium/llms.txt A Pydantic BaseModel representing an open file tab in the PyCodium editor. It stores metadata such as unique ID, display title, programming language, file content, encoding, and path. It also includes an asyncio.Event for managing file watching. ```python from pydantic import BaseModel import asyncio class EditorTab(BaseModel): """Editor tab with file content and metadata.""" class Config: arbitrary_types_allowed = True id: str # Unique tab identifier (UUID) title: str # Display name in tab bar language: str # Programming language for syntax highlighting content: str # File content encoding: str # File encoding (utf-8, utf-16, etc.) path: str # File path relative to project on_not_active: asyncio.Event # Signal to stop file watching is_special: bool = False # True for non-file tabs (settings) special_component: str | None = None # Component name for special tabs # Example: Creating a tab programmatically from uuid import uuid4 new_tab = EditorTab( id=str(uuid4()), title="example.py", language="python", content="print('Hello, World!')", encoding="utf-8", path="myproject/example.py", on_not_active=asyncio.Event(), ) ``` -------------------------------- ### Programming Language Detection from Filename (Python) Source: https://context7.com/jan-mue/pycodium/llms.txt A utility function that detects the programming language of a file based on its filename using Pygments lexers. It returns the detected language name, typically lowercased for compatibility with editors like Monaco. Returns 'undefined' if the language cannot be determined. ```python from pycodium.utils.detect_lang import detect_programming_language # Detect language from filename language = detect_programming_language("main.py") print(language) # Output: "Python" language = detect_programming_language("App.tsx") print(language) # Output: "TypeScript" language = detect_programming_language("Dockerfile") print(language) # Output: "Docker" language = detect_programming_language("unknown.xyz") print(language) # Output: "undefined" # The detected language is lowercased for Monaco editor compatibility language_for_monaco = detect_programming_language("script.js").lower() print(language_for_monaco) # Output: "javascript" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.